﻿//SETTING UP OUR POPUP  
//0 means disabled; 1 means enabled;
var mcpopupStatus = 0;
var myCatalogError = false;

//loading popup with jQuery magic!  
function loadMCPopup() {
    //loads popup only if it is disabled
    if (mcpopupStatus == 0) {
        $("#MCbackgroundPopup").css({
            "opacity": "0.7"
        });
        $("#MCbackgroundPopup").fadeIn("slow");
        $("#MCpopupContact").fadeIn("slow");
        mcpopupStatus = 1;
    }
}

//disabling popup with jQuery magic!  
function disableMCPopup() {
    //disables popup only if it is enabled
    if (mcpopupStatus == 1) {
        $("#MCbackgroundPopup").fadeOut("slow");
        $("#MCpopupContact").fadeOut("slow");
        mcpopupStatus = 0;
    }
}

//centering popup
function centerMCPopup() {
    //request data for centering  
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#MCpopupContact").height();
    var popupWidth = $("#MCpopupContact").width();
    //centering
    $("#MCpopupContact").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();
		
			$("#MCbackgroundPopup").css({
				"height": windowHeight,
				"position": "absolute"
			});
			$("#MCpopupContact").css({
				"position": "absolute"
			});
		}
	}
}

$(document).ready(function() {
    if (myCatalogError) {
        //centering with css
        centerMCPopup();
        //load popup
        loadMCPopup();
    }

    //following code will be here
    //LOADING POPUP  
    //Click the button event!
    $("#button").click(function() {
        //centering with css
        centerMCPopup();
        //load popup
        loadMCPopup();
    });

    //CLOSING POPUP  
    //Click the x event!
    $("#MCpopupContactClose").click(function() {
        disableMCPopup();
    });
});

function ShowPopup() {
    $(document).ready(function() {
        $("error").removeClass().addClass("show");
        //centering with css
        centerMCPopup();
        //load popup
        loadMCPopup();
    });
}
