﻿//SETTING UP OUR POPUP  
//0 means disabled; 1 means enabled;
var fmsupopupStatus = 0;
var showThankYou = false;

//loading popup with jQuery magic!  
function loadFMSUPopup(displayDiv) {
    //loads popup only if it is disabled
    if (fmsupopupStatus == 0) {
        $("#FastMailSignUpbackgroundPopup").css({
            "opacity": "0.7"
        });
        $("#FastMailSignUpbackgroundPopup").fadeIn("slow");
        $(displayDiv).fadeIn("slow");
        fmsupopupStatus = 1;
    }
}

//disabling popup with jQuery magic!  
function disableFMSUPopup(displayDiv) {
    //disables popup only if it is enabled
    if (fmsupopupStatus == 1) {
        $("#FastMailSignUpbackgroundPopup").fadeOut("slow");
        $(displayDiv).fadeOut("slow");
        fmsupopupStatus = 0;
    }
}

//centering popup
function centerFMSUPopup(displayDiv) {
    //request data for centering  
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(displayDiv).height();
    var popupWidth = $(displayDiv).width();
    
    //centering
    $(displayDiv).css({
        "position": "fixed",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });

	if (jQuery.browser.msie) {
		if(parseInt(jQuery.browser.version) == 6) {
		//only need force for IE6
		
		windowHeight = $("body").height();
		
			$("#FastMailSignUppopupContact").css({
				"position": "absolute"
			});
			$("#FastMailSignUppopupContactThankYou").css({
				"position": "absolute"
			});
			$("#FastMailSignUpbackgroundPopup").css({
				"position": "absolute",
				"height": windowHeight
			});
		}
	}

}

$(document).ready(function() {
    if (showThankYou) {
        //centering with css
        centerFMSUPopup("#FastMailSignUppopupContactThankYou");
        //load popup
        loadFMSUPopup("#FastMailSignUppopupContactThankYou");
        showThankYou = false;
    }
    //following code will be here
    //LOADING POPUP
    //Click the button event
    $("#button2").click(function() {
        //centering with css
        centerFMSUPopup("#FastMailSignUppopupContact");
        //load popup
        loadFMSUPopup("#FastMailSignUppopupContact");

    });

    //CLOSING Contact POPUP  
    //Click the x event!
    $("#FastMailSignUppopupContactClose").click(function() {
        disableFMSUPopup("#FastMailSignUppopupContact");
    });

    //CLOSING Thankyou POPUP  
    //Click the x event!
    $("#FastMailSignUppopupContactThankYouClose").click(function() {
        disableFMSUPopup("#FastMailSignUppopupContactThankYou");
    });
});
