//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
// optimize on speed by SailorMax
//
function getPageSize()
{
	var d = document;
	var db = d.body;
	var de = d.documentElement;
	var w = window;

	var xScroll, yScroll;
	if (w.innerHeight && w.scrollMaxY) {
		xScroll = db.scrollWidth;
		yScroll = w.innerHeight + w.scrollMaxY;
	} else if (db.scrollHeight > db.offsetHeight) { // all but Explorer Mac
		xScroll = db.scrollWidth;
		yScroll = db.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = db.offsetWidth;
		yScroll = db.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (de && de.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = de.clientWidth;
		windowHeight = de.clientHeight;
	} else if (db) { // other Explorers
		windowWidth = db.clientWidth;
		windowHeight = db.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	pageHeight	= (yScroll < windowHeight ? windowHeight : yScroll);
	// for small pages with total width less then width of the viewport
	pageWidth	= (xScroll < windowWidth ? windowWidth : xScroll);

	return [pageWidth, pageHeight, windowWidth, windowHeight];
}

var popup_div = "";
var popup_form = "";
var popup_stack = [];
var zIndex = 80;
function ShowPopup(form, vars)
{
	zIndex += 12;
	if (popup_div)
	{
		if (!window.XMLHttpRequest)
		{
			var els = popup_form.getElementsByTagName("SELECT");
			for (var i=0; i<els.length; i++)
				els[i].style.visibility = "hidden";
		}
		popup_stack.push([popup_div, popup_form]);
	}

	var psize = getPageSize();
	popup_div = document.createElement("DIV");
	var ss = "z-index:" + zIndex + "; position:absolute; top:0; left:0; width:100%; height:" + (psize[1]*2) + "px; background:white;";

	if (typeof(popup_div.style.filter) != "undefined")
		popup_div.style.setAttribute("cssText", ss);
	else
		popup_div.setAttribute("style", ss)

	if ((typeof(popup_div.style.filter) != "undefined"))
//				popup_div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/bg_white.png', sizingMethod=scale)";
		popup_div.style.filter = "alpha(opacity=70)";
	else
//				popup_div.style.background = "transparent url(/images/bg_white.png) 0 0 repeat";
		popup_div.style.opacity = "0.7";


	var myHeight = 400;
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	popup_form = document.getElementById(form).cloneNode(true);
	var ss = "z-index:" + (zIndex+10) + "; position:absolute; top:" + (document.documentElement.scrollTop+(myHeight/2-200)) + "px; left:23%; display:block; width:54%;";

	if (typeof(popup_div.style.filter) != "undefined")
		popup_form.style.setAttribute("cssText", ss);
	else
		popup_form.setAttribute("style", ss)

	popup_div.onmousedown = function()
	{
		return false;
	}

	if (form.substr(0, 3) == "msg")
	{
		if (window.XMLHttpRequest)
		{
			popup_form.style.position = "fixed";
			popup_form.style.top = "200px";
		}
		else
		{
			document.documentElement.onscroll = function()
			{
				popup_form.style.top = (document.documentElement.scrollTop+200) + "px";
			}
		}
	}

	eval(form+"InitPopup(vars, popup_form);");
	document.body.appendChild(popup_div);
	document.body.appendChild(popup_form);
}

function ClosePopup()
{
	if (!window.XMLHttpRequest)
		document.documentElement.onscroll = "";

	document.body.removeChild(popup_div);
	document.body.removeChild(popup_form);

	if (popup_stack.length)
	{
		var item = popup_stack.pop();
		popup_div = item[0];
		popup_form = item[1];

		if (!window.XMLHttpRequest)
		{
			var els = popup_form.getElementsByTagName("SELECT");
			for (i=0; i<els.length; i++)
				els[i].style.visibility = "visible";
		}
	}
	zIndex--;
}
