﻿	function OpenWebForm(asPageName,aiMenu,aiScrollbar,aiWidth,aiHeight)
	{
		var lLeft,lTop,lWidth,lHeight;
		var sFeatures;
		
		lWidth  = WindowWidthDeal(aiWidth);
		lHeight = WindowHeightDeal(aiHeight);
		
		lLeft   = WindowLeftDeal(-1,lWidth);
		lTop    = WindowTopDeal(-1,lHeight);
		
		sFeatures  = "scrollbars=" + aiScrollbar + ",resizable=0" + "menubar=" + aiMenu + ",toolbar=" + aiMenu + ",status=" + aiMenu + ",location=" + aiMenu;
		sFeatures += ",top=" + lTop + ",left=" + lLeft + ",width=" + lWidth + ",height=" + lHeight;
	
		window.open(asPageName,"_blank",sFeatures);
	}
	
	//*关闭当前页面
	function CloseWebForm()
	{
		if (window.opener)
		{
			window.close();
		}
		else
		{
			try
			{
				parent.window.img_Close_Frame_onclick();
			}
			catch(e)
			{
				window.close();
			}
				
		}
	}
	
	//*页面高度处理
	function WindowHeightDeal(aiHeight)
	{
		var allHeight,retHeight;
		
		allHeight = window.screen.availHeight;
		retHeight  = aiHeight;
		
		//*如果没有传入高度
		if(retHeight <= 0 || retHeight > allHeight) 
		{
			if (allHeight < 650)
				retHeight = allHeight;  //800*600时的高度为屏幕高度
			else
				retHeight = allHeight*0.75; //1024*768时候为屏幕的0.75 
		}
		
		return retHeight;
		
	}
	
	//*页面宽度处理
	function WindowWidthDeal(aiWidth)
	{	
		var allWidth,retWidth;
	
		allWidth  = window.screen.availWidth;
		retWidth  = aiWidth;
		
		//*如果没有传入宽度
		if(aiWidth  <= 0||aiWidth > allWidth ) 
		{
			if (allWidth <1000) 
				retWidth = allWidth;		   //800*600时的宽度为屏幕宽度
			else
				retWidth = allWidth*0.75;      //1024*768时候为屏幕的0.75
		}
		
		
		return retWidth;
		
	}
	
	//*页面左边处理
	function WindowLeftDeal(aiLeft,aiWidth)
	{
		var allWidth,retLeft;
		
		allWidth = window.screen.availWidth;
		retLeft  = aiLeft;
		
		//*小于0或者超过屏幕宽度则居中打开		
		if(retLeft < 0||retLeft + aiWidth > allWidth) 	
			retLeft = (allWidth - aiWidth)/2;
		
		return retLeft;		
		
	}
	
	//*页面顶点处理
	function WindowTopDeal(aiTop,aiHeight)
	{
		var allHeight,retTop;
		
		allHeight = window.screen.availHeight;
		retTop    = aiTop;
		
		//*小于0或者超过屏幕宽度则居中打开	
		if(retTop < 0 ||retTop + aiHeight > allHeight)
			retTop = (allHeight - aiHeight)/2;
		
		return retTop;
	
	}
	//*居中打开一个response窗口并返回信息
	function OpenWithResponse(asPage,aoSendParm,aiWidth,aiHeight)
	{
			
		var sFeatures = "edge: Raised; center: Yes; help: No; resizable: No; status: No;"
		var lLeft,lTop,lWidth,lHeight;
		var sRet;
			
		lWidth  = WindowWidthDeal(aiWidth);
		lHeight = WindowHeightDeal(aiHeight);
		
		lLeft   = WindowLeftDeal(-1,lWidth);
		lTop    = WindowTopDeal(-1,lHeight);
						
		
		sFeatures += "dialogHeight: " + lHeight + "px; dialogWidth: " + lWidth + "px; dialogTop: " + lTop + "px; dialogLeft: " + lLeft + "px;";	
					
		sRet = window.showModalDialog(asPage,aoSendParm,sFeatures);
		return sRet;
			
	}
	
	//*responsed的焦点的lock与unlock
	function LockFocus()
	{
		var i;
		//window.onblur = LockBlur;
		window.attachEvent(onblur,LockBlur)
		for(i = 0;i < document.all.length; i++)
		{
			//document.all(i).onblur = LockBlur;
			document.all(i).attachEvent(onblur,LockBlur)
		}
		
				
	}
	function LockBlur()
	{
		var x,y,k;
		var beginx,beginy,endx,endy;
		x = window.event.clientX;
		y = window.event.clientY;
		
		beginx = document.body.clientLeft;
		beginy = document.body.clientTop;
		
		endx = beginx + document.body.clientWidth;
		endy = beginy  + document.body.clientHeight;
		
		k = window.event.keyCode; 
		
		if(x == null) x = 0;
		if(y == null) y = 0 ;
		//if( k == 9|| k == 13) return; tab和enter键
		if( k > 0) return;              //*允许按键
		//if(x <= 0 || y <= 0 ) window.focus();
		if(x < beginx || y < beginy) window.focus();
		if(x > endx || y > endy) window.focus();
	}
	
	
	function UnLockFocus()
	{
		var i;
		//window.onblur = new Function ("return false;");
		window.detachEvent(onblur,LockBlur);
		for(i = 0;i < document.all.length; i++)
		{
			//document.all(i).onblur = new Function ("return false;");
			document.all(i).detachEvent(onblur,LockBlur);
		}
	}

	//回车键控制
	function CaptureEnterKey()
	{	
		if(window.event.keyCode==13)
		{	
			window.event.keyCode=9;
			return false;
		}	
	}
	//键盘向上、向下按键
	function updown(upcontrol, downcontrol)
	{
		//按向上键
		if ((window.event.keyCode == 38) && (document.all(upcontrol)))
		{
			document.all(upcontrol).focus();
		}
		else
		//按向下键
		if ((window.event.keyCode == 40) && (document.all(downcontrol)))
		{
			document.all(downcontrol).focus();
		}
	}
	//*****************用于进行锁定屏幕 is begin **************************************
	scrWaitBodyFocus=null;
	scrWaitBodyContext=null;
	scrWatiBodyKeyDown=null;
	scrWatiBodyClick=null;
	//*锁定屏幕进行等待
	function LockScreenToWait(msg)
	{
		if(arguments.length <=0) msg = "正在处理，请稍侯... ...";
		if (scrWaitBodyFocus==null && scrWaitBodyContext==null&&scrWatiBodyKeyDown==null&&scrWatiBodyClick==null){
			scrWaitBodyFocus = document.body.onfocus+'';
			scrWaitBodyContext = document.body.oncontextmenu+'';
			scrWatiBodyKeyDown = document.body.onkeydown+'';
			scrWatiBodyClick = document.body.onclick+'';
			document.body.onfocus = LockScreenToWait;
			document.body.oncontextmenu = CancelClick;
			document.body.onkeydown = CancelClick;
			document.body.onclick = LockScreenToWait;
		}
		var div = document.all["divScreenWaiting"];
		if (div+''=="undefined"){
			div = document.createElement("DIV");
			div.setAttribute("id","divScreenWaiting");
			
			div.style.position = "absolute";
			div.style.border = "1px solid #284860";
			div.style.padding = 10;
			div.style.paddingLeft = 30;
			div.style.paddingRight = 30;
			div.style.zIndex = 999;
			div.style.backgroundColor='buttonface';
			div.innerHTML = msg;
			document.body.appendChild(div);
		}
		var x =(document.body.clientWidth-div.offsetWidth)/2;
		var y = (document.body.clientHeight-div.offsetHeight)/2;
		div.style.pixelLeft = x;
		div.style.pixelTop = y;
		div.style.visibility = "visible";
		div.onclick = CancelClick;
		
		div.setCapture();
	}
	//*打开屏幕锁定
	function UnlockScreenWait()
	{
		var div = document.all["divScreenWaiting"];
		if (div+''=="undefined")
			return;
		div.style.visibility = "hidden";
		document.body.onfocus = scrWaitBodyFocus;
		document.body.oncontextmenu = scrWaitBodyContext;
		document.body.onkeydown = scrWatiBodyKeyDown;
		document.body.onclick = scrWatiBodyClick;
		scrWaitBodyFocus = null;
		scrWaitBodyContext = null;
		scrWatiBodyKeyDown = null;
		scrWatiBodyClick = null;
		document.releaseCapture();
	}
	//*用于取消屏幕锁定的锁定鼠标和键盘
	function CancelClick()
	{
		
		if(event.ctrlLeft&&event.keyCode == "13") UnlockScreenWait();//*用于特殊解除锁定
		return false;
	}
	//*************锁定屏幕 is end 
	
	//判断一个字符串是否是一个数字
function IsDigit(val)
{
	var ch;
	var digit = 0;
	if (val.length == 0 ) return false;
	for (var j = 0;j< val.length;j++)
	{	
		ch = val.charAt(j);
		if(j == 0 && (ch == '+' || ch == '-')) continue;	//正负号只能在字符串开始位置
		else if (ch == '.'&& j > 0 && digit ==0)	//该字符串中，只允许一个小数点，且小数点不能在字符串开始位置
		{
			digit = 1;
			continue;
		}
		else if (ch >= '0' && ch <= '9') continue;
		else
		{
			//alert("非法字符：" + val);
			return false;
		} 
	}
	return true;
}


	