		<!--
			//-------------------------------------------------------------
			// Select all the checkboxes (Hotmail style)
			// Note: Please note this will select all the check boxes on the
			// form.
			//-------------------------------------------------------------
			function SelectAllCheckboxes(spanChk){
			
			// Added as ASPX uses SPAN for checkbox 
			var xState=spanChk.checked;
			var theBox=spanChk;
			
			// Old code for VS 2002 / .NET framework 1.0 code
			//-----------------------------------------------
			// In .NET 1.0 ASP.NET was using SPAN tag with
			// CheckBox control. 
			//
			//var oItem = spanChk.children;
			//var theBox=oItem.item(0)
			//xState=theBox.checked;	
			//-----------------------------------------------
			
				elm=theBox.form.elements;
				for(i=0;i<elm.length;i++)
				if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
					{
					//elm[i].click();
					if(elm[i].checked!=xState)
					elm[i].click();
					//elm[i].checked=xState;
					}
			}

			//-------------------------------------------------------------
			//----Select highlish rows when the checkboxes are selected
			//
			// Note: The colors are hardcoded, however you can use 
			//       RegisterClientScript blocks methods to use Grid's
			//       ItemTemplates and SelectTemplates colors.
			//		 for ex: grdEmployees.ItemStyle.BackColor OR
			//				 grdEmployees.SelectedItemStyle.BackColor
			//-------------------------------------------------------------
			function HighlightRow(chkB)	{
			
			// Old code for VS 2002 / .NET framework 1.0 code
			//-----------------------------------------------
			// In .NET 1.0 ASP.NET was using SPAN tag with
			// CheckBox control. 
			//var oItem = chkB.children;
			//xState=oItem.item(0).checked;
			var xState=chkB.checked;
				
			if(xState)
				{chkB.parentElement.parentElement.style.backgroundColor='lightcoral';  // grdEmployees.SelectedItemStyle.BackColor
				chkB.parentElement.parentElement.style.color='white'; // grdEmployees.SelectedItemStyle.ForeColor
				}else 
				{chkB.parentElement.parentElement.style.backgroundColor='white'; //grdEmployees.ItemStyle.BackColor
				chkB.parentElement.parentElement.style.color='black'; //grdEmployees.ItemStyle.ForeColor
				}
			}
			// -->
		
//选择当前行
var para=window.dialogArguments; 
function OnSelect()
		{
			var t = window.event.srcElement.parentElement.rowIndex;
			//var hidId = 'DataGrid1__ctl35_hidId';
			para.Var1.value=window.event.srcElement.parentElement.cells(0).innerText;
			para.Var2.value=window.event.srcElement.parentElement.cells(1).innerText;
			window.close();
			
			//alert(window.event.srcElement.parentElement.cells(0).innerText);
			
			//alert(window.event.srcElementparentElement.rowIndex);
			//alert(window.event.srcElement.parentElement.cells(0).innerText+DataGrid1.elements[hidId].value);
	     }
	     
//=================================================================================================
// WndType 就是对话框的标题
//=================================================================================================

//上传文件使用
function GetDoc()
		{
			window.showModalDialog('selectframe.aspx?url=UploadFileDialog.aspx&WndType=Upload','',
			'dialogHeight=300px;dialogWidth=400px;status=no;edge=raised;scroll=yes');
		}

//打开日立对话框使用
function GetCalendar(param)
	{				
		window.showModalDialog('SelectFrame.aspx?url=Calendar/Calendar.html&WndType=SelectDate',
		param,'dialogHeight=209px;dialogWidth=210px;status=no;edge=raised;scroll=no');
	}

//选择用户对话框使用
function SelectUser(id,name)
	{
       	var obj = new Object();
	    obj.Var1= id;
	    obj.Var2= name;			   
	    window.showModalDialog('SelectFrame.aspx?url=SelectUsersPage.aspx&WndType=SelectUser',obj,
	    'dialogHeight=540px;dialogWidth=480px;status=no;edge=raised;scroll=no');
	}
	
//选择岗位对话框使用
function SelectPos(id,pos)
	{
       	var obj = new Object();
	    obj.Var1= id;
	    obj.Var2= pos;
	    window.showModalDialog('SelectFrame.aspx?url=SelectPosDialog.aspx&WndType=SelectPos',obj,
	    'dialogHeight=540px;dialogWidth=480px;status=no;edge=raised;scroll=no');
	}

//选择部门对话框使用
function SelectDept(id,Dept)
	{
       	var obj = new Object();
	    obj.Var1= id;
	    obj.Var2= Dept;
	    window.showModalDialog('SelectFrame.aspx?url=SelectDeptDialog.aspx&WndType=SelectDept',obj,
	    'dialogHeight=540px;dialogWidth=480px;status=no;edge=raised;scroll=no');
	}
	
//选择职称对话框使用
function SelectJobTitle(id,JobTitle)
	{
       	var obj = new Object();
	    obj.Var1= id;
	    obj.Var2= JobTitle;
	    window.showModalDialog('SelectFrame.aspx?url=SelectJobTitleDialog.aspx&WndType=SelectJobTitle',obj,
	    'dialogHeight=540px;dialogWidth=480px;status=no;edge=raised;scroll=no');
	}
	
/*	
//显示错误提示信息对话框
function MessageBox(title,msg)
	{
       	var message	 = new Object();
	    message.Var1 = title;
	    message.Var2 = msg;
	    window.showModalDialog('SelectFrame.aspx?url=ErrorMessage.aspx&WndType=MessageBox',message,
	    'dialogHeight=300px;dialogWidth=400px;status=no;edge=raised;scroll=no');
	}
	*/

var gbReadOnly = false;
var iCurLength;
	iCurLength = 10;
/*
function window.onload(){
	//<<< determine page is use WebService >>>
	if (typeof(_initWebService) == "function"){
		try{
			_initWebService();
		}
		catch(e){}
	}
	
	var oForm = document.forms[0];
	var oEdit = oForm.all("txtEdit");
	if (oEdit == null) return;
	gbReadOnly = oEdit.value == "Read";
	var oButtons = oForm.all.tags("BUTTON");
	for (var i=0; i<oButtons.length; i++){
		var oButton = oButtons[i];
		if (oButton.BackButton == null)
			oButton.disabled = gbReadOnly;
	}
	var oInputs = oForm.all.tags("INPUT");
	for (var i=0; i<oInputs.length; i++){
		var oInput = oInputs[i];
		if (oInput.type == "button" && oInput.BackButton == null)
			oInput.disabled = gbReadOnly;
	}
	EnterToTab();
}
*/
function EnterToTab() {
	for(var i=0;i<document.forms.length;i++) {
		var f=document.forms[i];
		
		for(var j=0;j<f.length;j++){
			var e=f.elements[j];			
			if(e.type == "text" || e.type == "select-one") {
				e.attachEvent("onkeydown", onkeydown);
			}
		}
	}	
}

 function GetSeleText(SelectList)
        {
        
           
        
			var cboField="";
			for(var loop_index = 0;loop_index < SelectList.options.length;loop_index++ ) {
						if (loop_index==SelectList.options.length-1) {
						if (SelectList.options[loop_index].text !="")
							cboField+= SelectList.options[loop_index].text;
						}
						else {
						if (SelectList.options[loop_index].text!="")
							cboField+= SelectList.options[loop_index].text+',';
						}			
				}	
			
			if (cboField=="")
			{
				alert("你没有选择选项！");
				return "";
			}
			else
			 {
			     return cboField;
			 }
        }     


function verify(){
  return verifyForm(document.forms[0]);
}



function verifyForm(f){
//	debugger;
//			var f=document.forms[0];
			var msg="";
			var empty_fields="";
			var errors="";
			//遍历所有的表单元素,查找所定义了mustFill属性的text以及textarea元素,检查是否为空,
			//另外,如果元素定义了numeric属性,则检查其是否为数字,如果定义了min以及max属性,则检查其是否
			//在范围中,最后把有错误的字段的错误信息集中在一起提示




			for(var i=0;i<f.length;i++){
				var e=f.elements[i];
				 
				 if(((e.type == "text")||(e.type == "textarea")||(e.type=="select-one"))){
				 
					  
					if(e.mustFill||e.mustfull||e.mustfill){
				
				           
					    if (e.type=="select-one"){
					       if ((e.selectedIndex==-1)||(e.options(e.selectedIndex).value=="")||(e.options(e.selectedIndex).value==null)){
                              if(e.promptName){	
								empty_fields=empty_fields+"\n"+e.promptName+"\u4E0D\u5141\u8BB8\u4E3A\u7A7A!";
						    	}	
							else{
								empty_fields=empty_fields+"\n"+e.name+"\u4E0D\u5141\u8BB8\u4E3A\u7A7A!";					       
					          }
					       }
					    }
					    else
					    {
					   
						   if((e.value == null)||(e.value == "")||isBlank(e.value)){						  
							  if(e.promptName){	
								empty_fields=empty_fields+"\n"+e.promptName+"\u4E0D\u5141\u8BB8\u4E3A\u7A7A!";
							  }	
							  else{
								empty_fields=empty_fields+"\n"+e.name+"\u4E0D\u5141\u8BB8\u4E3A\u7A7A!";							
							  }					
						    }					
						}
					}					
					
					if(e.numeric||(e.min!=null)||(e.max!=null)){
						if(!isBlank(e.value)){
							if(!isNumeric(e.value)){								
								errors ="\n" + errors + e.promptName + "应该为数字！";
							}	
							else if((e.min!=null) && (v<e.min)){
								errors +="\n"+e.promptName+"应该不小于"+e.min;
							}
							else if((e.max!=null) && (v>e.max)){
							    //errors +="\n"+e.promptName+"应该不超过"+e.min;
							}
						}
					}
					
					if(e.isDate){
						if(!isBlank(e.value)){
							var v=e.value;
							var vResult=dateverify(v,'');
							if(vResult==''){
								errors +="\n"+e.promptName+"eg:YYYY-MM-DD";
							}
							else{
								e.value=vResult;
							}					
						}
					}					
					
					
					if(e.isDateTime){
						if(!isBlank(e.value)){
							var v=e.value;
							var vResult=dateverify(v,"yyyy-mm-dd hh:nn");
							if(vResult==''){
								errors +="\n"+e.promptName + " eg:YYYY-MM-DD HH:MI:SS";
							}
							else{
								e.value=vResult;
							}
					  }
					}										
				    
				    if (e.isDateOrDateTime){				       
						if(!isBlank(e.value)){
							var v=e.value;
							//alert(v.substring(0,16));
							var vResult= dateverify(v,"");
							var vResult1=dateverify(v.substring(0,16),"yyyy-mm-dd hh:nn"); 
							//alert(vResult1);
							if((vResult=='') && (vResult1=='')){
								errors +="\n"+e.promptName+"eg:YYYY-MM-DD HH:MI:SS或YYYY-MM-DD HH:MI";
							}
							else{
							   if (vResult!='') { 
							    	e.value=vResult;
							   }
							   else
							   {
							     if (vResult1!='') { 
							     	e.value=vResult1;
							     }
							   }
							}					
						}
					 }
					 
				}
			}
			if(!empty_fields && !errors) return true;
			msg="";
			if(empty_fields){
				msg+=empty_fields+"\n";
			}
			if(errors) msg+= errors;
			alert(msg);
			return false;	
}

function on_isNumeric (s) {
	if(!isBlank(s)){
		if(!isNumeric(s)){
			alert("请输入数字");
			return false;
		}	
	}
}

function isNumeric (s) {
	var decimalPointDelimiter = ".";
		var seenDecimalPoint = false;
		
		for (i = 0; i < s.length; i++){   
		    // Check that current character is number.
		    var c = s.charAt(i);

		    if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
		    else if (!isDigit(c)) return false;
		}
		return true;
}

function isDigit (c){
	return ((c >= "0") && (c <= "9"))
}

function isBlank(s){
	for(var i=0;i<s.length;i++){
		var c=s.charAt(i);
		if ((c!='')&&(c!=' ')&&(c!='\n')&&(c!='\t')){
				return false;
		}   
	}	
	return true;
}

function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11){
	this[0] = m0;
	this[1] = m1;
	this[2] = m2;
	this[3] = m3;
	this[4] = m4;
	this[5] = m5;
	this[6] = m6;
	this[7] = m7;
	this[8] = m8;
	this[9] = m9;
	this[10] = m10;
	this[11] = m11;
}

//日期的合法性判断，如果日期合法，返回经过处理的日期（yyyy-mm-dd或者yyyy-MM-dd hh:mm:ss）如果不合法，则返回空串
function dateverify(date,format) {
	var format,dateString;
	var tmpString;
	var interString;
	var formatString='ymdhns';
	interString='';
	if (format==null || format=='') format='yyyy-mm-dd';
	for (i0=0;i0<format.length;i0++) {
		if (formatString.indexOf(format.charAt(i0))==-1) interString=interString+format.charAt(i0);
	};
	
	interString=interString+interString.charAt(0);
	format=format+interString.charAt(0);
	date=date+interString.charAt(0);
	
	year=0;
	month=0;
	day=0;
	hour=1;
	min=1;
	sec=1;
	dateString='';
	oldIndex=0;
	oldIndex0=0;
	newIndex=0;
	
	for (i0=0;i0<interString.length;i0++) {
			tmpString0='';
			tmpString='';
			newIndex=date.indexOf(interString.charAt(i0),oldIndex);
		if (newIndex!=-1) {
			tmpString=date.substring(oldIndex,newIndex);
			oldIndex=newIndex+1;
			newIndex=format.indexOf(interString.charAt(i0),oldIndex0);
			for (j=0;j<newIndex-oldIndex0-tmpString.length;j++) tmpString0=tmpString0+'0';
			if (tmpString.length<(newIndex-oldIndex0)) tmpString=tmpString0+tmpString;
			if (tmpString.length>(newIndex-oldIndex0)) tmpString='0';
			dateString=dateString+tmpString;
			if (i0<interString.length-1) dateString=dateString+interString.charAt(i0);
			if (format.charAt(newIndex-1)=='y') year=parseInt(tmpString,10); 
			if (format.charAt(newIndex-1)=='m') month=parseInt(tmpString,10);
			if (format.charAt(newIndex-1)=='d') day=parseInt(tmpString,10);
			if (format.charAt(newIndex-1)=='h') hour=parseInt(tmpString,10);
			if (format.charAt(newIndex-1)=='n') min=parseInt(tmpString,10);
			if (format.charAt(newIndex-1)=='s') sec=parseInt(tmpString,10);
			oldIndex0=newIndex+1;
		  } 
		  else{
			year=0;
		}	
	};
	var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))  monthDays[1] = 29;
	if (month<1 || month>12) dateString=''
	else if (day<1 || day>monthDays[month-1]) dateString=''
	else if (year<1) dateString=''
	else if (hour<0 || hour>23) dateString=''
	else if (min<0 || min>59) dateString=''
	else if (sec<0 || sec>59) dateString=''
	//alert(dateString);
	return dateString;
}

function onkeydown() {
	if(event.keyCode==13)	event.keyCode=9;
}


function Back(){
    if (typeof(window.opener)=="undefined")
    {
        var oForm,pageName;
		if (pageName == null){
			oForm = document.all.tags("FORM")[0];
			pageName = oForm.id;
		}
		else{
			oForm = eval("document." + pageName);
		}		
        if (oForm.txtEdit.value=="Read")
        {
			history.go(-1);
        }
        else
        {
           //备用 window.parent.parent.frames[1].location.reload();          
          //alert(window.parent.WorkSpaceFrame.src);           
		  // debugger;
          //window.parent.WorkSpaceFrame.location=window.parent.WorkSpaceFrame.location;
          history.go(-1);
        }		
	}
	else
	{
	   window.opener.parent.location.reload();
	   window.close();
	}
}
//	ADAM: 2005-1-10 9:30:47
//	
//	function:
//		doBack - back asp(net) page or close
//	parameters:
//
function doBack(){
	if (typeof(back) == "function"){
		back();
	}
	else{
		Back();
	}
}

function fPopUpCalendarDlg(ctrlobj) {
  //选择日期（弹出）
	//日期控件：ctrlobj为需要返回的表单名，例如：




	//			<input type='text' readonly name='date_begin' 'size='10' value='2003-02-18'>
	//			<img src='../images/dSelect.gif' border=0 onClick='fPopUpCalendarDlg(date_begin);return false'>
	//注意事项：应将时间表单设为只读，即 readonly
	showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
	showy = event.screenY - event.offsetY -168; // + deltaY;
	newWINwidth = 210 + 4 + 18;

	var url = top.gAbsolutePate + "Include/Calendar.htm";
	//alert(url);
	var pars= "dialogWidth:197px;dialogHeight:210px;dialogLeft:"+showx+"px;dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "
	retval = window.showModalDialog(url,"", pars);
	if( retval != null ){
	       
		ctrlobj.value = retval.substring(0,10);
	}	
}

function fPopUpCalendarDlgDT(ctrlobj) {
  //选择日期（弹出）
	//日期控件：ctrlobj为需要返回的表单名，例如：




	//			<input type='text' readonly name='date_begin' 'size='10' value='2003-02-18'>
	//			<img src='../images/dSelect.gif' border=0 onClick='fPopUpCalendarDlg(date_begin);return false'>
	//注意事项：应将时间表单设为只读，即 readonly
	showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
	showy = event.screenY - event.offsetY -168; // + deltaY;
	newWINwidth = 210 + 4 + 18;

	var url = top.gAbsolutePate + "Include/Calendar.htm";
	//alert(url);
	var pars= "dialogWidth:197px;dialogHeight:210px;dialogLeft:"+showx+"px;dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "
	retval = window.showModalDialog(url,"", pars);
	if( retval != null ){	     
		ctrlobj.value = retval;
	}	
}

function sltDateNoPop(){  
	//选择日期（不弹出）



	var obj=window.event.srcElement.parentElement.children(0).id;   		
	fPopCalendar(document.all(obj),document.all(obj));
}

function sltDate()
{  //选择日期（不弹出）




   	//var obj=window.event.srcElement.parentElement.children(0).id;   	
    // fPopCalendar(document.all(obj),document.all(obj));
    
    showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
	showy = event.screenY - event.offsetY -168; // + deltaY;
	newWINwidth = 210 + 4 + 18;

	var ctrlobj=window.event.srcElement.parentElement.children(0).id;   	
	var url = top.gAbsolutePate + "Include/JvDateCal.htm";	
	var pars= "dialogWidth:197px;dialogHeight:210px;dialogLeft:"+showx+"px;dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "
	retval = window.showModalDialog(url,"", pars);	
	if( retval != "-1" ){
	    var strNodeary=retval.split(";") 
 		var strNodeID=strNodeary[0];
		document.all(ctrlobj).value = strNodeID;
	}	
}

function sltDateTime()
{
    showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
	showy = event.screenY - event.offsetY -168; // + deltaY;
	newWINwidth = 210 + 4 + 18;

	var ctrlobj=window.event.srcElement.parentElement.children(0).id;   	
	var url = top.gAbsolutePate + "Include/JvDateCal.htm";	
	var pars= "dialogWidth:197px;dialogHeight:210px;dialogLeft:"+showx+"px;dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "
	retval = window.showModalDialog(url,"", pars);		
	if( retval != "-1" ){
	    var strNodeary=retval.split(";") 
 		var strNodeID=strNodeary[0];
		var strNodeName=strNodeary[1];		
		document.all(ctrlobj).value = strNodeID+" "+strNodeName;
	}		
}

function sltWord___bak()
{
   	var obj=window.event.srcElement.parentElement.children(0).id;   	
    fPopWord(document.all(obj),document.all(obj));
}

function sltWord()
{   
    showx = event.screenX - event.offsetX+15 ; // + deltaX;
	showy = event.screenY - event.offsetY ; // + deltaY;
	newWINwidth = 210 + 4 + 18;
   
   var url = top.gAbsolutePate + "Include/SelectWord_Auto.aspx";	
   var obj=window.event.srcElement.parentElement.children(0).id;   
   var pars= "dialogWidth:299px;dialogHeight:258px;dialogLeft:"+showx+"px;dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; "
   var strNode=window.showModalDialog (url,"",pars) ;
   if(strNode!=-1)
   {
	 if(typeof(strNode)!="undefined") 
	 { 
	   var strNodeary=strNode.split("*") 
 	   var strNodeID=strNodeary[0];
	   var strNodeName=strNodeary[1];	   
	   document.all(obj).value=document.all(obj).value+strNodeName;
       //document.all(obj1).value =strNodeName;		 
	  } 
  }			
 }
//	ADAM: 2005-1-10 9:30:47
//	function:
//		doPost - Post asp(net) page
//	parameters:
//		flag - is post by default
//
function doPost(flag){
	if (flag == null){
		if (typeof(submit) == "function"){
			submit();
			return;
		}
	}
	Post(flag);
}

function Post(flag)
{
  if (flag==1)
  {
      PostStandEdit();
  }
  else
  {
      StandandPost();
  }
}

function StandandPost(pageName){
	if (verify()){
		var oForm,pageName;
		if (pageName == null){
			oForm = document.all.tags("FORM")[0];
			pageName = oForm.id;
		}
		else{
			oForm = eval("document." + pageName);
		}
		oForm.action = pageName + ".aspx?IsPost=1";
		oForm.submit();
	}
}

function PostStandEdit(pageName)
{
	if (verify())
    {    
		var oForm,pageName;
		if (pageName == null){
			oForm = document.all.tags("FORM")[0];
			pageName = oForm.id;
		}
		else{
			oForm = eval("document." + pageName);
		}    
	 	oForm.action=pageName + ".aspx?IsPost=1&PAGEID="+document.all("hidPAGEID").value;				
		__doPostBack('hidbtnSave','');
	}
}

function btnAttach_onclick()
{
    iCurLength += 1;    
    if (document.all("trFile10").style.display=="")
    {
       alert("最多只支持10个附件!");
       return false;   
    }
    document.all("txtAttachSum").value = parseFloat(document.all("txtAttachSum").value) + 1;
    switch(iCurLength)
	{
		case 11:
			document.all("trFile2").style.display = "";
			break;
		case 12:
			document.all("trFile3").style.display = "";
			break;
		case 13:
			document.all("trFile4").style.display = "";
			break;
		case 14:
			document.all("trFile5").style.display = "";
			break;		
		case 15:
			document.all("trFile6").style.display = "";
			break;			
		case 16:
			document.all("trFile7").style.display = "";
			break;			
		case 17:
			document.all("trFile8").style.display = "";
			break;			
		case 18:
		    document.all("trFile9").style.display = "";
		    break;		
		case 19:
			document.all("trFile10").style.display = "";
			break;
		}    
}

		   
function ChoiseTransForm()
{   //选择变电站与电厂--(专用于继保科)
  try
  {
		var obj=window.event.srcElement.parentElement.children(0).id;    
		var str="IsOnlyOne=1&temp=1";         
		str=top.gAbsolutePate + "EquipMng/SelectTransformerFrame.aspx?"+str+",'选择窗口','dialogWidth:400px;dialogHeight:500px;edge:sunken;help:no;resizable:yes;scroll:no;status:no;unadorned:no'";
		reval=window.showModalDialog(str); 
		if (reval.type=='OK') 
		{ 		   
		   var ilength=document.all(obj).options.length
		   for (var i=ilength-1;i>=0;i--)
		   {
				document.all(obj).options.remove(i)
		    }
			var Opt=document.createElement("option");  
			Opt.value=reval.value;
			Opt.text=reval.text;
			document.all(obj).options.add(Opt);			
		}     
		document.all(obj).focus();		
	}
	catch(e)
	{
		//alert(e.description);
	}		   
}

function ChoiseTransProtectForm(ctrlobj)
{
     
   try
   {
      var sTransCode=ctrlobj.value;
      if (sTransCode==null){
        alert("请先选择单位");
      }
      var obj=window.event.srcElement.parentElement.children(0).id;       
      var url=top.gAbsolutePate + "Include/selectProtect.aspx?TransCode="+sTransCode;
            
      reval=window.showModalDialog(url,"","dialogWidth:250px;dialogHeight:350px;edge:sunken;help:no;resizable:no;scroll:no;status:no;unadorned:no"); 
	  if (reval.type=='OK') 
	  {
		  var ilength=document.all(obj).options.length
		   for (var i=ilength-1;i>=0;i--)
		   {
				document.all(obj).options.remove(i)
		    }
			var Opt=document.createElement("option");  
			Opt.value=reval.value;
			Opt.text=reval.text;
			document.all(obj).options.add(Opt);			
	  }
	  document.all(obj).focus();	 
   }
   catch(e)
   {
   }		 
}

function ChoiseTransAotuForm(ctrlobj)
{
     
   try
   {
      var sTransCode=ctrlobj.value;
      if (sTransCode==null){
        alert("请先选择单位");
      }
      var obj=window.event.srcElement.parentElement.children(0).id;       
      var url=top.gAbsolutePate + "Include/selectProtect.aspx?TransCode="+sTransCode;
            
      reval=window.showModalDialog(url,"","dialogWidth:250px;dialogHeight:350px;edge:sunken;help:no;resizable:no;scroll:no;status:no;unadorned:no"); 
	  if (reval.type=='OK') 
	  {
		  var ilength=document.all(obj).options.length
		   for (var i=ilength-1;i>=0;i--)
		   {
				document.all(obj).options.remove(i)
		    }
			var Opt=document.createElement("option");  
			Opt.value=reval.value;
			Opt.text=reval.text;
			document.all(obj).options.add(Opt);			
	  }
	  document.all(obj).focus();	 
   }
   catch(e)
   {
   }		 
}


function btnPrompt_onclick()
{
   var obj=window.event.srcElement.parentElement.children(0).id;
   var obj1=window.event.srcElement.parentElement.children(1).id;
   var strNode=window.showModalDialog (top.gAbsolutePate + "SelectUser/SelectUser.aspx",0,"edge:sunken;help:no;resizable:no;scroll:no;status:no;unadorned:no ") 
   if(strNode!=-1)
   {
	 if(typeof(strNode)!="undefined") 
	 { 
	   var strNodeary=strNode.split(";") 
 	   var strNodeID=strNodeary[0];
	   var strNodeName=strNodeary[1];
	   var strDeptID=strNodeary[2];
	   document.all(obj).value=strNodeID;
       document.all(obj1).value =strNodeName;		 
	  } 
  }			
  }
  
  
  	function SelectSystem(){
		var oSysCode = window.event.srcElement.parentElement.children(0).id;
		var oSysName = window.event.srcElement.parentElement.children(1).id;
		var oSubSysCode = window.event.srcElement.parentElement.children(2).id;
		var oSubSysCodeName = window.event.srcElement.parentElement.children(3).id;		
		var selected = oSubSysCode.value;
		var url = top.gAbsolutePate + "include/SelectCode.aspx?Code=AutoSystem&Selected=" + selected;
		var cap = "选择系统";
		var pars= "dialogHeight:420px;dialogWidth:300px;edge:Raised;center:Yes;help:No;resizable:No;status:No;scroll:off";
		
		var CodeObject = window.showModalDialog(url, cap, pars);
		if (CodeObject==null) return;
		document.all(oSysCode).value = CodeObject.ParentID;
		document.all(oSysName).value = CodeObject.ParentName;
		document.all(oSubSysCode).value = CodeObject.ID;
		document.all(oSubSysCodeName).value = CodeObject.Name;
		//alert(oSysCode);
	}
	
	
//=======================================================//
//                                                       //
//                                                       //
//                   字符串处理函数                      //
//                                                       //
//                                                       //
//=======================================================//
//=======================================================//
//	        lTrim(string):去除左边的空格                 //
//=======================================================//
function lTrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(0)) != -1){
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1){
			j++;
		}
		s = s.substring(j, i);
	}
	return s;
} 

//=======================================================//
//	        rTrim(string):去除右边的空格                 //
//=======================================================//
function rTrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1){
		var i = s.length - 1;
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1){
			i--;
		}
		s = s.substring(0, i+1);
	}
	return s;
}

//=======================================================//
//	        trim(string):去除前后空格                    //
//=======================================================//
function trim(str){
	return rTrim(lTrim(str));
}

///////////////////////////////////////////////////////////
//
//		2004年12月28日




//		作者:	李兵峰




//
///////////////////////////////////////////////////////////
//=========================================================
//
//	检查所有输入数据的合法性




//
//=========================================================
function verifyInput(){
	for(var i=0; i<document.all.length; i++){
		var o = document.all(i);
		// 检查输入




		if (o.MustInput != null || o.mustinput != null || o.Mustinput != null || o.mustInput != null){
			if (!isInputed(o)){
				return false;
			}
		}
		// 检查年月格式




		if (o.MonthDay != null || o.monthday != null || o.Monthday != null || o.monthDay != null){
			if (!isMonthDay(o)){
				return false;
			}
		}
	}
	return true;
}
//=========================================================
//
//	通过 id 或 id参考 获取对象句柄
//
//=========================================================
function getObject(id){
	var src;
	if (typeof(id) == 'object' && id != null){
		src = id;
	}
	else{
		var srcID = trim(id);
		src = document.all(srcID);
		if (src == null){
			srcID = srcID.toUpperCase();
			src = document.all(srcID);
		}
	}
	if (src == null){
		alert("error parameter: id must be 'object reference or object id|name.'");
	}
	return src;
}
//=========================================================
//
//	判断是否输入内容
//
//=========================================================
function isInputed(id, msg, err) {
	var src = getObject(id);
	if (src == null){
		return false;
	}
	
	var str = src.value;
	if (trim(str) < 1) {
		var caption = msg;
		if (caption == null || caption == 'undefined' || trim(caption) == ''){
			try{
				caption = src.title;
				if (caption == null || caption == 'undefined' || trim(caption) == ''){
					var idx = src.parentElement.cellIndex;
					caption = src.parentElement.parentElement.cells(idx - 1).innerText;
				}
			}
			catch(e){
				caption = src.id;
			}
		}
		
		err = "必须输入数据项: '" + caption + "' ";
		alert(err);
		try{
			src.focus();
		}
		catch(e){
		}
		return false;
	}
	return true;
}
//=========================================================
//
//	判断输入内容是否合法的 月日 格式
//
//=========================================================
function isMonthDay(id, mustInputed) {
	// must input
	if (mustInputed){
		if (!isInputed(id)){
			return false;
		}
	}

	// Month Day Format
	var MSG = '输入的月日格式必须为: 年.(或-或/)日,如: 12.01';
	var src = getObject(id);
	try{
		var str = trim(src.value);
		var re = new RegExp("[\-|\.|\/|年]");
		var arr = str.split(re);

		if (arr.length != 2){
			throw msg;
		}
		
		var m = parseInt(arr[0]);
		var d = parseInt(arr[1]);
		if (m < 0 || m > 12 || d < 0 || d > 31){
			throw msg;
		}
		// 添加"月"、"日"属性




		src.Month = m;
		src.Day = d;
	}
	catch(e){
		alert(MSG);
		src.focus();
		return false;
	}
	return true;
}


/*===============
	界面操作
===============*/
//
// 选择列表项




//
function doSelect(osrc, otar){
	for(var i=0; i<osrc.length; i++){
		var opt = osrc.options(i);
		if (opt.selected){
			_addItem(otar, opt);
		}
	}
}
//
// 删除列表中的列表项




//
function doDelete(otar){
	var index = otar.selectedIndex;
	if (index == -1) return ;
	
	for(var i=otar.length-1; i>-1; i--){
		if (otar.options(i).selected){
			index = i;
			otar.options.remove(i);
		}
	}
	var count = otar.options.length;
	if (count > 0){
		if (index == 0){
			otar.selectedIndex = 0;
		}
		else{
			otar.selectedIndex = index - 1;
		}
	}
}
//
// 将列表项移到最前




//
function moveFirst(otar){
	var index = otar.selectedIndex;
	if (index < 1) return;
	
	var opt = otar.options(index);
	var o = document.createElement("OPTION");
	otar.options.add(o, 0);
	o.value = opt.value;
	o.text = opt.text;
	otar.options.remove(index + 1);
	o.selected = true;
}
//
// 将列表项移到上一项的位置
//
function movePrior(otar){
	var index = otar.selectedIndex;
	if (index < 1) return;
	
	var opt = otar.options(index);
	var o = document.createElement("OPTION");
	otar.options.add(o, index-1);
	o.value = opt.value;
	o.text = opt.text;
	otar.options.remove(index + 1);
	o.selected = true;
}

//
// 将列表项移到下一项的位置
//
function moveNext(otar){
	var index = otar.selectedIndex;
	if (index == -1 || index >= otar.options.length-1) return;
	
	var opt = otar.options(index);
	var o = document.createElement("OPTION");
	otar.options.add(o, index+2);
	o.value = opt.value;
	o.text = opt.text;
	otar.options.remove(index);
	o.selected = true;
}
//
// 将列表项移到最后




//
function moveLast(otar){
	var index = otar.selectedIndex;
	if (index == -1 || index >= otar.options.length-1) return;
	
	var opt = otar.options(index);
	var o = document.createElement("OPTION");
	otar.options.add(o);
	o.value = opt.value;
	o.text = opt.text;
	otar.options.remove(index);
	o.selected = true;
}
//
// 添加列表项




//
function _addItem(slt, opt){
	var bContains = false;
	var index = 0;
	for(var i=0; i<slt.length; i++){
		if (slt.options(i).value == opt.value && !bContains){
			bContains = true;
		}
		if (slt.options(i).selected){
			index = i;
		}
	}
	if (slt.selectedIndex == -1) index = slt.length;
	
	if (!bContains){
		var o = document.createElement("OPTION");
		slt.options.add(o, index);
		o.value = opt.value;
		o.text = opt.text;
		o.selected = true;
	}
}


 function GetSeleVal(SelectList)
        {
        
			var cboField="";
			for(var loop_index = 0;loop_index < SelectList.options.length;loop_index++ ) {
						if (loop_index==SelectList.options.length-1) {
						if (SelectList.options[loop_index].value !="")
							cboField+= SelectList.options[loop_index].value;
						}
						else {
						if (SelectList.options[loop_index].value!="")
							cboField+= SelectList.options[loop_index].value+',';
						}			
				}	
			
			if (cboField=="")
			{
				alert("你没有选择选项！");
				return "";
			}
			else
			 {
			     return cboField;
			 }
        }     


var ERR_UNKNOWN = "\u672A\u77E5\u9519\u8BEF"; // UnKnow Error
//******************************************************//
//                                                      //
//                   Window Function                    //
//                                                      //
//******************************************************//
// -------------------------------------------------------
// Function : enterTab
// Descripton : capture KEY Enter to Tab
// Parameter :
//   str - none
// -------------------------------------------------------
function enterTab(){
	if(event.keyCode==13) event.keyCode=9;
}
//--------------------------------------------------------
// Function: isEditTag
// Description: object is editable
// Parameter:
//    o - object
//--------------------------------------------------------
function isEditTag(o){
	if (!o) o = event.srcElement;
	else o = findObj(o);
	var result = false;
	if ((o.tagName == "TEXTAREA") ||
        (o.tagName == "INPUT" && (o.type == "text") || (o.type == "password"))){
    result = true;
	}
	return result;
}
//--------------------------------------------------------
// Function: isClickTag
// Description: object is mouse operatable
// Parameter:
//    o - object
//--------------------------------------------------------
function isClickTag(o){
	if (!o) o = event.srcElement;
	else o = findObj(o);
	var result = false;
	if (o.tagName == "A" ||
      o.tagName == "BUTTON" ||
      o.tagName == "IMG" ||
      o.tagName == "MARQUEE" ||
      o.tagName == "SELECT" ||
      (o.tagName == "INPUT" && (o.type == "button" || 
                                o.type == "checkbox" || 
                                o.type == "file" || 
                                o.type == "radio" || 
                                o.type == "reset" || 
                                o.type == "submit"))){
    result = true;
	}
	return result;
}
// -------------------------------------------------------
// Function : getPath()
// Description : Get Web Application Virtual Url
// Parameter :
//   none
// -------------------------------------------------------
function getPath(){
  if (!top.gAbsolutePath){
		var loc = document.location;
		top.protocal = loc.protocol;
		top.host = loc.host;
		top.hostname = loc.hostname;
		top.port = loc.port;
		top.gAbsolutePath = top.protocal + "//" + top.host + (top.port != '' ? ':' + top.port : '') + loc.pathname.substr(0, loc.pathname.indexOf('/', 1)+1);
  }
  top.path = top.gAbsolutePath;
  return top.gAbsolutePath;
}






//******************************************************//
//                                                      //
//                   String Function                    //
//                                                      //
//******************************************************//
String.prototype.trim = function(){
	return trim(this);
}
String.prototype.getLength = function(){
	return trim(this).length;
}
String.prototype.getLengthA = 
String.prototype.getAbsoluteLength = function(){
	var str = trim(this);
	var len = str.length;
	for (var i=0; i<str.length; i++){
		if (str.charCodeAt(i) > 255)
			len ++;
	}
	return len;
}
// -------------------------------------------------------
// Function : lTrim(str)
// Descripton : trim left EMPTY Char
// Parameter :
//   str - String of you want to trim left
// -------------------------------------------------------
function lTrim(str){
  var whitespace = new String(" \t\n\r");
  var s = new String(str);

  if (whitespace.indexOf(s.charAt(0)) != -1){
    var j=0, i = s.length;
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1){
      j++;
    }
    s = s.substring(j, i);
  }
  return s;
} 
// -------------------------------------------------------
// Function : rTrim(str)
// Descripton : trim right EMPTY Char
// Parameter :
//   str - String of you want to trim right
// -------------------------------------------------------
function rTrim(str){
  var whitespace = new String(" \t\n\r");
  var s = new String(str);

  if (whitespace.indexOf(s.charAt(s.length-1)) != -1){
    var i = s.length - 1;
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1){
      i--;
    }
    s = s.substring(0, i+1);
  }
  return s;
}
// -------------------------------------------------------
// Function : trim(str)
// Descripton : trim EMPTY Char
// Parameter :
//   str - String of you want to trim
// -------------------------------------------------------
function trim(str){
  return rTrim(lTrim(str));
}

// -------------------------------------------------------
// Function : onlyCharacters(str)
// Descripton : valid string contains non digit
// Parameter :
//   str - String of you want to deal
// -------------------------------------------------------
function onlyCharacters(inputString){
  var searchForNumbers = /\d+/;
  if (searchForNumbers.test(inputString)) 
    return false;
  else
    return true;
}





//******************************************************//
//                                                      //
//                   Object Function                    //
//                                                      //
//******************************************************//
// -------------------------------------------------------
// Function : findObj(obj)
// Description : find object in document
// Parameter : 
//   obj - object's id or ref
//   doc - document object ref
// Example : 
//   obj = findObj("image1");
// -------------------------------------------------------
function findObj(obj, doc){
  var p, i, foundObj;
  if (obj != undefined && typeof(obj) == "object") return obj;
  
  if(!doc) doc = document;
  if( (p = obj.indexOf("?")) > 0 && parent.frames.length){
    doc = parent.frames[obj.substring(p+1)].document;
    obj = obj.substring(0,p);
  }
  if(!(foundObj = doc[obj]) && doc.all) foundObj = doc.all[obj];
  for (i=0; !foundObj && i < doc.forms.length; i++) 
    foundObj = doc.forms[i][obj];
  for(i=0; !foundObj && doc.layers && i < doc.layers.length; i++) 
    foundObj = findObj(obj,doc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(obj);
  
  return foundObj;
}
// -------------------------------------------------------
// Function : getParent(obj, tag)
// Description : Get TagName is tag Parent Object 
// Parameter :
//   obj - Source Control
//   tag - Parent Object's TagName(default is DIV)
// -------------------------------------------------------
function getParent(obj, tag){
  var oSource, tagName;
  if (arguments.length == 1){
    oSource = event.srcElement;
    tagName = obj;
  }
  else if (arguments.length == 2){
    oSource = obj;
    tagName = tag;
  }
  else{
		return null;
  }
  
  var result = oSource.parentElement;
  while(result != null && result.tagName != tagName){
    result = result.parentElement;
  }
  return result;
}
//--------------------------------------------------------
// Function : setVisible
// Description :Set object visible
// Parameters:
//    obj - object
//    visible - object's visibility
//          true(default) - visible
//          false - invisible
//    ignoreChild - ignore child object 
//          true(default) - ignore child object
//          false - control child object
//--------------------------------------------------------
function setVisible_(obj, visible, ignoreChild){
  var o,v,c;
  switch(arguments.length){
    case 0:
      o = event.srcElement;
      v = c = true;
      break;
    case 1:
			if (obj != undefined && (typeof(obj) == "object" || typeof(obj) == "string")){
				o = findObj(obj);
				v = c = true;
			}
			else if (typeof(obj) == "boolean"){
				o = event.srcElement;
				v = visible;
				c = true;
			}
      break;
    case 2:
			if (obj != undefined && (typeof(obj) == "object" || typeof(obj) == "string")){
				o = findObj(obj);
				v = visible;
				c = true;
			}
			else if (typeof(obj) == "boolean"){
				o = event.srcElement;
				v = obj;
				c = visible;
			}
      break;
     case 3:
			o = obj;
			v = visible;
			c = ignoreChid;
			break;
  }
  if (o == null) o = event.srcElement;
  if (v == null) v = true;
  if (c == null) c = true;
  
  var display = ""; 
  if (!v) display = "none";
  try{
    o.style.display = display;
    if (!c){
			var oc = o.all;
			if (oc != null){
				if (oc.length != null){
					for (var j=0; j<oc.length; j++){
						oc[j].style.display = display;
					}
				}
				else{
					oc.style.display = display;
				}
			}
    }
  }
  catch(e){
  }
}
//--------------------------------------------------------
// Function: setReadOnly
// Description: set object and children readonly(disabled)
// Parameters:
//    o - object
//    r - false(default) - writable
//      - true - readonly
//--------------------------------------------------------
function setReadOnly_(o, r){
  if (o == null || o.tagName == null || o.style == null || o.style.display == null) return;
  if (r == null) r = false;
  
  try{
    if (isEditTag(o)){
      if (o._sourceReadOnlyTag == undefined) o._sourceReadOnlyTag = o.readOnly;
      if (!r){
				o.readOnly = o._sourceReadOnlyTag;
      }
      else{
				o.readOnly = r;
      }
    }
    else if (isClickTag(o)){
      if (o._sourceReadOnlyTag == undefined) o._sourceReadOnlyTag = o.disabled;
      if (!r){
				o.disabled = o._sourceReadOnlyTag;
      }
      else{
				o.disabled = r;
      }
    }
    
    if ((o.tagName == "BUTTON" && o.className.toUpperCase() == "BTNSELECT") ||
        (o.tagName == "INPUT" && o.type =="button" && o.className.toUpperCase() == "BTNSELECT")){
      if (r){
        o.style.display = "none";
      }
      else{
        o.style.display = "";
      }
    }
    
    var oChilds = o.all;
    if (oChilds != null){
      for(var i=0; i<oChilds.length; i++){
				if (isEditTag(oChilds[i]) || isClickTag(oChilds[i]))
					setReadOnly(oChilds[i], r);
      }
    }
  }
  catch(e){
    alert(e);
  }
}
// -------------------------------------------------------
// Function : getProperty(att, obj)
// Description : get object's att attribue value
// Parameter :
//   att - attribute name
//	 obj - object want to find
// -------------------------------------------------------
function getProperty(att, obj){
  if (!obj) return "";
  
  if (hasProperty(att, obj))
    return eval("obj." + att);
  else 
    return "";
}
// -------------------------------------------------------
// Function : hasProperty(att, obj)
// Description : determin object has att attribue value
// Parameter :
//   att - attribute name
//	 obj - object want to find
// -------------------------------------------------------
function hasProperty(att, obj){
  try{
		var o = eval("obj." + att);
		if (o != null){
		  return true;
		} 
		else{
		  return false;
		}
  }
  catch(e){
		return false;
  }
}

//******************************************************//
//                                                      //
//                   ListBox Function                   //
//                                                      //
//******************************************************//
function getEmptyOption(){
  var valEmpty = '';
  var txtEmpty = '-\u7A7A-';		// --空--
	var opt = document.createElement("OPTION");
  opt.value = valEmpty;
  opt.text = txtEmpty;
  return opt;
}
// -------------------------------------------------------
// Function: contaionOption
// Description: decide listbox contain option or not
// Parameters:
//   list - list box control ref
//   val - value of item
// -------------------------------------------------------
function contaionOption(list, val){
	var contain = false;
  for (var i=0; i<list.options.lengh; i++){
    if (list.options[i].value == val){
      contain = true;
      break;
    }
  }
  return contain;
} 
// -------------------------------------------------------
// Function: addOption
// Description: Add option into select control
// Parameters:
//   slt - list box control ref
//   val - value of item
//   name - display value of item(if ignore,name equal value)
// -------------------------------------------------------
function addOption(slt, val, name){
  if (!contaionOption(slt, val)){
    var opt = document.createElement("OPTION");
    opt.value = val;
    opt.text = (name == null) ? val : name;
    slt.options.add(opt);
  }
}
// -------------------------------------------------------
// Function:  getOption
// Description: get option object by item's value
// Parameters:
//   slt - list box control ref
//   val - value of item
// -------------------------------------------------------
function getOption(slt, val){
  for (var i=0; i<slt.options.length; i++){
    if (slt.options[i].value == val){
      return slt.options[i];
    }
  }
  return null;
}
// -------------------------------------------------------
// Function: createOption
// Description: Create Option Object by option object ref or item's value
// Parameters:
//    opt - option 对象或值
// -------------------------------------------------------
function createOption(opt){
  var option = opt;
  if (typeof(option) != "object"){
    option = document.createElement("OPTION");
    option.value = option.text = opt;
  }
  return option;
}
// -------------------------------------------------------
// Function:  indexOfOption
// Description: get item index
// Parameters:
//   slt - list box control ref
//   opt - option object ref or item's value
// -------------------------------------------------------
function indexOfOption(slt, opt){
  var options = slt.options;
  var option = createOption(opt);
  var result = -1;
  for (var i=0; i< options.length; i++){
    var o = options[i];
    if (o.value == option.value){
      result = i;
      break;
    }
  }
  return result;
}
// -------------------------------------------------------
//  Function:  addListItem
//  Description:  向下拉框添加选择框
//  Parameter:
//    slt - 下拉框
//    opt - option 对象或值
//    index - 指明添加的位置
//    order - 是否自动排序,默认为 true
//    repeat - 是否允许"重复",默认为 false
// -------------------------------------------------------
function addListItem(slt, opt, index, order, repeat){
  var result = false;
  
  var options = slt.options;
  var option = createOption(opt);
  if (!isNaN(index)) index = -1;
  if (order == null) order = true;
  if (repeat == null) repeat = false;
  
  if (!repeat && indexOfOption(slt, opt) > -1){
    return result; // do nothing if duplicate
  }
  
  if (order){
    var loc = options.length;
    for (i=0; i< options.length; i++){
      var o = options[i];
      if (o.value >= option.value){
        loc = i;
        break;
      }
    }
    options.add(option, loc);
    result = true;
  }
  else{
    if (index == -1 || index >= options.length){
      options.add(option);
    }
    else{
      options.add(option, index);
    }
    result = true;
  }
  return result;
}

//--------------------------------------------------------
// Function:  edtListItem
// Description:  替换下拉框中的选择项
// Parameter:
//    slt
//    opt - 新选择项或id或值
//    old - 原选择项
//    reorder - 是否重排序(默认排序,true)
//    repeat - 是否允许重复(默认不允许重复,false)
//--------------------------------------------------------
function edtListItem(slt, opt, old, reorder, repeat){
  var result = false;
  
  var options = slt.options;
  var option = null;
  
  if (old == null) {
    if (slt.selectedIndex > -1){
      option = options[slt.selectedIndex];
    }
    else{
      return result;
    }
  }
  else if (typeof(old) == "object") option = opt;
  else option = getOption(slt, old);
  if (option == null) return result;
  
  if (reorder == null) reorder = true;
  if (repeat == null) repeat = false;  
    
  var index = option.index;
  options.remove(index);
  
  var newOption = createOption(opt);
  result = addListItem(slt, newOption, index, reorder, repeat);
  return result;
}

//--------------------------------------------------------
// Function:  delListItem
// Description:  从下拉框中删除选择框
//  参数:
//    slt - 下拉框
//    opt - option 对象或值
//    all - 是否删除所有值相同项
//--------------------------------------------------------
function delListItem(slt, opt, all){
  var options = slt.options;
  var result = false;
  if (opt == null){
    if (slt.selectedIndex > -1){
      options.remove(slt.selectedIndex);
      result = true;
    }
  }
  else if (typeof(opt) == "object"){
    if (opt.index > -1){
      options.remove(opt.index);
      result = true;
    }
  }
  else{
    if (all){
      var items = 0;
      for (var i=options.length-1; i>=0; i--){
        if (options[i].value == opt){
          items ++;
          options.remove(i);
        }
      }
      if (items>0){
        result = true;        
      }
    }
    else{
      var index = -1;
      for(var i=0; i<options.length; i++){
        if (options[i].value == opt){
          index = i;
          break;
        }
      }
      if (index > -1){
        options.remove(index);
      }
    }
  }
  return result;
}




//******************************************************//
//                                                      //
//                   Cookie Function                    //
//                                                      //
//******************************************************//

// -------------------------------------------------------
// Function : readCookie(name)
// Description : Read cookie
// Parameter :
//   name - Cookie name
// Example :
//		alert(readCookie("myCookie"));
// -------------------------------------------------------
function readCookie(name){
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0){ 
    offset = document.cookie.indexOf(search);
    if (offset != -1){ 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
// -------------------------------------------------------
// Function : writeCookie(name, value, hours)
// Description : Write cookie
// Parameter :
//   name - Cookie name
//   hours - expire date
//           if ignore,cookie will end at session end
// Example :
//   writeCookie("myCookie", "my name", 24);
// -------------------------------------------------------
function writeCookie(name, value, hours){
  var expire = "";
  if(hours != null){
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}



//******************************************************//
//                                                      //
//                   XML Function                       //
//                                                      //
//******************************************************//

//--------------------------------------------------------
// Function: fillSelectByNode
// Description: fill list box by xmlnode
// Parameters:
//    slt - select object
//    node - xmlnode
//    empty - insert empty items before insert or not
//--------------------------------------------------------
function fillSelectByNode(slt, node, empty){
  if (slt == null || node == null || slt.tagName != "SELECT") return;
  // empty all
  for (var i=slt.options.length-1; i>-1; i--)
    slt.options.remove(i);
  
  
  if (empty != false) // add empty row
		slt.options.add(getEmptyOption());
  
  try{  // add list
    if (node.hasChildNodes){
      for (var i=0; i<node.childNodes.length; i++){
        var sub = node.childNodes[i];
        var code = sub.getAttribute("CODE");  
        var name = sub.getAttribute("NAME");
        addOption(slt, code, name);
      }  
    }
  }
  catch(e){
    alert(ERR_UNKNOWN + e);
  }
}


//******************************************************//
//                                                      //
//                   Parameter Function                 //
//                                                      //
//******************************************************//
//--------------------------------------------------------
// Function: getBoolPara
// Description: 获取 Boolean 类型参数值
// Parameters:
//   val - 参数值
//   defaultVal - 默认值(在value为空时)
//--------------------------------------------------------
function getBoolPara(val, defaultVal){
	defaultVal = !!defaultVal;
	var result = true;
	
	if (val == undefined || val == 'undefined'){
		result = defaultVal;
	}
  else if (typeof(val) == 'boolean'){
		result = val;
  }
  else if (typeof(val) == 'string'){
		if (value.toLowerCase() == 'true' ||
		    value.toLowerCase() == 'false'){
			result = eval(val);
		}
  }
  else{
		result = !val;
  }
  return result;
}



/************************************************
function：匹配除 < > & / | ' \以外的所有字母数字中文字符
op  是不包含< > & / | ' \ 返回false
    是包含< > & / | ' \ 返回true
*************************************************/
function unSafeWord(op){
    return new RegExp("[<>&/|'\]+","g").test(op);
}

/****************************************************
功能：表单验证（正则表达式）
1.是否为空；
2.中文字符；
3.双字节字符
4.英文；
5.数字；
6.整数；
7.实数；
8.Email地址；
9.使用HTTP协议的网址；
10.电话号码；
11.货币；
12.手机号码；
13.邮政编码；
14.身份证号码；
15.QQ号码；
16.日期；
17.符合安全规则的密码；
18.某项的重复值；
19.两数的关系比较；
20.判断输入值是否在(n, m)区间；
21.输入字符长度限制(可按字节比较)；
22.对于具有相同名称的单选按钮的选中判断；
23.限制具有相同名称的多选按钮的选中数目；
24.自定义的正则表达式验证；
****************************************************/
Validator = {
    Require : /.+/,
    Email : /^\w+([-+.]\w+)*@\w+([-.]\\w+)*\.\w+([-.]\w+)*$/,
    Phone : /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/,
    Mobile : /^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/,
    Url : /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,
    IdCard : /^\d{15}(\d{2}[A-Za-z0-9])?$/,
    Currency : /^\d+(\.\d+)?$/,
    Number : /^\d+$/,
    Zip : /^[1-9]\d{5}$/,
    QQ : /^[1-9]\d{4,8}$/,
    Integer : /^[-\+]?\d+$/,
    Double : /^[-\+]?\d+(\.\d+)?$/,
    English : /^[A-Za-z]+$/,
    Chinese : /^[\u0391-\uFFE5]+$/,
    //UnSafe : /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/,
    UnSafe : /[<>&/|'\\]+/,
    IsSafe : function(str){return !this.UnSafe.test(str);},
    SafeString : "this.IsSafe(value)",
    Limit : "this.limit(value.length,getAttribute('min'), getAttribute('max'))",
    LimitB : "this.limit(this.LenB(value), getAttribute('min'), getAttribute('max'))",
    Date : "this.IsDate(value, getAttribute('min'), getAttribute('format'))",
    Repeat : "value == document.getElementsByName(getAttribute('to'))[0].value",
    Range : "getAttribute('min') < value && value < getAttribute('max')",
    Compare : "this.compare(value,getAttribute('operator'),getAttribute('to'))",
    Custom : "this.Exec(value, getAttribute('regexp'))",
    Group : "this.MustChecked(getAttribute('name'), getAttribute('min'), getAttribute('max'))",
    ErrorItem : [document.forms[0]],
    ErrorMessage : ["以下原因导致提交失败：\t\t\t\t"],

    Validate : function(theForm, mode){
        var obj = theForm || event.srcElement;
        var count = obj.elements.length;
        this.ErrorMessage.length = 1;
        this.ErrorItem.length = 1;
        this.ErrorItem[0] = obj;
        for(var i=0;i<count;i++){
            with(obj.elements[i]){
                var _dataType = getAttribute("dataType");
                if(typeof(_dataType) == "object" || typeof(this[_dataType]) == "undefined") continue;
                this.ClearState(obj.elements[i]);
                if(getAttribute("require") == "false" && value == "") continue;
                switch(_dataType){
                    case "Date" :
                    case "Repeat" :
                    case "Range" :
                    case "Compare" :
                    case "Custom" :
                    case "Group" : 
                    case "Limit" :
                    case "LimitB" :
                    case "SafeString" :
                        if(!eval(this[_dataType])) {
                            this.AddError(i, getAttribute("msg"));
                        }
                        break;
                    default :
                        if(!this[_dataType].test(value)){
                            this.AddError(i, getAttribute("msg"));
                        }
                        break;
                }
            }
        }
        if(this.ErrorMessage.length > 1){
            mode = mode || 1;
            var errCount = this.ErrorItem.length;
            switch(mode){
                case 2 :
                    for(var i=1;i<errCount;i++)
                        this.ErrorItem[i].style.color = "red";
                case 1 :
                    alert(this.ErrorMessage.join("\n"));
                    this.ErrorItem[1].focus();
                    break;
                case 3 :
                    for(var i=1;i<errCount;i++){
                        try{
                            var span = document.createElement("SPAN");
                            span.id = "__ErrorMessagePanel";
                            span.style.color = "red";
                            this.ErrorItem[i].parentNode.appendChild(span);
                            span.innerHTML = this.ErrorMessage[i].replace(/\d+:/,"*");
                        }
                        catch(e){alert(e.description);}
                    }
                    this.ErrorItem[1].focus();
                    break;
                default :
                    alert(this.ErrorMessage.join("\n"));
                    break;
            }
            return false;
        }
        return true;
    },

    limit : function(len,min, max){
        min = min || 0;
        max = max || Number.MAX_VALUE;
        return min <= len && len <= max;
    },

    LenB : function(str){
        return str.replace(/[^\x00-\xff]/g,"**").length;
    },

    ClearState : function(elem){
        with(elem){
            if(style.color == "red")
                style.color = "";
            var lastNode = parentNode.childNodes[parentNode.childNodes.length-1];
            if(lastNode.id == "__ErrorMessagePanel")
                parentNode.removeChild(lastNode);
        }
    },

    AddError : function(index, str){
        this.ErrorItem[this.ErrorItem.length] = this.ErrorItem[0].elements[index];
        this.ErrorMessage[this.ErrorMessage.length] = this.ErrorMessage.length + ":" + str;
    },

    Exec : function(op, reg){
        return new RegExp(reg,"g").test(op);
    },

    compare : function(op1,operator,op2){
        switch (operator) {
            case "NotEqual":
                return (op1 != op2);
            case "GreaterThan":
                return (op1 > op2);
            case "GreaterThanEqual":
                return (op1 >= op2);
            case "LessThan":
                return (op1 < op2);
            case "LessThanEqual":
                return (op1 <= op2);
            default:
                return (op1 == op2); 
        }
    },

    MustChecked : function(name, min, max){
        var groups = document.getElementsByName(name);
        var hasChecked = 0;
        min = min || 1;
        max = max || groups.length;
        for(var i=groups.length-1;i>=0;i--)
            if(groups[i].checked) hasChecked++;
        return min <= hasChecked && hasChecked <= max;
    },

    IsDate : function(op, formatString){
        formatString = formatString || "ymd";
        var m, year, month, day;
        switch(formatString){
            case "ymd" :
                m = op.match(new RegExp("^\\s*((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})\\s*$"));
                if(m == null ) return false;
                day = m[6];
                month = m[5]--;
                year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
                break;
            case "dmy" :
                m = op.match(new RegExp("^\\s*(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$"));
                if(m == null ) return false;
                day = m[1];
                month = m[3]--;
                year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));
                break;
            default :
                break;
        }
        var date = new Date(year, month, day);
        return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate());

        function GetFullYear(y){return ((y<30 ? "20" : "19") + y)|0;}
    }
}


