//验证表单
function CheckInput(){
	var frm=document.frmName
	var strDate,nowYear,nowMonth,nowDay
	with(frm){
		//验证用户名
		if (Trim(username.value).length == 0){
			alert("请输入用户名！")
			username.focus()
			return false
		}else if(!isUsername(Trim(username.value))){
			alert("用户名不能包含 \n ><,[]{}?/+=|\\'\":;~!@#$%^&()` 等字符！")
			username.focus()
			return false
		}
		//验证密码
		if (password.value.length == 0){
			alert("请输入密码！")
			password.focus()
			return false
		}
		if(repassword.value.length == 0){
			alert("请输入确认密码！")
			repassword.focus()
			return false
		}
		if (password.value != repassword.value){
			alert("两次输入密码不符，请重新输入！")
			password.focus()
			return false
		}
		//验证Email
		if(Trim(email.value).length == 0){
			alert("请输入电子信箱地址！")
			email.focus()
			return false
		}
		else if(!isEmail(email.value)){
			alert("请输入正确的电子信箱地址！")
			email.focus()
			return false
		}
		//验证生日
		if(Trim(birthday.value) != 0){
			if(!isDate(birthday.value))
			{
				return false
			}
			else
			{
				strDate = birthday.value
				dateArray = strDate.split("-")
				Year = dateArray[0]
				Month = dateArray[1]-1
				Day = dateArray[2]
				nowYear = nowyear.value
				nowMonth = nowmonth.value-1
				nowDay = nowday.value
				var birthDay = new Date(Year,Month,Day,"00","00","00")
				var Today = new Date(nowYear,nowMonth,nowDay,"00","00","00")
				if (birthDay > Today)
				{
					alert("5岁以下儿童不宜！")
					birthday.focus()
					return false
				}
			}
		}
		
		//验证身份证号码
		if(Trim(pid.value).length == 0)
		{
			alert("请输入身份证号码。")
			pid.focus()
			return false
		}
		else
		{	
			var strP_id = Trim(pid.value)
			var p_idtype = getP_idtype(strP_id)
			if(!p_idtype)
			{
				alert("身份证号码为15位或18位数字，请检查")
				pid.focus()
				return false
			}
			var strBirthday,strSex,strMonth,strDay
			if(p_idtype == 1) 
			{
				if (parseInt(strP_id.substring(8,10)))
					strMonth = parseInt(strP_id.substring(8,10))-1
				else
					strMonth = parseInt(strP_id.substring(9,10))-1
				if (parseInt(strP_id.substring(10,12)))
					strDay = parseInt(strP_id.substring(10,12))
				else
					strDay = parseInt(strP_id.substring(11,12))
				strBirthday =  new Date("19" + strP_id.substring(6,8),strMonth,strDay,"00","00","00")
				strSex = parseInt(strP_id.substring(14,15)) % 2
			}
			if(p_idtype == 2) 
			{
				if (parseInt(strP_id.substring(10,12)))
					strMonth = parseInt(strP_id.substring(10,12))-1
				else
					strMonth = parseInt(strP_id.substring(11,12))-1
				if (parseInt(strP_id.substring(12,14)))
					strDay = parseInt(strP_id.substring(12,14))
				else
					strDay = parseInt(strP_id.substring(13,14))
				strBirthday =  new Date(strP_id.substring(6,10),strMonth,strDay,"00","00","00")
				strSex = parseInt(strP_id.substring(16,17)) % 2
			}
			if(Trim(birthday.value) != 0 && (strBirthday - birthDay) != 0)
			{
				alert("生日与身份证号码不符！")
				pid.focus()
				return false
			}
			var sexValue
			if (sex[0].checked)
			{
				sexValue = 1
			}
			else
			{
				sexValue = 0
			}
			if (strSex != sexValue)
			{
				alert("性别与身份证号码不符！")
				pid.focus()
				return false
			}
		}
		//验证真实姓名
		if (Trim(realname.value).length == 0)
		{
			alert("请输入真实姓名！")
			realname.focus()
			return false
		}
		else if(!isUsername(Trim(realname.value)))
		{
			alert("真实姓名不能包含 \n ><,[]{}?/+=|\\'\":;~!@#$%^&()`等字符!")
			realname.focus()
			return false
		}
		//验证电话
		if(Trim(tel.value).length == 0){
			alert("请输入电话号码！")
			tel.focus()
			return false
		}
		
		//验证地址
		if(Trim(address.value).length == 0){
			alert("请输入地址！")
			address.focus()
			return false
		}
		//验证邮政编码
		if(Trim(zip.value).length == 0){
			alert("请输入邮政编码！")
			zip.focus()
			return false
		}
		
		if (isHasMotor[0].checked)
		{
			//验证品牌
			if(Trim(trademark.value).length == 0){
				alert("请输入品牌！")
				trademark.focus()
				return false
			}
			//验证型号
			if(Trim(model.value).length == 0){
				alert("请输入型号！")
				model.focus()
				return false
			}		
		}
	}
	return true
}
//
function isUsername(strUsername){
	var regexp =/^[^><,\[\]{}?/+=|\\'\":;~!@#$%^&()`]+$/
	return regexp.test(strUsername)
}
function getP_idtype(strP_id){
	var regexp1 = /^(\d{15})$/
	var regexp2 = /^(\d{18})$/
	if(regexp1.test(strP_id)){
		return 1
	}else if(regexp2.test(strP_id)){
		return 2
	}else{
		return 0
	}
}
//初始化Province
function intiProvince(strID){
	var frm=document.frmName
	with(frm.provinceid){
	 	length=0
		for(i=0;i<arrProvince.length;i++){
			options[i]=new Option(arrProvince[i])
			options[i].value = arrProvinceValue[i]
			if (arrProvinceValue[i] == strID)
			{
				options[i].selected = true
			}
		}
	}
}

//初始化City
function intiCity(myIndex,strID){
	var frm=document.frmName
	with(frm.cityid){
		if (arrCity[myIndex][0]=="……")
			disabled = true
		else
			disabled = false
	 	length=0
		for(i=0;i<arrCity[myIndex].length;i++){
			options[i] = new Option(arrCity[myIndex][i])
			options[i].value= arrCityValue[myIndex][i]
			if (arrCityValue[myIndex][i] == strID)
			{
				options[i].selected = true
			}
		}
	}
	
}
