﻿function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d = parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	obj.visibility=v; }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);







function $(objectId)
{
	if(document.getElementById && document.getElementById(objectId)) 
	{
		// W3C DOM
		return document.getElementById(objectId);
	} 
	else if (document.all && document.all(objectId)) 
	{
		// MSIE 4 DOM
		return document.all(objectId);
	} 
	else if (document.layers && document.layers[objectId]) 
	{
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
	} 
	else 
	{
		return (false);
	}
}




function _Trim(str)
{
	var re = /\s*(\S[^\0]*\S)\s*/;
	re.exec(str);
	return RegExp.$1;
}

function Trim(str){
	return str.replace(/^s*/g,"").replace(/s*$/g,"");
}

String.prototype.replaceAll  = function(s1,s2){    
	return this.replace(new RegExp(s1,"gm"),s2);    
}

function FrameSet(cols)
{
	window.parent.document.getElementById("FrameSet").cols = "" + cols + ",7,*";
	window.parent.document.getElementById("FrameMain").src = "Welcome.asp";
}



function MainFrameSet(cols)
{
	window.parent.document.getElementById("FrameMain").cols = "*," + cols + "";
}



function sAlert(str, CloseView, ViewType)
{
	var msgw, msgh, bordercolor;
	msgw = 400; //# 提示窗口的宽度
	msgh = 100; //# 提示窗口的高度
	titleheight = 15 //# 提示窗口标题高度
	bordercolor = "#336699"; //# 提示窗口的边框颜色
	titlecolor = "#99CCFF"; //# 提示窗口的标题颜色


	var sWidth, sHeight;
	sWidth = document.body.clientWidth
	sHeight = document.body.clientHeight;

	//sHeight = screen.availHeight - window.screenTop;
	//sHeight = screen.height;

	var bgObj = document.createElement("div");
	bgObj.setAttribute("id", "bgDiv");
	bgObj.style.position = "absolute";
	bgObj.style.top = "0";
	bgObj.style.background = "#000000";
	bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3, opacity=25, finishOpacity=75);";
	bgObj.style.opacity = "0.6";
	bgObj.style.left = "0";
	bgObj.style.width = sWidth + "px";
	bgObj.style.height = sHeight + "px";
	bgObj.style.zIndex = "10000";
	document.body.appendChild(bgObj);


	
	var msgObj = document.createElement("div");
	msgObj.setAttribute("id", "msgDiv");
	msgObj.setAttribute("align", "center");
	msgObj.style.background = "#FFFFFF";
	msgObj.style.border = "1px solid " + bordercolor;
	msgObj.style.position = "absolute";
	msgObj.style.left = "50%";
	msgObj.style.top = "50%";
	msgObj.style.font = "10px Verdana, Geneva, Arial, Helvetica, sans-serif";
	msgObj.style.marginLeft = "-225px" ;
	msgObj.style.marginTop = document.documentElement.scrollTop - 75 + "px";
	msgObj.style.width = msgw + "px";
	msgObj.style.height = msgh + "px";
	msgObj.style.textAlign = "left";
	msgObj.style.lineHeight = "20px";
	msgObj.style.zIndex = "10001";

	document.body.appendChild(msgObj);



	if (CloseView == 1)
	{
		var title = document.createElement("h4");
		title.setAttribute("id","msgTitle");
		title.setAttribute("align","right");
		title.style.margin = "0";
		title.style.padding = "3px";
		title.style.background = bordercolor;
		title.style.filter = "progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100, style=1, opacity=75, finishOpacity=100);";
		title.style.opacity = "0.75";
		title.style.border = "1px solid " + bordercolor;
		title.style.height = titleheight + "px";
		title.style.font = "10px Verdana, Geneva, Arial, Helvetica, sans-serif";
		title.style.color = "#FFFFFF";
		title.style.cursor = "pointer";
		title.innerHTML= "CLOSE";

		document.getElementById("msgDiv").appendChild(title);

		title.onclick = function() {
			document.getElementById("msgDiv").removeChild(txt);
			document.getElementById("msgDiv").removeChild(title);
			document.body.removeChild(msgObj);
			document.body.removeChild(bgObj);
		}

	}


	var txt = document.createElement("p");
	txt.style.margin = "1em 0"
	txt.style.padding = "0 10 0 10 px;"
	txt.setAttribute("id", "msgTxt");
	txt.innerHTML = str;
	document.getElementById("msgDiv").appendChild(txt);


	if (ViewType == 0)
	{
		document.getElementById("msgDiv").removeChild(txt);

		if (CloseView == 1)
		{
			document.getElementById("msgDiv").removeChild(title);
		}
		document.body.removeChild(msgObj);
		document.body.removeChild(bgObj);
	}
}



// 切换样式
function ChangeStyle(StyleName)
{
	event.srcElement.className = StyleName;
}


function Href(Url)
{
	window.location.href=Url;
	return (false);
}


// 切换样式
function ChangeMessageStyle(o, StyleType)
{
	if (StyleType == 1)
	{
		$("WarningMessage_" + o.id).className = "MessageStyle";
	}
	else
	{
		$("WarningMessage_" + o.id).className = "";
	}
}



// 提交前确认
function DoConfirm(ConfirmMsg, href)
{
	if (!confirm(ConfirmMsg))
	{
		return (false);
		window.event.returnValue = false;
	}
	else
	{
		location.href = href;
	}
}



function Disabled(obj, StatusType)
{
	if (StatusType == 0)
	{
		$(obj).disabled = false;
	}

	if (StatusType == 1)
	{
		$(obj).disabled = true;
	}
}




// 回车光标移到下个文本域
function EnterTab()
{
	if (event.keyCode == 13)
	{
		event.keyCode = 9;
	}


	if (event.keyCode == 38)
	{
		event.shiftKey = true;
		event.keyCode = 9;
	}
}




// 只能输入数字
function OnlyNumber()
{
	if ((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode != 46))
	{
		event.returnValue = false;
	}
}



// 设置相同值
function SameValue(objOne, objTwo)
{
	$(objOne).value = $(objTwo).value;
}



// 调整窗体大小并自动居中窗体
function Move2Center(w_width, w_height)
{
	var popUpLocationX = Math.round((screen.availWidth - w_width) / 2);
	var popUpLocationY = Math.round((screen.availHeight - w_height) / 2);
	if (popUpLocationX < 0) popUpLocationX = 0;
	if (popUpLocationY < 0) popUpLocationY = 0;

	window.moveTo(popUpLocationX, popUpLocationY);
	window.resizeTo(w_width, w_height);
}



// 关闭父窗口
function CloseParent()
{
	parent.opener = null;
	parent.close();
}


// 操作警告信息开启或关闭
function ControlLayer(LayerID, LayerType, LayerState)
{
	// 关闭层
	if (LayerState == 0)
	{
		if (LayerType == 0)
		{
			parent.$(LayerID).style.visibility = "hidden";
			return (false);
		}
		else
		{
			$(LayerID).style.visibility = "hidden";
			return (false);
		}
	}


	// 显示层
	if (LayerState == 1)
	{
		if (LayerType == 0)
		{
			parent.$(LayerID).style.visibility = "visible";
			return (false);
		}
		else
		{
			$(LayerID).style.visibility = "visible";
			return (false);
		}
	}
}



// 控制显示样式(彩色或者黑白)

var ColorType = 0;
function ChangeColor()
{

	BodyHTML = document.getElementsByTagName("body");

	if (ColorType == 0)
	{
		BodyHTML[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
		ColorType = 1;
	}
	else
	{
		BodyHTML[0].style.filter = "";
		ColorType = 0;
	}

}



// 跳转控制
function FrameHref(Href)
{
	parent.frames["MainFrame"].location.href=Href;
}



// 显示图标提示
function CheckImage(ObjID, StyleType, Message)
{
	switch(StyleType)
	{
		case 1:
			ImageStyle = "<img src=\"..\/Images\/Icon\/Icon_Right.gif\" alt=\"正确信息\" width=\"16\" height=\"16\" align=\"absmiddle\" \/> <font color=\"#009900\"><strong>" + Message + "<\/strong><\/font>";
			break;

		case 2:
			ImageStyle = "<img src=\"..\/Images\/Icon\/Icon_Wrong.gif\" alt=\"错误信息\" width=\"16\" height=\"16\" align=\"absmiddle\" \/> <font color=\"#FF0000\"><strong>" + Message + "<\/strong><\/font>";
			break;

		case 3:
			ImageStyle = "<img src=\"..\/Images\/Icon\/Icon_Unknown.gif\" alt=\"未知信息\" width=\"16\" height=\"16\" align=\"absmiddle\" \/> <font color=\"#0044CC\"><strong>" + Message + "<\/strong><\/font>";
			break;

		case 4:
			ImageStyle = "<img src=\"..\/Images\/Icon\/Icon_Loading.gif\" alt=\"信息读取中...\" width=\"16\" height=\"16\" align=\"absmiddle\" \/> <font color=\"#666666\"><strong>" + Message + "<\/strong><\/font>";
			break;

		default:
			break;
	}

	$(ObjID).innerHTML = ImageStyle;
}



function VoidIt(ShipmentID)
{
	DoConfirm("Are you true void this Shipment?", "Shipment_History.asp?Method=VoidIt&ShipmentID=" + ShipmentID);
}

function LenBarCodeLength(CodeLength)
{
     var i,sum,ArrayCode;
     sum=0;
	 ArrayCode = CodeLength.split("");
     for(i=0;i<ArrayCode.length;i++)
     {
         if ((ArrayCode[i]>=0) && (ArrayCode[i]<=9))
             sum=sum+1;
     }
     return sum;
}

function setSelectCountry(SelectName, SelectValueList){
	ExecXMLHTTP("../Include/Country.xml", "GET", "", function(){
		if(ajax.readyState == 4){
			if(ajax.status == 200){
				var xml = ajax.responseXML;
				var countrys = xml.getElementsByTagName("country");
				var CountryOfOrigin = document.getElementsByName(SelectName);
				for(i=0;i<CountryOfOrigin.length;i++){
					var coo = CountryOfOrigin[i];
					coo.options.length = 0;
					for(j=0;j<countrys.length;j++){
						var short = countrys[j].getAttribute("short");
						var en = countrys[j].getAttribute("en");
						coo.options[j] = new Option(en, short);
					}
					coo.value=SelectValueList[i];
				}
			}else{
				alert("Server data-processing mistakes!");
			}
		}
	}, true)
}
