﻿//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(popup_id, modal) {
	//loads popup only if it is disabled
	if (popupStatus == 0) {
		if (modal) {
			jQuery("#backgroundPopup").css({
				"opacity": "0.7"
			});
			jQuery("#backgroundPopup").fadeIn("slow");
		}
		jQuery(popup_id).fadeIn("slow");
		popupStatus = 1;
	}
}
//centering popup
function centerPopup( popup_id ) {
	//request data for centering
//	var windowWidth = document.documentElement.clientWidth; 
//	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $j(popup_id).height();
	var popupWidth = $j(popup_id).width();
	//centering
	jQuery(popup_id).css({
		"position": "absolute",
		"top": windowHeight() / 2 - popupHeight / 2,
		"left": windowWidth() / 2 - popupWidth / 2
	});
	//only need force for IE6

	jQuery("#backgroundPopup").css({
		"height": windowHeight()
	});

}

function positionPopup(popup_id, top, left) {
	jQuery(popup_id).css({
		"position": "absolute",
		"top": top,
		"left": left
	});
	//only need force for IE6

	jQuery("#backgroundPopup").css({
		"height": windowHeight()
	});

}

function windowWidth() {
	var myWidth = 0;
	if (typeof (window.innerWidth) == 'number') {
		myWidth = window.innerWidth;
	} else if (document.documentElement
		&& document.documentElement.clientWidth
		) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if (document.body
		&& document.body.clientWidth
		) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	return myWidth;
}		
	
function windowHeight() {
	var myHeight = 0;
	if (typeof (window.innerWidth) == 'number') {
		myHeight = window.innerHeight;
	} else if (document.documentElement
		&& document.documentElement.clientHeight
		) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if (document.body
		&& document.body.clientHeight
		) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}		
	
//disabling popup with jQuery magic!
function disablePopup( popup_id ) {
    //disables popup only if it is enabled
	if (popupStatus == 1) {
		jQuery("#backgroundPopup").fadeOut("slow");
		jQuery(popup_id).fadeOut("slow");
		popupStatus = 0;
	}
}

