﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(popupBG, popupMsg){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$(popupBG).css({
			"opacity": "0.85"
		});
		$(popupBG).fadeIn("slow");
		$(popupMsg).fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(popupBG, popupMsg){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$(popupBG).fadeOut("slow");
		$(popupMsg).fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(e, popupBG, popupMsg){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var height = $(popupMsg).height();
    var width = $(popupMsg).width();
    var valY=0;
    var topVal="";
    var leftVal="";
    
    valY = e.pageY;
    
    //alert(document.body.scrollHeight + ", " + windowHeight + ", " + e.clientY);
    
    if(e.pageY == null){
        valY = e.clientY;
    }
    
    if(navigator.appName == "Netscape" && valY > 500){valY = valY-200;}
    if(valY < 400){valY = 400;}

    //alert(e.pageY + "," + e.clientY + "," + navigator.appName);
    if(e != null)
    {
        leftVal=((windowWidth/2)-(width/2)-140)+"px";
        topVal=(valY-(height/2))+"px"; 
        
        $(popupMsg).css({
            "position": "absolute",
            "top":topVal,
            "left":leftVal
        }).show();
        
        $(popupBG).css({
	        "height": windowHeight
        });
	    //load popup
	    loadPopup(popupBG, popupMsg);
	}
	else
	{
	    leftVal=((windowWidth/2)-(width/2)-140)+"px";
        topVal=((windowHeight/2)-(height/2))+"px"; 
        
        $(popupMsg).css({
            "position": "absolute",
            "top":(topVal),
            "left":leftVal
        }).show();
        
        $(popupBG).css({
	        "height": windowHeight
        });
	    //load popup
	    loadPopup(popupBG, popupMsg);
	}
}
function centerPopupNoEvent(popupBG, popupMsg){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var height = $(popupMsg).height();
    var width = $(popupMsg).width();
    var valY=0;
    var topVal="";
    var leftVal="";
    
    //alert(document.body.scrollHeight + ", " + windowHeight);
    
    leftVal=((windowWidth/2)-(width/2)-140)+"px";
    topVal=((windowHeight/2)-(height/2))+"px"; 
    
    $(popupMsg).css({
        "position": "absolute",
        "top":(topVal),
        "left":leftVal
    }).show();
    
    $(popupBG).css({
        "height": windowHeight
    });
    //load popup
    loadPopup(popupBG, popupMsg);
}

function centerPopupMsgNoEvent(popupBG, popupMsg, lbl, textMsg)
{
    //alert(e.type)
    centerPopupNoEvent(popupBG, popupMsg);
    $(lbl).text(textMsg);
    //alert($(lbl));
}

//CONTROLLING EVENTS IN jQuery
//$(document).ready(function(){
	
	//LOADING POPUP general button
	//Click the button event!
	/*
	$("#button").click(function(e){
		//centering with css
		centerPopup(e);
	    
	});
	
	//loading popup on step3 for new booking.
	$("#ctl00_ctl00_cphMainPlaceHolder_cphBody_btnConfCancel").click(function(e){
		//centering with css
		centerPopup(e);
	    
	});
	
	//CLOSING POPUP
	//Click the x event!
	$("#popupClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		//disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	//document click event!
	$(document).click(function(e){
		alert(e.type);
	});
	*/

//});
