	//用户名（增加对@符号的支持)
	function checkUsername(username) {
		//return /^[a-zA-Z\d\.\@\-_]+$/.test(username);
	 	var pos = username.indexOf("@");
	 	if(pos == -1)
	 		return username.length > 0;
	 	else{
	 		var ssn = username.substring(0,pos);
	 		return ssn.length > 0;
	 		
	 	}
	 	
	}
	//用户密码
	function checkPassword(password) {
	    return password.length>0;
		//return /^.{6,20}$/.test(password); 
	}
	//密保卡序列号
	function checkSerial(serial) {
		return /^\d{15}$/.test(serial); 
	}
	//点卡序列号
	function checkPcSerial(serial) {
		return /^\d{6,14}$/.test(serial); 
	}
	//密保卡随机密码
	function checkPass(otp) {
		return /^\d{3,9}$/.test(otp); 
	}
	//安全码
	function checkPinma(pinma) {
		return /^.{6,16}$/.test(pinma); 
	}
	
	//验证码
	function checkRadomPass(random) {
		return /^.{1,6}$/.test(random); 
	}

	//手机
	function checkMobile(mobile) {
		return /^18\d{9}$/.test(mobile) || /^13\d{9}$/.test(mobile) || /^15\d{9}$/.test(mobile) || /^147\d{8}$/.test(mobile) || mobile.length == 0; 
	}
	
	//找回密保卡的密码
	
	function checkRandomPwd(pwd){
		return /^\d{8}$/.test(pwd);
	}
	
	//找回密保卡时用户填写的手机校验
	
	function checkMobileOfFetchCard(mobile){
		return /^18\d{9}$/.test(mobile) || /^13\d{9}$/.test(mobile) || /^15\d{9}$/.test(mobile) || /^147\d{8}$/.test(mobile);
		
	}
	
	//检查数字图片
	function checkusercheckcode(usercheckcode){
		return 	usercheckcode.length > 0;
		
	}
	function doValidate(form){
		if(form.username && !checkUsername(form.username.value)){
			alert("请输入正确的通行证用户名！");
			form.username.focus();
			return false;
		} else
		if(form.password && !checkPassword(form.password.value)){
			alert("请输入通行证密码！");
			form.password.focus();
			return false;
		} else
		
		if(form.serial && !checkSerial(form.serial.value)){
			alert("请输入正确的密保卡序列号！数字间不需要空格。");
			form.serial.focus();
			return false;
		} else

		if(form.pass && !checkPass(form.pass.value)){
			alert("请重新输入对应位置的密码！");
			form.pass.focus();
			return false;
		} else
		
		if(form.serial1 && !checkSerial(form.serial1.value)){
			alert("请输入正确的密保卡序列号！数字间不需要空格。");
			form.serial1.focus();
			return false;
		} else

		if(form.pass1 && !checkPass(form.pass1.value)){
			if(form.pass1.value.indexOf(' ') >=0 )
				alert("请重新输入对应位置的密码！输入的3个密码之间无需空格。");
			else
				alert("请重新输入对应位置的密码！");
			form.pass1.focus();
			return false;
		} else
		
		if(form.serial2 && !checkSerial(form.serial2.value)){
			alert("请输入正确的密保卡序列号！数字间不需要空格。");
			form.serial2.focus();
			return false;
		} else

		if(form.pass2 && !checkPass(form.pass2.value)){
			if(form.pass2.value.indexOf(' ') >=0 )
				alert("请重新输入对应位置的密码！输入的3个密码之间无需空格。");
			else
				alert("请重新输入对应位置的密码！");
			form.pass2.focus();
			return false;
		} else
		
		if(form.pinma && !checkPinma(form.pinma.value)){
			
			alert("请输入正确的安全码！");
			return false;
			if(form.pinma){
				form.pinma.focus();
			} 

			if(form.pinma.type!="hidden"){
				form.pinma.focus();
			} 
			return false;
		} 
		else 
				
		if(form.serial1 && form.serial2 && form.serial1.value == form.serial2.value){
			alert("两次输入的序列号重复！");
			form.serial2.focus();
			return false;
		} else
		
		if(form.radomPass && !checkRadomPass(form.radomPass.value)){
			alert("请输入正确的验证码！");
			form.radomPass.focus();
			return false;
		} else
			
		if(document.getElementById("recurmobile") && document.getElementById("recurmobile").style.display!='none' 
			&&form.pserial && !checkPcSerial(form.pserial.value)){
			alert("请输入正确的点卡序列号！");
			form.pserial.focus();
			return false;
		} else

		if(document.getElementById("pserial1") && !checkPcSerial(form.pserial.value)){
			alert("请输入正确的点卡序列号！");
			form.pserial.focus();
			return false;
		} else

		if(form.accmobile && form.accmobile.checked && form.mobile.value.length>0){
			alert("请您确定重现密保卡使用的手机号！");
			form.mobile.focus();
			return false;
		} else

		if(form.mobile && !checkMobile(form.mobile.value)){
			alert("请输入正确的手机号！");
			form.mobile.focus();
			return false;
		} else

		if(form.mobileOfGetPwd && !checkMobileOfFetchCard(form.mobileOfGetPwd.value)){
			alert("请输入正确的手机号！");
			form.mobileOfGetPwd.focus();
			return false;
		} else
		
		if(form.pwd && !checkRandomPwd(form.pwd.value)){
			alert("请输入正确的随机密码！");
			form.pwd.focus();
			return false;
		} else 
		
		if(form.usercheckcode && ! checkusercheckcode(form.usercheckcode.value)){
			alert("请输入图片中的文字！");
			form.usercheckcode.focus();
			return false;
			
		}else
		
		return true;
	}

	function formSubmit(form){
		if(form.bind){

			if( form.mobile.value.length>0 && !confirm('您确定绑定这张密保卡吗？确定前请您保管好显示的卡片。') )//用户输入了手机号
				return false;
			else if( form.mobile.value.length==0 && !confirm('您确定绑定这张密保卡吗？确定前请您保管好显示的卡片。\n建议您留下手机号，密保卡丢失后，可以通过手机取回。'))
				return false ;

		}else if(form.add){
            if( form.mobile.value.length>0 && !confirm('您确定增加绑定这张密保卡吗？确定前请您保管好显示的卡片。'))//用户输入了手机号
				return false;
			else if( form.mobile.value.length==0 && !confirm('您确定增加绑定这张密保卡吗？确定前请您保管好显示的卡片。\n建议您留下手机号，密保卡丢失后，可以通过手机取回。') )
				return false;
		}else if(form.chg){
			if( form.mobile.value.length>0 && !confirm('您确定替换这张密保卡吗？确定前请您保管好显示的卡片。')) //用户输入了手机号
				return false;
			else if( form.mobile.value.length==0 && !confirm('您确定替换这张密保卡吗？确定前请您保管好显示的卡片。\n建议您留下手机号，密保卡丢失后，可以通过手机取回。') )
				return false;

		}

		//form validate
		if(doValidate(form)){
			if(form.oper){
					var oper = form.oper.value;
					if(oper == "chg"){
						if(!confirm("如果您的旧卡绑定了多个帐号，这些帐号绑定的旧卡都会同时被替换为新卡。是否继续？"))
							return false;
					}
						
			}
			form.submit();
		}
		return false;
	}
	
	function isEcard(serial){
		var isEcard = false;
		if(serial.value.length > 2){
			if(serial.value.substring(0,2) == '18' || serial.value.substring(0,2) == '19' ){
				isEcard = true;
			}
		}
		if(isEcard){
			document.getElementById("recurmobile").style.display="";
		}else
			document.getElementById("recurmobile").style.display="none";
	}
	
	
	/*
	 * 绑定密保卡表单检查
	 * 
	 */
	 
	function bindCardFormCheck(form){
			
		
		if(form.password && !checkPassword(form.password.value)){
			alert("请输入通行证密码！");
			form.password.focus();
			return false;
		}else
	
		if(form.serial && !checkSerial(form.serial.value)){
			alert("请输入正确的密保卡序列号！数字间不需要空格。");
			form.serial.focus();
			return false;
		} else
		
		
		if(form.pass && !checkPass(form.pass.value)){
			if(form.pass.value.indexOf(' ') >=0 )
				alert("请重新输入对应位置的密码！输入的3个密码之间无需空格。");
			else
				alert("请重新输入对应位置的密码！");
			form.pass.focus();
			return false;
		} else
		
		if(form.mobile && !checkMobile(form.mobile.value)){
			alert("请输入正确的手机号！");
			form.mobile.focus();
			return false;
		} 
		else
		{
			
		//接下来的处理和电子密保卡的绑定类似
		var isEnterCheckInfo = false;
		
		if(form.pinma != null){
				if(form.pinma.value.length > 0){
						
						isEnterCheckInfo = true;
						if(!checkPinma){
							alert("安全码不正确！");
							return false;
						}
				}
		}
		if(form.answer != null){
				if(form.answer.value.length > 0){
						isEnterCheckInfo = true;
				}
		}

		if(!isEnterCheckInfo){
			if(form.pinma == null && form.answer != null){
					alert("请输入提示问题答案！");
					return false;
			}else if(form.pinma != null && form.answer == null){
					alert("请输入安全码！");
					return false;
			}else if(form.pinma != null && form.answer != null){
					alert("请输入安全码或者提示问题答案！");
					return false;
			}else if(form.pinma == null && form.answer == null){
				return true;
			}
			
			
		}
		
		
		
		
		}
		
	

		
		
	}
	/*
	 * 找回电子密保卡表单检查
	*/
	
	function getEcardFormCheck(form){
		
		
		if(form.password && !checkPassword(form.password.value)){
			alert("请输入通行证密码！");
			form.password.focus();
			return false;
		}
		
		var isEnterCheckInfo = false;

		
		 
		
		
		if(form.pinma != null){
				if(form.pinma.value.length > 0){
						
						isEnterCheckInfo = true;
						if(!checkPinma){
							alert("安全码不正确！");
							return false;
						}
				}
		}
		if(form.answer != null){
				if(form.answer.value.length > 0){
						isEnterCheckInfo = true;
				}
		}

		if(!isEnterCheckInfo){
			if(form.pinma == null && form.answer != null){
					alert("请输入提示问题答案！");
					return false;
					
			}else if(form.pinma != null && form.answer == null){
					alert("请输入安全码！");
					return false;
			}else if(form.pinma != null && form.answer != null){
					alert("请输入安全码或者提示问题答案！");
					return false;
			}else if(form.pinma == null && form.answer == null){
				return true;
			}
			
			
		}

		return true;
		

	}
	
	//绑定电子密保卡时，选择输入安全码还是输入提示问题的答案
	function changeUse(input,ctlContainer_innerHTML){
		
	
		if(input.id == "useAnswer"){
				
				document.getElementById("answer").style.background = "white";
				document.getElementById("answer").disabled = "";
				
			
				document.getElementById("ctlcontainer").innerHTML = "<input style=\"background:#cccccc\" disabled =\"disabled\" id=pinma name=pinma type=password class=text />";
				
				
				
				
				
		}else if(input.id == "usePinma"){
			
				document.getElementById("answer").style.background = "#cccccc";
				document.getElementById("answer").disabled = "disabled";
				document.getElementById("answer").value = "";
				
				
				//切换回原来的html.
				document.getElementById("ctlcontainer").innerHTML = ctlContainer_innerHTML;
				document.getElementById("OTPCtl").OnlyNum = false;
				
		}
	}
	
	function changeColor(input){
			input.style.background = "#33FF66";
	}
	
	