
var popupStatus = 0;
var lastpopup='';
var bgPopup="#backgroundPopup";
var bgCSS=" display:none; \n\
            position:fixed;\n\
            _position:absolute;\n\
            height:100%;\n\
            width:100%;\n\
            background: #000000; \n\
            border:1px solid  #cecece;  \n\
            ";

function createBgPopup(){
    bgDiv=$(bgPopup);
    if(bgDiv.length==0)
    {
        $("<div id='backgroundPopup' style='" +bgCSS + "'></div>").appendTo("body");
         if (window.ActiveXObject) {
             $(bgPopup).css("top",$(document).scrollTop()+"px");
         }else {
             $(bgPopup).css("top","0px");
         }
          $(bgPopup).css("left","0px");
    }
        $(bgPopup).click(function() {
            disablePopup();
        })
}

function loadPopup(idPopup,position){
    if(popupStatus==0){
        lastpopup=idPopup;
        popupStatus = 1;
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
            var ieversion=new Number(RegExp.$1);
            $("select").hide();
        }
        createBgPopup();
        setPositionPopup(position);
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $(idPopup).fadeIn("slow");


    }
}


function disablePopup(){
    if(popupStatus==1){
        $("#backgroundPopup").fadeOut("slow");
        $(lastpopup).fadeOut("slow");
        popupStatus = 0;
        //test for MSIE x.x;
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
            var ieversion=new Number(RegExp.$1);
            $("select").show("slow");
        }
        
    }
}

function setPositionPopup(position) {
    if(position=='center') {
        centerPopup();
    }
}

function centerPopup(){
    var windowWidth = document.documentElement.clientWidth;
    var topScroll= $(document).scrollTop();
    var leftScroll= $(document).scrollLeft();
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(lastpopup).height();
    var popupWidth = $(lastpopup).width();
    $(lastpopup).css({
        "position": "absolute",
        "top": windowHeight/2-popupHeight/2+topScroll,
        "left": windowWidth/2-popupWidth/2 +leftScroll
    });
    //only need force for IE6

    $(bgPopup).css({
        "height": windowHeight
    });

}

