function AddOptions(SelectListId,TopPid,SelSubPid)
  {
	for(i=0;i<subpid[TopPid].length;i++)
	{
		var objOption = new Option(subpid[TopPid][i][1],subpid[TopPid][i][0]);
		document.getElementById(SelectListId).options.add(objOption);  
		if(SelSubPid==subpid[TopPid][i][0])
			document.getElementById(SelectListId).options[i].selected=true;
	}
  }
  function RemoveOptions(SelectListId)
  {
	var len=document.getElementById(SelectListId).options.length;
	for(i=(len - 1);i>=0;i--)
	{
		//document.getElementById(SelectListId).options.remove(i);
		document.getElementById(SelectListId).remove(i);
	}
  }
  function DoChange(SelectListId,TopPid,SelSubPid)
  {
	RemoveOptions(SelectListId);
	AddOptions(SelectListId,TopPid,SelSubPid);
  }

  //mem_Reg
    function CheckInputId(InputId)
	{
		var ChkVal=document.getElementById(InputId).value;
		if(ChkVal.length==0)
		{
			alert("请输入您要检测的信息！");
			document.getElementById(InputId).focus();
			return false;
		}
		return true;
	}
    function DoCheckUserName(InputId,ButtonId)
	{
		var rtn;
		var ChkVal;
		if(CheckInputId(InputId))
		{
			ChkVal=document.getElementById(InputId).value;
			if(ChkVal.length>12 || ChkVal.length<4)
			{
				alert("用户名密码长度在4－12位之间，请重新输入");
				document.getElementById(InputId).focus();
				return false
			}			
			document.getElementById(ButtonId).disabled=true;
			rtn=showModalDialog('mem_do_checkuser.php?type=1'+'&val='+ChkVal,0,'DialogWidth:0PX;DialogHeight:0PX;status=no;help=no;resizable=yes;');
			if(rtn=="1")
			{
				alert("您可以使用该用户户名["+ChkVal+"]进行注册！");
				document.getElementById(ButtonId).disabled=false;
				return true;
			}
			else
			{	
				alert("该用户名["+ChkVal+"]已存在，请重新输入！");
				document.getElementById(ButtonId).disabled=false;
				document.getElementById(InputId).focus();				
				return false;
			}
			return true;			
		}
	}

	function DoCheckUserCode(TypeName,InputId,ButtonId)
	{
		var rtn;
		var ChkVal;
		var msg,msg1;
		var Obj=document.getElementsByName(TypeName);
		var i=0;
		var UserType;
		for(i=0;i<Obj.length;i++)
		{
			if(Obj[i].checked)
			{	
				UserType=Obj[i].value;
				break;
			}
		}
		if(CheckInputId(InputId))
		{
			ChkVal=document.getElementById(InputId).value;
			if(UserType==1)
			{
				//企业
				if(ChkVal.length>50 || ChkVal.length<1)
				{
					alert("企业机构代码长度在1－50位之间，请重新输入");
					document.getElementById(InputId).focus();
					return false
				}
				msg="您可以使用该机构代码["+ChkVal+"]进行注册！";
				msg1="该机构代码["+ChkVal+"]已存在，请重新输入！";
			}
			else if(UserType==2)
			{
				//个人
				pattern = /(^\d{15}|\d{18})$/;
				if(pattern.test(ChkVal)==false)
				{
					alert("个人身份证号码长度应是15或者18位数字！");
					document.getElementById(InputId).focus();
					return false;
				}
				msg="您可以使用该身份证号码["+ChkVal+"]进行注册！";
				msg1="该身份证号码["+ChkVal+"]已存在，请重新输入！";
			}						
			document.getElementById(ButtonId).disabled=true;
			rtn=showModalDialog('mem_do_checkuser.php?type=2'+'&val='+ChkVal,0,'DialogWidth:0PX;DialogHeight:0PX;status=no;help=no;resizable=yes;');
			if(rtn=="1")
			{				
				alert(msg);
				document.getElementById(ButtonId).disabled=false;
				return true;
			}
			else
			{	
				alert(msg1);
				document.getElementById(ButtonId).disabled=false;
				document.getElementById(InputId).focus();				
				return false;
			}
			return true;			
		}
	}
	
	//表单验证
	function CheckDataByFrm(FormName)
	{
		var DataType;
		var LenStr;
		var DataVal;
		var startLen=1;
		var Len=0;
		var lenAry=new Array();
		var pattern;
		var ElementType;
		var FormObject;		
		eval("FormObject="+FormName);
		for(i=0;i<FormObject.length;i++)
		{
			startLen=1;
			ElementType=FormObject[i].type.toLowerCase();
			//alert("i:"+i+"，"+FormObject[i].name+"，"+ElementType);
			if(ElementType!="text" && ElementType!="textarea" && ElementType!="password" && ElementType!="file")
				continue;
			if(FormObject[i].disabled)continue;
						
			DataType=FormObject[i].datatype;			
			DataVal=FormObject[i].value;
			if(DataVal.length==0)
				Len=0;
			else Len=GetStrLen(DataVal);
			
			LenStr=FormObject[i].datalen;

			if(typeof(LenStr)!='undefined')
			{
				lenAry=LenStr.split(",");
				startLen=parseInt(lenAry[0]);
				endLen=parseInt(lenAry[1]);
				if(Len<startLen || Len>endLen)
				{					
					alert(FormObject[i].report+"(字符串长度在"+startLen+"-"+endLen+"之间)");
					FormObject[i].focus();
					return false;
				}
			}

			if(typeof(DataType)!='undefined')
			{	
				//有类型设置且为varchar时，不能为空
				DataType=DataType.toLowerCase();
				if(DataType=="varchar")
				{	
					//字符长度判断
					if(Len==0)
					{
						alert(FormObject[i].report);
						FormObject[i].focus();
						return false;
					}
					else	continue;
				}
				else if(DataType=="email" && Len>0)
				{
					pattern = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
					if(pattern.test(DataVal)==false)
					{
						alert("您输入的Email地址格式不正确，请重新输入！");
						FormObject[i].focus();
						return false;
					}
				}
				else if(DataType=="fileno" && Len>0)
				{
					pattern = /(^\d{9})$/;
					if(pattern.test(DataVal)==false)
					{
						alert(FormObject[i].report);
						FormObject[i].focus();
						return false;
					}
				}
				else if(DataType=="checknum" && Len>0)
				{
					pattern = /(^[0-9a-zA-Z]{4})$/;
					if(pattern.test(DataVal)==false)
					{
						alert(FormObject[i].report);
						FormObject[i].focus();
						return false;
					}
				}
				else if(DataType=="idcard" && Len>0)
				{
					pattern = /(^\d{15}|\d{18})$/;
					if(pattern.test(DataVal)==false)
					{
						alert(FormObject[i].report);
						FormObject[i].focus();
						return false;
					}
				}

			}
		}
		return true;

	}
	function GetStrLen(Str)
	{
		var len=0;
		for(j=0;j<Str.length;j++)
		{
			if(Str.charCodeAt(j)>127)
				len=len+2;
			else len=len+1;
		}
		return len;
	}
	function IsMatch(ElementIda,ElementIdb,What)
	{
		if(document.getElementById(ElementIda).value!=document.getElementById(ElementIdb).value)
		{
			alert(What+"两次输入不一致，请重新输入！");
			document.getElementById(ElementIda).focus();
			return false;
		}
		else return true;
	}

	function attach_view(SelectId)
	{
		var Obj = document.getElementById(SelectId);
	    if (Obj.value.length ==0)
	    {
	        alert("请选定已经上传的文件！");
	        Obj.focus();
	        return false;
	    }
	    else
	    {
			document.forms['frmAttach'].action="attach_down.php?cmd=view";	    	
	    	document.forms['frmAttach'].submit();	    	
	    	return true;
	    }
	}
	function attach_delete(SelectId)
	{
		var valRet="";
		var b_con=false;
		var Obj = document.getElementById(SelectId);		
	    if (Obj.value.length ==0)
	    {
	        alert("请选定已经上传的文件！");
	        Obj.focus();
	        return false;
	    }	    
	    selectTxt=Obj.options[Obj.selectedIndex].text;
	    b_con=confirm('真的要删除预审文件【'+selectTxt+'】？');
		if(!b_con)return false;
		document.forms['frmAttach'].action="prejudge_attach.php?cmd=delete";
		document.forms['frmAttach'].submit();
		return true;
	}
	function attach_upload()
	{
		if(CheckDataByFrm(document.forms['frmAttach'].name))
		{
			document.forms['frmAttach'].action="prejudge_attach_do_submit.php";
			document.forms['frmAttach'].submit();
			return true;
		}
		return false;
	}
	function attach_down(FileNo,CheckNum,FileId)
	{
		var i=0;
		for(i=0;i<document.forms.length;i++)
		{
			if(document.forms[i].name=="frmList")
			{
				document.getElementById('PrejudgeAttach').value=FileNo+"|"+CheckNum+"|"+FileId;
				document.forms[i].action="attach_down.php?cmd=view";
				document.forms[i].submit();
				break;
			}
		}		
		return true;
	}
	function NextPage(f,n)
	{
		document.forms[0].action="prejudge_attach.php";
		document.forms[0].submit();		
		return true;
	}
	
	function DoHidden(type)
	{
		if(type==1)
		{
			//企业
			document.getElementById('CompName').style.display="";
			document.getElementById('LegalMan').style.display="";
			document.getElementById('LegalRepresenative').disabled=false;
			document.getElementById('RealName').disabled=false;

			document.getElementById('CodeName').innerHTML="机构代码";
			//document.getElementById('UserCode').value="";
			document.getElementById('UserCode').report="企业单位机构代码长度不能超过50字节！";
			document.getElementById('UserCode').datalen="1,50";
			document.getElementById('UserCode').datatype="varchar";
		}
		else if(type==2)
		{
			//个人
			document.getElementById('CompName').style.display="none";
			document.getElementById('LegalMan').style.display="none";
			document.getElementById('LegalRepresenative').disabled=true;
			document.getElementById('RealName').disabled=true;

			document.getElementById('CodeName').innerHTML="身份证号码";
			//document.getElementById('UserCode').value="";
			document.getElementById('UserCode').report="个人身份证号码长度应是15或者18位数字！";
			document.getElementById('UserCode').datalen="15,18";
			document.getElementById('UserCode').datatype="idcard";			
		}
	}
	function prejudge_view(f,n)
	{
		url="prejudge_view.php?f="+f+"&n="+n;
		//window.location.href=url;
		window.open(url);
		return true;
	}