var oCanvas = false;
var bodyScrollTop;
var msgbox = false;
var msgbox_background = false;
var selects_on_page = false;
var selects_on_msgbox = false;

document.write('<div id="msgbox_background" style="display: none;" class="opacity"></div>');

function showMsgbox(form)
{
	if (!oCanvas) oCanvas = document.getElementsByTagName((document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0];
   
	/*bodyScrollTop = document.body.scrollTop;
	document.body.style.overflow = 'hidden';*/

	msgbox = _$(form);
	if (!msgbox_background) msgbox_background = _$('msgbox_background');
	if (!selects_on_page) selects_on_page = document.getElementsByTagName('select');
	if (!selects_on_msgbox) selects_on_msgbox = msgbox.getElementsByTagName('select');
	if (selects_on_page && selects_on_page.length > 0)
	{
		for(i in selects_on_page)
		{
			//selects_on_page[i].disabled = true;
		}
	}
	
	if (selects_on_msgbox && selects_on_msgbox.length > 0)
	{
		for(i in selects_on_msgbox)
		{
			//selects_on_msgbox[i].disabled = false;
		}
	}

	show(msgbox_background);
	show(msgbox);
	document.body.onkeypress = function() {escape_press(event)};

	centerMsgbox();
	window.onresize = centerMsgbox;
}

function centerMsgbox()
{
	msgbox_background.style.minHeight = getDocumentHeight() + 'px';
	msgbox_background.style.height = getDocumentHeight() + 'px';
	msgbox_background.style.width = getDocumentWidth() + 'px';
	/*
	msgbox.style.top = oCanvas.scrollTop + getClientHeight()/2 - msgbox.clientHeight/2 + 'px';
	msgbox.style.left = oCanvas.scrollLeft + getClientWidth()/2 - msgbox.clientWidth/2 + 'px';
	*/
}

function hideMsgbox()
{
	if (!msgbox) msgbox_background = _$('msgbox');
	if (!msgbox_background) msgbox_background = _$('msgbox_background');

	if (selects_on_page && selects_on_page.length > 0)
	{
		for(i in selects_on_page)
		{
			//selects_on_page[i].disabled = false;
		}
	}
	
	hide(msgbox_background);
	hide(msgbox);
	document.body.onkeypress = function() {};
	
	document.body.style.overflow = '';
	document.body.scrollTop = bodyScrollTop;
}

function escape_press(event)
{
	if (event.keyCode == 27)
		hideMsgbox();
}

function getClientWidth()
{
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function getDocumentHeight()
{
	return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}

function getDocumentWidth()
{
	return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
}

function show(obj)
{
	if (typeof obj != 'object') obj = _$(obj);
	if (obj) obj.style.display = '';
}

function hide(obj)
{
	if (typeof obj != 'object') obj = _$(obj);
	if (obj) obj.style.display = 'none';
}