var popupStatus = 0;
var wsSetFadeIn = 0;
var wsSB_AM = 1;
var wsInputID = "";
function wsMessage(wsMelding,wsTime,wsFadeIn,wsAC,wsSessionID) {
    wsSetFadeIn = wsFadeIn;
    wsTime = wsTime * 1000;
    $('#popupMessage').html(wsMelding);
    setTimeout("disablepopup()", wsTime);
    loadpopup();
    wsInputID = "#" + wsAC
    wsSB_AM = $(wsInputID).val();
    jQuery.post("#",{MYVAR: "90", SB_AC: wsAC, SB_AM: wsSB_AM, SessionID: wsSessionID});
}

function loadpopup(){
    centerpopup();
    if(popupStatus==0){                     
        $("#backgroundpopup").css({
            "opacity": "0.7"
        });
        if (wsSetFadeIn==1) {
            $("#backgroundpopup").fadeIn("slow");
        }
        $("#popupContact").fadeIn("slow");
        popupStatus = 1;
    }
}

function disablepopup(){
    if(popupStatus==1){
        $("#backgroundpopup").fadeOut("slow");
        $("#popupContact").fadeOut("slow");
        popupStatus = 0;
    }
}

function centerpopup(){
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContact").height();
    var popupWidth = $("#popupContact").width();

    $("#popupContact").css({
        "position": "fixed",
        "top": (windowHeight - popupHeight) / 2,
        "left": (windowWidth - popupWidth) / 2
    });

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

$(document).ready(function(){

    $("#popupContactClose").click(function(){
        disablepopup();
    });

    $("#backgroundpopup").click(function(){
        disablepopup();
    });
    
    $(document).keypress(function(e){
        if(e.keyCode==27 && popupStatus==1){
            disablepopup();
        }

    });

});


