var popupStatus = {};
var clickedPopUp = '';
//loading popup with jQuery magic!
function loadPopup(popupId) {
    //loads popup only if it is disabled 
    if(popupStatus[popupId]==0){ 
        $(".backgroundPopup").css({ 
            "opacity": "0.2" 
        }); 
        $(".backgroundPopup").fadeIn("slow"); 
        $("#" + popupId).fadeIn("fast"); 
        popupStatus[popupId] = 1; 
    } 
} 
 
//disabling popup with jQuery magic! 
function disablePopup(popupId){ 
    //disables popup only if it is enabled
    if (popupStatus[popupId] == 1) {
        if (popupId == clickedPopUp) {
            $(".backgroundPopup").fadeOut("slow");
            $("#" + popupId).fadeOut("slow");
            popupStatus[popupId] = 0;
        }
    } 
} 
 
//centering popup 
function centerPopup(popupId){ 
    //request data for centering 
    var windowWidth = document.documentElement.clientWidth; 
    var windowHeight = document.documentElement.clientHeight; 
    var popupHeight = $("#" + popupId).height(); 
    var popupWidth = $("#" + popupId).width(); 
    //centering 
    $("#" + popupId).css({ 
        "position": "absolute", 
        "top": windowHeight/2-popupHeight/2, 
        "left": windowWidth/2-popupWidth/2 
    }); 
    //only need force for IE6 
 
    $(".backgroundPopup").css({ 
        "height": windowHeight 
    }); 
 
} 
 
 
//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {
    popupStatus = { popupContactpdf: 0, popupContact2: 0, popupContact3: 0, popupContactadv: 0,popupContact: 0,popupnews: 0,popupnews1: 0, popupContact1: 0,backgroundPopup1: 1, backgroundPopup2: 1, backgroundPopuppdf: 1, backgroundPopup: 1 };

    //LOADING POPUP 
    //Click the button event!
    $(".popuplink").click(function() {
        var popupId = $(this).attr("popup");
        clickedPopUp = popupId;
        //centering with css 
        centerPopup(popupId);
        //load popup 
        loadPopup(popupId);
    });

    //CLOSING POPUP 
    //Click the x event! 
    $(".popupContactClose").click(function() {
        var popupId = $(this).parents("div").attr("id");
        disablePopup(popupId);
    });
	    //Click out event!
    $(".backgroundPopup").click(function() {
        // close any that are open
        for (var popupId in popupStatus) {
            if (popupStatus[popupId] == 1) {
                disablePopup(popupId);
            }
        }
    });
	$(
".yes").click(function() {
disablePopup(
'popupContactpdf');

});

    //Press Escape event! 
    $(document).keypress(function(e) {
        var popupId = $(e.target).parents("div.popupContact").attr("id");
        if (e.keyCode == 27 && popupStatus[popupId] == 1) {
            disablePopup(popupId);
        }
    });

});
