﻿$(document).ready(function() {
    if (Sys != null) {
        var manager = Sys.WebForms.PageRequestManager.getInstance();
        manager.add_endRequest(endRequest);
        manager.add_beginRequest(OnBeginRequest);
    }

    function OnBeginRequest(sender, args) {
        CenterAJAXGif();
        loadPopup();
    }
    function endRequest(sender, args) {
        disablePopup();
    }

    //loading popup with jQuery 
    function loadPopup() {
        $("#backgroundPopup").css({ "opacity": "0.3" });
        $("#backgroundPopup").fadeIn("slow");
        $("#popupContact").fadeIn("slow");
    }

    //disabling popup with jQuery 
    function disablePopup() {
        $("#backgroundPopup").fadeOut("fast");
        $("#popupContact").fadeOut("fast");
    }

    function CenterAJAXGif() {
        //request data for centering  
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var popupHeight = $("#popupContact").height();
        var popupWidth = $("#popupContact").width();

        //centering  
        $("#popupContact").css({
            "position": "fixed",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });

        //only need force for IE6  	  
        $("#backgroundPopup").css({
            "height": windowHeight
        });
    }
});    
