﻿var LoadingImg = "/js/img/loading.gif";
var WarnImg = "/js/img/wrong.gif";
var PromptImg = "/js/img/right.gif";
var LoadingBgColor = "#FFFFFF";
var WarnBgColor = "#FFFFFF";
var PromptBgColor = "#EEFFEE";
var LoadingBorderColor = "#D2E1EE";
var WarnBorderColor = "#FF6C00";
var PromptBorderColor = "#66BB66";
var LoadingDefaulTitle = "正在载入，请稍候...";
var WarnDefaultTitle = "操作失败";
var PromptDefaultTitle = "操作成功";
var defaultWidth = 300;
var gHideSelects=true;
var gHideObjects=true;
var defaultHeight = 50;
var msgType = "Prompt"; // Loading/Prompt

var img,bgColor,borderColor;

function MyAlert(msg)
{
    hiddenSelectBox(window);
    DisplayPromptMessage(window, msg, 300,80);
}

function DisplayWarnMessage(Window,msg,width,height) {
	
	img = WarnImg;
	bgColor = WarnBgColor;
	borderColor = WarnBorderColor;
	msgType = "Prompt";
	if (msg == null || msg == "")
		msg = WarnDefaultTitle;
	DisplayMessage(Window,msg,width,height,msgType);
}
function DisplayPromptMessage(Window,msg,width,height) {
	
	img = PromptImg;
	bgColor = PromptBgColor;
	borderColor = PromptBorderColor;
	msgType = "Prompt";
	if (msg == null || msg == "")
		msg = PromptDefaultTitle;
	DisplayMessage(Window,msg,width,height,msgType);
}
function DisplayLoadingMessage(Window,msg,width,height) {
	
	img = LoadingImg;
	bgColor = LoadingBgColor;
	borderColor = LoadingBorderColor;
	msgType = "Loading";
	if (msg == null || msg == "")
		msg = LoadingDefaulTitle;
	DisplayMessage(Window,msg,width,height,msgType);
}
function DisplayMessage(Window,msg,width,height,msgType) {
	
	if (msg == null || msg == "")
		msg = defaultLoadingTitle;
	if (width == null || width == 0 || width == "")
		width = defaultWidth;
	if (height == null || height == 0 || height == "") 
		height = defaultHeight;
	theBody = Window.document.getElementsByTagName('BODY')[0];
	promptDiv = Window.document.getElementById("promptDiv");
	if (isNull(promptDiv)) {
		promptDiv = Window.document.createElement('div');
		theBody.appendChild(promptDiv);
	}
	else
		promptDiv.style.display = ''; 
	var promptDivStyle = promptDiv.style;
	promptDiv.id = 'promptDiv';
	var fullWidth = getViewportWidth(Window);
	var fullHeight = getViewportHeight(Window);
	var scrollTop = getScrollTop(Window);
	var scrollLeft = getScrollLeft(Window);
	promptDivStyle.top = "0px";
	promptDivStyle.left = "0px";
	promptDivStyle.width = (fullWidth+scrollLeft)+"px";
	promptDivStyle.height = (fullHeight+scrollTop)+"px";
	promptDivStyle.position = "absolute";
	promptDivStyle.opacity = "0.4";
	promptDivStyle.filter = "alpha(opacity=40)";
	promptDivStyle.background = "#FFFFFF";	
	if(msgType != "Loading") {
		promptDiv.onclick = function(){  
		  var obj = Window.document.getElementById('promptDiv');
		  if (obj != null) 
			obj.style.display = 'none';
		  obj = Window.document.getElementById('msgDiv');
		  if (obj != null) 
			obj.style.display = 'none';   
		} 
	}
	
	msgDiv = Window.document.getElementById("msgDiv");
	if (isNull(msgDiv)) {
		msgDiv = Window.document.createElement('div');
		theBody.appendChild(msgDiv);
	}
	else
		msgDiv.style.display = ''; 
	msgDiv.id = 'msgDiv';	
	var msgDivStyle = msgDiv.style;
        msgDivStyle.zIndex = 10000;
	msgDivStyle.width = width+"px";
	msgDivStyle.height = height+"px";
	msgDivStyle.border = "1px "+ borderColor +" solid";
	msgDivStyle.background = bgColor;	
	msgDivStyle.position = "absolute"; 
	height = height + 200;   
	msgDivStyle.top = ((fullHeight-height)/2+scrollTop)+"px";
	msgDivStyle.left = ((fullWidth-width)/2+scrollLeft)+"px";
	msgDiv.innerHTML = "<table width=100% height=100%><tr><td align='center' valign='middle' width='20%'><img src='"+img+"' align='absmiddle'></td><td align='left' valign='middle' style='font-size:12px;font-weight:normal'>"+msg+"</td></tr></table>";
	
	if(msgType != "Loading") {		
		msgDiv.onclick = function(){  
		  var obj = Window.document.getElementById('promptDiv');
		  if (obj != null) 
			obj.style.display = 'none';
		  obj = Window.document.getElementById('msgDiv');
		  if (obj != null) 
			obj.style.display = 'none';   
		} 
	} 
	
	window.setTimeout('dispear();', 3000);
}

function centerPopWin_bak(width, height) {
	
	var promptDiv = document.getElementById("promptDiv");
	if (width == null || isNaN(width)) {
		width = promptDiv.offsetWidth;
	}
	if (height == null) {
		height = promptDiv.offsetHeight;
	}
	
	//var theBody = document.documentElement;
	var theBody = document.getElementsByTagName("BODY")[0];
	//theBody.style.overflow = "hidden";
	var scTop = parseInt(getScrollTop(window),10);
	var scLeft = parseInt(theBody.scrollLeft,10);

	var fullHeight = getViewportHeight(window);
	var fullWidth = getViewportWidth(window);
	
	promptDiv.style.top = (scTop + ((fullHeight - height) / 2)) + "px";
	promptDiv.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
	
	window.setTimeout('dispear();', 2000);
}

/**
 * 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 getViewportHeight(Window) {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth(Window) {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}

/**
 * Gets the real scroll top
 */
function getScrollTop(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 getScrollLeft(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;
	}
}

function isNull(obj){
	
	if (typeof(obj) == "undefined")
	  return true;
	  
	if (obj == undefined)
	  return true;
	  
	if (obj == null)
	  return true;
	 
	return false;
}

function dispear(){
	
	var promptDiv = document.getElementById('promptDiv');
	var msgDiv = document.getElementById('msgDiv');
	if (promptDiv != null)
	{
		promptDiv.style.display = 'none';
		if(msgDiv != null)
			msgDiv.style.display = 'none';
		displaySelectBox(window);
	}
}

function displaySelectBox(win) {
	
	var selects = win.document.getElementsByTagName("SELECT");
	var objects = win.document.getElementsByTagName("OBJECT");
	if(gHideSelects)
	{
		for(var i = 0; i < selects.length; i++) {
			selects[i].style.visibility="visible";
		}
	}
	if(gHideObjects)
	{
		for(var i = 0; i < objects.length; i++) {
			objects[i].style.visibility="visible";
		}
	}
}

function hiddenSelectBox(win) {
	
	var selects = win.document.getElementsByTagName("SELECT");
	var objects = win.document.getElementsByTagName("OBJECT");
	if(gHideSelects)
	{
		for(var i = 0; i < selects.length; i++) {
			selects[i].style.visibility="hidden";
		}
	}
	if(gHideObjects)
	{
		for(var i = 0; i < objects.length; i++) {
			objects[i].style.visibility="hidden";
		}
	}
}