// JavaScript Document
/***********************************
 * author: zhouzhonghua
 * loading.....
 * create time: 2007-12-24
 ***********************************/
 var loadingImg = "/images/loading.gif";
function PostLoading(msg,width,height) {
	hideSelectBoxes();
	if (msg == null || msg == "") {
		msg = "正在载入，请稍候...";
	}
	if (width == null || width == 0 || width == "") {
		width = 300;
	}
	if (height == null || height == 0 || height == "") {
		height = 150;
	}
	theBody = document.getElementsByTagName('BODY')[0];
	maskDiv = document.createElement('div');
	maskDiv.id = 'maskDiv';
	var fullWidth = getViewportWidthOfWindow(window);
	var fullHeight = getViewportHeightOfWindow(window);
	var scrollTop = getScrollTopOfWindow(window);
	var scrollLeft = getScrollLeftOfWindow(window);
	maskDiv.style.top = "0px";
	maskDiv.style.left = "0px";
	maskDiv.style.width = (fullWidth+scrollLeft)+"px";
	maskDiv.style.height = (fullHeight+scrollTop)+"px";
	maskDiv.style.position = "absolute";
	maskDiv.style.opacity = ".4";
	maskDiv.style.filter = "alpha(opacity=40)";
	maskDiv.style.background = "#FFFFFF";
	theBody.appendChild(maskDiv);
	loadDiv = document.createElement('div');
	loadDiv.id = 'loadDiv';
	//loadDiv.style = width+"px;"+height+"px;border:1px #6699CC solid;";
	loadDiv.style.width = width+"px";
	loadDiv.style.height = height+"px";
	loadDiv.style.border = "1px #6699CC solid";
	loadDiv.style.background = "#EFEFEF";
	loadDiv.align = "center";
	loadDiv.style.position = "absolute";
	loadDiv.innerHTML = "<table width=100% height=100%><tr><td align=center valign=middle><img src='"+loadingImg+"' align='absmiddle'>&nbsp;"+msg+"</td></tr></table>";
	theBody.appendChild(loadDiv);
	centerLoadWin(width,height);
}

function hideLoading() {
	if (document.getElementById("maskDiv")) {
		document.getElementById("maskDiv").style.display = 'none';
	}
	if (document.getElementById("loadDiv")) {
		document.getElementById("loadDiv").style.display = 'none';
	}
}

function WindowLoading(Window,msg,width,height) {
	if (Window == undefined) {
		return;
	}
	if (msg == null || msg == "") {
		msg = "正在载入，请稍候...";
	}
	if (width == null || width == 0 || width == "") {
		width = 300;
	}
	if (height == null || height == 0 || height == "") {
		height = 200;
	}
	theBody = Window.document.getElementsByTagName('BODY')[0];
	if (!theBody) {
		return;
	}
	maskDiv = Window.document.getElementById("maskDiv");
	if (maskDiv == "undefinded" || maskDiv == window.undefined) {
		maskDiv = Window.document.createElement('div');
		theBody.appendChild(maskDiv);
	}
	maskDiv.id = 'maskDiv';
	var fullWidth = getViewportWidthOfWindow(Window);
	var fullHeight = getViewportHeightOfWindow(Window);
	var scrollTop = getScrollTopOfWindow(Window);
	var scrollLeft = getScrollLeftOfWindow(Window);
	maskDiv.style.top = "0px";
	maskDiv.style.left = "0px";
	maskDiv.style.width = (fullWidth+scrollLeft)+"px";
	maskDiv.style.height = (fullHeight+scrollTop)+"px";
	maskDiv.style.position = "absolute";
	maskDiv.style.opacity = ".4";
	maskDiv.style.filter = "alpha(opacity=40)";
	maskDiv.style.background = "#FFFFFF";
	loadDiv = Window.document.getElementById("loadDiv");
	if (loadDiv == "undefinded" || loadDiv == window.undefined) {
		loadDiv = Window.document.createElement('div');
	}
	loadDiv.id = 'loadDiv';
	//loadDiv.style = width+"px;"+height+"px;border:1px #6699CC solid;";
	loadDiv.style.width = width+"px";
	loadDiv.style.height = height+"px";
	loadDiv.style.border = "1px #6699CC solid";
	loadDiv.style.background = "#EFEFEF";
	loadDiv.align = "center";
	loadDiv.style.position = "absolute";
	loadDiv.style.top = ((fullHeight-height)/2+scrollTop)+"px";
	loadDiv.style.left = ((fullWidth-width)/2+scrollLeft)+"px";
	loadDiv.innerHTML = "<table width=100% height=100%><tr><td align=center valign=middle><img src='"+loadingImg+"' align='absmiddle'>&nbsp;"+msg+"</td></tr></table>";
	theBody.appendChild(loadDiv);
	//centerLoadWin(width,height);
}

function centerLoadWin(width, height) {
	var loadDiv = document.getElementById("loadDiv");
	if (width == null || isNaN(width)) {
		width = loadDiv.offsetWidth;
	}
	if (height == null) {
		height = loadDiv.offsetHeight;
	}
	
	//var theBody = document.documentElement;
	var theBody = document.getElementsByTagName("BODY")[0];
	//theBody.style.overflow = "hidden";
	var scTop = parseInt(getScrollTopOfWindow(window),10);
	var scLeft = parseInt(theBody.scrollLeft,10);

	var fullHeight = getViewportHeightOfWindow(window);
	var fullWidth = getViewportWidthOfWindow(window);
	
	loadDiv.style.top = (scTop + ((fullHeight - height) / 2)) + "px";
	loadDiv.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeightOfWindow(Window) {
	if (Window.innerHeight!=window.undefined) return Window.innerHeight;
	if (Window.compatMode=='CSS1Compat') return Window.document.documentElement.clientHeight;
	if (Window.document.body) return Window.document.body.clientHeight; 

	return Window.undefined; 
}
function getViewportWidthOfWindow(Window) {
	var offset = 17;
	var width = null;
	if (Window.innerWidth!=window.undefined) return Window.innerWidth; 
	if (Window.document.compatMode=='CSS1Compat') return Window.document.documentElement.clientWidth; 
	if (Window.document.body) return Window.document.body.clientWidth; 
}

/**
 * Gets the real scroll top
 */
function getScrollTopOfWindow(Window) {
	if (self.pageYOffset) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if (Window.document.documentElement && Window.document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		return Window.document.documentElement.scrollTop;
	}
	else if (Window.document.body) // all other Explorers
	{
		return Window.document.body.scrollTop;
	}
}
function getScrollLeftOfWindow(Window) {
	if (self.pageXOffset) // all except Explorer
	{
		return self.pageXOffset;
	}
	else if (Window.document.documentElement && Window.document.documentElement.scrollLeft)
		// Explorer 6 Strict
	{
		return Window.document.documentElement.scrollLeft;
	}
	else if (Window.document.body) // all other Explorers
	{
		return Window.document.body.scrollLeft;
	}
}
/**
* Hides all drop down form select boxes on the screen so they do not appear above the mask layer.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
*
* Thanks for the code Scott!
*/
function hideSelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
				document.forms[i].elements[e].style.visibility="hidden";
			}
		}
	}
}
