//SETUP POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;
var popupHeight = null;
var popupWidth = null;
var width = null;
var height = null;

//loading popup
function loadPopup(script,pageid,accountid,width,height,asp_option){

	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	if(!height) {
		popupHeight = $("#popupLayer").height(); }
		else {
		popupHeight = height; }

	if(!width) {
		popupWidth = $("#popupLayer").width(); }
		else {
		popupWidth = width; }


	//centering & sizing
	$("#popupLayer").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2 + "px",
		"left": windowWidth/2-popupWidth/2 + "px",
		"width": popupWidth + "px",
		"height": popupHeight + "px"
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});

	if (asp_option=="true") {
		varScript = script
	}
	else {
		var varScript = script + ".asp";
		var varScript = varScript + "?P=" + pageid;
	}
	
	$("#backgroundPopup").css({
		"opacity": "0.7"
	});
	$("#backgroundPopup").fadeIn("slow");
	$("#popupLayer").fadeIn("slow");
	$("#popupLayer").load(varScript);
	popupStatus = 1;

}


//disabling popup
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupLayer").fadeOut("slow", function() {
			$("#popupLayer").html("");										  
		});
		popupStatus = 0;
	}
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//CLOSING POPUP
	//Click the x event!
	$("#popupLayerClose").click(function(){
		disablePopup();
	});

	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});