
var Firefox = (document.getElementById && !document.all);
var MSIE = (-1 != navigator.userAgent.indexOf('MSIE'));

function getTrueBody() {
	return(document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

/*********************************************************************
 *                         Start of mask document                    *
 *********************************************************************/

function getViewportWidth()
{
	var width = self.innerWidth;
	var mode = document.compatMode;

	if (mode || MSIE) {
		width = getTrueBody().clientWidth;
	}
	return width;
}

function getViewportHeight()
{
	var height = self.innerHeight;
	var mode = document.compatMode;

	if (mode || MSIE) {
		height = getTrueBody().clientHeight;
	}

	return height;
}

function GetDocumentWidth()
{
	var scrollWidth = getTrueBody().scrollWidth;
	return Math.max(scrollWidth, getViewportWidth());
}

function GetDocumentHeight()
{
	var scrollHeight = getTrueBody().scrollHeight;
	return Math.max(scrollHeight, getViewportHeight());
}

function DocumentMaskReSize()
{
	var div = document.getElementById('document_mask');
	
	if (div) {
		div.style.width = GetDocumentWidth();
		div.style.height = GetDocumentHeight();
		/*
		if (MSIE) {
			var iframe = document.getElementById('document_mask_iframe');
			iframe.style.width = div.style.width;
			iframe.style.height = div.style.height;
		}
		*/
	}
}

function DocumentMask(message)
{
	var div;
	div = document.getElementById('document_mask');
	if (!div) {
		div = document.createElement('DIV');
		div.id = 'document_mask';
		document.body.appendChild(div);

		div.maskMsg = document.createElement('DIV');
		document.body.appendChild(div.maskMsg);
		if (typeof message == 'string') {
			div.maskMsg.innerHTML = '<img border="0" src="/2008/images/loading.gif" width="16" height="16" align="texttop"> '+message;
		} else {
			div.maskMsg.innerHTML = '<img border="0" src="/2008/images/loading.gif" width="16" height="16" align="middle">';
		}
		

		/* This iframe is to fix the IE6 problem. In IE6, the <select> will
		 * always on top if we don't use iframe to overwrite it.
		 */
		/*
		if (MSIE) {
			iframe = document.createElement('IFRAME');
			iframe.id = 'document_mask_iframe';
			document.body.appendChild(iframe);
		}
		*/
	}
	div.style.top = 0;
	div.style.left = 0;
	div.style.zIndex = 1;//10000;
	div.style.width = GetDocumentWidth();
	div.style.height = GetDocumentHeight();
	div.style.display = 'block';
	div.style.position = 'absolute';
	div.style.filter = "alpha(opacity:50)";
	div.style.KHTMLOpacity = 0.5;
	div.style.MozOpacity = 0.5;
	div.style.opacity = 0; //0.5;
	//div.style.background = '#FFFFFF' //'#ccc';

	div.maskMsg.style.border = 'double #c3daf9';
	div.maskMsg.style.backgroundColor = '#ffffff';
	div.maskMsg.style.position = 'absolute';
	div.maskMsg.style.display = 'block';
	div.maskMsg.style.fontSize = '12px';
	div.maskMsg.style.fontFamily = 'Arial, Helvetica, sans-serif';
	div.maskMsg.style.color = '#333333';
	div.maskMsg.style.padding = '5px 10px';
	div.maskMsg.style.top = parseInt(document.body.scrollTop)+ (getViewportHeight()/2) - (parseInt(div.maskMsg.clientHeight) / 2);
	div.maskMsg.style.left = (getViewportWidth()/2) - (parseInt(div.maskMsg.clientWidth)/2) + parseInt(document.body.scrollLeft); 
	div.maskMsg.style.zIndex = div.style.zIndex + 1;


	/*
	if (MSIE) {
		iframe.style.top = 0;
		iframe.style.left = 0;
		iframe.style.zIndex = div.style.zIndex - 1;
		iframe.style.display = 'block';
		iframe.style.position = 'absolute';
		iframe.style.border = 0;
		iframe.style.width = div.style.width;
		iframe.style.height = div.style.height;
		iframe.style.filter = "alpha(opacity:0)";
		iframe.style.KHTMLOpacity = 0;
		iframe.style.MozOpacity = 0;
		iframe.style.opacity = 0;
	}
	*/

	window.onresize = DocumentMaskReSize;
}

function DocumentUnMask()
{
	var div = document.getElementById('document_mask');
	
	if (!div) {
		return;
	}
	/*
	if (MSIE) {
		var iframe = document.getElementById('document_mask_iframe');
		iframe.style.display = 'none';
	}
	*/
	div.maskMsg.style.display = 'none';
	div.style.display = 'none';

	window.onresize = null;
}

