//读取URL后的参数
function QueryString(sName)
{
	var sSource = String(window.document.location);
	var sReturn = "";
	var sQUS = "?";
	var sAMP = "&";
	var sEQ = "=";
	var iPos;

	iPos = sSource.indexOf(sQUS);

	var strQuery = sSource.substr(iPos, sSource.length - iPos);
	var strLCQuery = strQuery.toLowerCase();
	var strLCName = sName.toLowerCase();

	iPos = strLCQuery.indexOf(sQUS + strLCName + sEQ);
	if (iPos == -1)
	{
		iPos = strLCQuery.indexOf(sAMP + strLCName + sEQ);
		if (iPos == -1)
		return "";
	}

	sReturn = strQuery.substr(iPos + sName.length + 2,strQuery.length-(iPos + sName.length + 2));
	var iPosAMP = sReturn.indexOf(sAMP);

	if (iPosAMP == -1)
		return sReturn;
	else
		sReturn = sReturn.substr(0, iPosAMP);
	return sReturn;
}


// Add By Jeff ON 2004-08-01

function GoToLogin()
{
	var win = window;
	while(win.parent!=null)
	{
		win = win.parent;
	}
	while(win.top !=null)
	{
		win = win.top;
	}
	win.location ="default.aspx;"
}

String.prototype.Trim=function()
{
	return this.replace(/(^\s*)|(\s*$)/g,"");
}

function SetTextBoxKeyDownToButton(objTextBox,objButton)
{
	if(event.keyCode ==13)
	{
		objButton.click();
		return false;
	}
}

function ShowErrMsg(msg,ShowError)
{
	var iWidth =200
	var iHeight =100
	ShowErrMsgBySize(msg,ShowError,iWidth,iHeight);
	
}



function CheckDocumentState()
{
	for(var i=0;i<document.frames.length;i++)
	{
		if(document.frames[i].document.readyState !="complete"
		&&document.frames[i].document.readyState !="interactive"
		)
		{
			//alert(document.frames[i].document.readyState);
			window.status = document.frames[i].document.readyState;
			setTimeout(CheckDocumentState,100);
			return false;
		}
	}
	
	gCommFunctionReady = true;
	ShowErrMsgBySize(gCommFunctionErrMsg,gCommFunctionShowErr,gCommFunctionWidth,gCommFunctionHeight);
	
}

var gCommFunctionErrMsg = "";
var gCommFunctionShowErr = null;
var gCommFunctionWidth = 0;
var gCommFunctionHeight = 0;
var gCommFunctionReady = false;

function ShowErrMsgBySize(msg,ShowError,iWidth,iHeight)
{	
	gCommFunctionErrMsg = msg;
	gCommFunctionShowErr  = ShowError;	 
	gCommFunctionWidth = iWidth;
	gCommFunctionHeight = iHeight;
	
	//要等待所有IFRAME 都载完以后再显示
	if(!gCommFunctionReady)
	{
		
		CheckDocumentState();
		return;
	}
	 
	var str="<style>.MsgTable{filter:progid:DXImageTransform.Microsoft.Shadow (color='gray',Direction=135,Strength=3); "+
	"border-top:solid 1px #eeeef1;"+
	"border-left:solid 1px #eeeef1;"+
	"border-bottom:solid 1px black;"+
	"border-right:solid 1px black;"+
	"background-color:#F2F9FF;"+
	";}td{font-size:12px;}</style><body oncontextmenu='javascript:return false' style='margin:0px' class='msgtable' scroll='no'><TABLE  width='100%'   cellpadding='2' cellspacing='0'  >"+
				"<TR height='22px' bgcolor='#C8E1FB'>" +
				"<TD colspan='2' style='color:#014F8A;font-weight:bold'>信息提示:</TD>" +
				"</TR><TR height='30px'><TD width='20px;'></TD>"+
				"<TD>{0}</TD></TR>"+
			"</TABLE></body>";
		if(ShowError)
		{
			msg ="<font color='red'>"+msg+"</font>";
		}
		str = str.replace("{0}",msg);
		
	
		//var div = document.createElement("DIV");
		//div.innerHTML = str;
		//document.body.appendChild(div);
		
		//用PopWindow
		var win = window.createPopup();
		win.document.write(str);
	 
		 
		
		var left =  window.screenLeft+ (document.body.offsetWidth-iWidth)/2
		var top		= window.screenTop+ (document.body.offsetHeight-iHeight)/2
		win.show(left,top,iWidth,iHeight)
		 
		
}
function ShowRefreshDocument()
{
    document.body.innerHTML = "";
	var str="<TABLE class='1' width='150'  cellpadding='2' cellspacing='0' onclick="
			 +"\"this.style.display='none';\">"+
				"<TR  height='30px' >"+
				"<TD style='color:black'  nowrap>{0}</TD></TR>"+
			"</TABLE>";
	 
		msg ="&nbsp;正在加载中,请稍候……&nbsp;";
	 
		str = str.replace("{0}",msg);
		
	
		var div = document.createElement("DIV");
		div.style.left =  (document.body.offsetWidth-150)/2;
		div.style.position ="absolute";
		div.style.top =  (document.body.offsetHeight)/2-100;
		div.innerHTML =   str;
		window.status =  "正在加载中,请稍候……";
		document.body.appendChild(div);
}

//iDeciLength decimal length
function CheckNumberInput(iLength,iDeciLength,iAllowZeroCapital)
{
	event.cancelBubble =true;
	
	 
	
	var sClipBoardText = window.clipboardData.getData("Text");
	if (sClipBoardText==null )
	sClipBoardText ="";
	if(event.ctrlKey )
	{
		if(event.keyCode == 67  ||event.keyCode ==99||event.keyCode ==10 || event.keyCode ==13) // Ctrl + C
		{
			return true;
		}
		if(!isNaN(sClipBoardText) && sClipBoardText.length<=iLength)
		{
			return true;
		}
		
		return false;
	}
	
	
	if (iDeciLength>0 && iLength<3 ) return false; 
	
	if(event.keyCode == 9 ) return true;
	
	var c = String.fromCharCode(event.keyCode);
	var keyCodeAry = new Array(96,97,98,99,100,101,102,103,104,105)
	var keyCode = event.keyCode;
	var specialKeyAry = new Array(13,27,8,46,35,36,37,38,39,40);
	if (itemInAry(specialKeyAry,keyCode)) return true;
	
	var text= event.srcElement.value;
	
	if(document.selection.createRange().text==text && event.keyCode !=9)
	{
		event.srcElement.value ="";
		text ="";
		event.srcElement.focus();
	}
	//get text cursor position
	var obj = window.event.srcElement;
	var s=document.selection.createRange();
	s.setEndPoint("StartToStart",obj.createTextRange())
	var pos = s.text.length;
	
	
	if((isNaN(c)||keyCode==32 ||event.shiftKey) &&  !itemInAry(keyCodeAry,keyCode))
	{
		if ( text.indexOf(".",0)==-1 &&(iLength>0) &&  (keyCode ==110||(keyCode==190 && !event.shiftKey)) )
	    {
			if(pos == text.length && (iLength-text.length)<2 && document.selection.createRange().text!=text)
			{
				return false;
			}else{}
			
	    }else 
	      return false;
		if (iDeciLength==0) return false;
	}
	
	if(text.length==iLength && !(document.selection.createRange().text==text) ) return false; //max length and not hightlight
	
	
	if(pos ==0 && (keyCode==110||(keyCode==190 && !event.shiftKey))  && text.length<iLength-1)
	{
		obj.value = "0.";
		return false;;
	}
	
	if(pos ==0 && iDeciLength>0 && text=="" && (c=="0"||keyCode==96))
	{
		obj.value ="0.";
		return false;
	}
	
	if( (c=="0"||keyCode==96) && iDeciLength<=0 &&pos==0 && iAllowZeroCapital!=1)
	{
		return false;
	}
	
	var zeroPos = text.indexOf(".");
	if(zeroPos>0 && pos > zeroPos)
	{
		if (text.length-zeroPos-1 ==iDeciLength) return false;
	}
	
	//alert(pos.length);
	
	
	
	return true;
}

function itemInAry(ary,item)
{
	for (var i =0;i<ary.length;i++)
	{
		if (ary[i]==item)
		{
			return true;
		}
	}
	return false;
}


//Add End 


//Add BY zhzofeng on 2004-09-27

function OpenWindow(url,width,height,name,options)
{
	var left = (screen.width-width)/2;
	var top = (screen.height-height)/2;
	if(options ==null)
		options ="";
	var newWin =  window.open(url,name,"left=" +left+",top="+top+",width="+width+",height="+height+","+options);
	newWin.focus();
		
}
function OpenModalWindow(url,width,height,param,options)
{
	if(options ==null)
		options ="";
	var left = (screen.width-width)/2;
	var top = (screen.height-height)/2;
	
	return  window.showModalDialog(url,param,"dialogLeft="+left+"px;dialogTop="+top+"px;dialogWidth="+width+"px;dialogHeight="+height+"px;status=0;help=0;"+options);
	 
 }
 
 
 
function OpenModelLessWindow(url,width,height,param,options)
{
	if(options ==null)
		options ="";
	var left = (screen.width-width)/2;
	var top = (screen.height-height)/2;
	 
	return  window.showModelessDialog(url,param,"dialogLeft="+left+"px;dialogTop="+top+"px;dialogWidth="+width+"px;dialogHeight="+height+"px;status=0;help=0;"+options);
	 
 }
 
 
 function OpenPrintWindow(url,param)
 {
	 
	var left = 0
	var top =  0;
	var width = screen.width-20;
	var height = screen.height -60;	 
	var a =   window.open(url,"Print","left="+left+" ,top="+top+" ,width="+width+",Height="+height+",status=0,scrollbars=1,menubar=0"+param,"d");
	a.focus();
	return a;
	 
 }
 
 
 //Add End
 
 	function DefaultButtonClick(name)
	{
			if(event.keyCode ==13)
			{
				eval("document.Form1."+name).click();
				return false;
			}
	}
	
	function SelEmployee(sFrmName,txtId,txtName,path,type)
	{
		var url ="../admin/EmployeeSelect.aspx?SelectType="+type	;
		//alert(url);
		if(path!=null)
		url =path+url;
		var obj = OpenModalWindow(url,600,400,null);
		//alert(obj[0]);
		
		if(obj!=null)
		{
			
			eval(sFrmName+"."+txtId+"").value = obj[0];
			eval(sFrmName+"."+txtName+"").value = obj[1];
			 
		}
		
	}
	
function DataGridOnClick()
{
	
	 
	 try
	 {
		var obj = event.srcElement;
		if(obj.tagName.toUpperCase() =="TD")
		{
			var objTr = obj.parentElement;
			if(objTr.cells[0].firstChild.tagName.toUpperCase()=="INPUT")
			objTr.cells[0].firstChild.click();
		}
	 }catch(e)
	 {
	 
	 }
}

function CheckBoxPropertisChange()
{
	
	
	var objCheck = event.srcElement;
	var objTr = objCheck.parentElement.parentElement;
	
	var i =0;
	while(objTr.tagName.toUpperCase()!="TR" && i<20)
	{
		objTr = objTr.parentElement;
		i++;
	}
	
	if(objCheck.checked)
	{
		objTr.selected = 1;
		objTr.runtimeStyle.cssText = GetSelectedCssText();
	}else
	{
		objTr.runtimeStyle.cssText = "";
		objTr.selected = null;
	}	
	 
}


function GetSelectedCssText()
{
	return "background-color:darkblue;color:white";
}

function DataGridOnMouseOver()
{
	var objTr = event.srcElement;
	
	var i =0;
	while(objTr.tagName.toUpperCase()!="TR" && i<20)
	{
		objTr = objTr.parentElement;
		i++;
	}
	if(objTr.selected == null)
	{
		objTr.runtimeStyle.cssText ="background-color:ccccee";
	}
}

function DataGridOnMouseOut()
{
	
	var objTr = event.srcElement;
	
	var i =0;
	while(objTr.tagName.toUpperCase()!="TR" && i<20)
	{
		objTr = objTr.parentElement;
		i++;
	}
	
	if(objTr.selected == null)
	{
		objTr.runtimeStyle.cssText ="";
	}
}


function Open_Calendar(frmId,txtId,ChildPath)
{		
	var iLeft=screen.width/2-150;
	var iTop=screen.height/2-200;
	
	iLeft = event.x+window.screenLeft-120;
	iTop = event.y+window.screenTop-80;
	
	var url='../js/utlCalendar.htm?frmid='+frmId+'&txtid='+txtId+'';
	if(typeof(ChildPath)!="undefined" && ChildPath)
	{
		url ="../"+url;
	}
	 
	/*popup = window.open('../Calendar/utlCalendar.htm?frmid='+frmId+'&txtid='+txtId+'','popup','width=180,height=160,left='+iLeft+',top='+iTop+',scrollbars=no,resizable=no');
	popup.focus(); 
	return false;
	*/
	
 
	//Modified By Jeff ON 2004-08-04 改为Modal窗口
		//Add by Jeff  on 2005-07-12把当前值传入
	var curValue = eval("document."+frmId+"."+txtId).value;
	var value=window.showModalDialog(url,curValue ,"dialogLeft="+iLeft+"px;dialogWidth=185px;dialogHeight=182px;dialogTop="+iTop+"px;status=0;scroll=no;help=0");
	var objTextBox =eval("document."+frmId+"."+txtId);
	if(objTextBox!=null && value!=null)
	{
		objTextBox.value = value;
	}
	return false;
	
	
}

function Open_Calendar1(frmId,txtId,ChildPath)
{		
	var iLeft=screen.width/2-150;
	var iTop=screen.height/2-200;
	
	iLeft = event.x+window.screenLeft-120;
	iTop = event.y+window.screenTop-80;
	
	
	var url='../js/utlCalendar1.htm?frmid='+frmId+'&txtid='+txtId+'';
	if(ChildPath)
	{
		url ="../"+url;
	}
	/*popup = window.open('../Calendar/utlCalendar1.htm?frmid='+frmId+'&txtid='+txtId+'','popup','width=180,height=230,left='+iLeft+',top='+iTop+',scrollbars=no,resizable=no,border=0');
	window
	popup.focus(); 
	return false;*/
	
	//Modified By Jeff ON 2004-08-04 改为Modal窗口
	//Add by Jeff  on 2005-07-12把当前值传入
	var curValue = eval("document."+frmId+"."+txtId).value;
	var value=window.showModalDialog(url,curValue ,"dialogLeft="+iLeft+"px;dialogWidth=185px;dialogHeight=215px;dialogTop="+iTop+"px;status=0;scroll=no;help=0");
	var objTextBox =eval("document."+frmId+"."+txtId);
	if(objTextBox!=null && value!=null)
	{
		objTextBox.value = value;
	}
	return false;
}


function GetE(id)
{
	return document.getElementById(id);
}
