$(document).ready(function(){
	//省变化市则跟着变化
	$("#provinceid3").change(function(){
		var provinceid = $("#provinceid3 option:selected").val();
		if(provinceid=="one"){
			$("#codeByAreaid").empty();
			$("#codeByAreaid").append("<option>请选择</option>");
		}else{
			$.post("userinfo.do",{ operate: "getCity", provinceid: provinceid },function(data){
				var citys = data.split(";");
				$("#codeByAreaid").empty();
				$("#codeByAreaid").append("<option>请选择</option>");
				for(var i = 0; i < citys.length-1; i++)
				{
					var cityss = citys[i].split(",");
					$("#codeByAreaid").append("<option value="+cityss[0]+">"+cityss[1]+"</option>");
				}
			})
		}
	});
	$("#provinceid1").change(function(){
		var provinceid = $("#provinceid1 option:selected").val();
		if(provinceid=="one"){
			$("#provinceid2").empty();
			$("#provinceid2").append("<option>请选择</option>");
		}else{
			$.post("userinfo.do",{ operate: "getCity", provinceid: provinceid },function(data){
				var citys = data.split(";");
				$("#provinceid2").empty();
				$("#provinceid2").append("<option>请选择</option>");
				for(var i = 0; i < citys.length-1; i++)
				{
					var cityss = citys[i].split(",");
					$("#provinceid2").append("<option value="+cityss[0]+">"+cityss[1]+"</option>");
				}
			})
		}
	});
	//添加更多资料
		$("#checkbox").click(function(){
			if(this.checked)
			{
				$("#isHiden").css("display","block");
			}else{
				$("#isHiden").css("display","none");
			}
		})
	//判断username是否已被使用
	var check = true;
	$("#username").blur(function(){
		if(jQuery.trim(this.value)=="")
		{
			$("#uname").html("<span class='red01'>用户名不能为空！</span>");
			check = false;
		}else{
			var reg = /\w{6,15}/;
			if(this.value.match(reg))
				$.post("./userinfo.do",{operate:'checkUsernameAjax',username:this.value},function(data){
					if(data=='no')
					{
						$("#uname").html("<span class='red01'>该用户名已经被注册！</span>");
						check = false;
					}
					if(data=='yes')
					{
						$("#uname").html("<span class='gray999'>该用户名可以使用！</span>");
						check = true;
					}
				})
			else
			{
				$("#uname").html("<span class='red01'>用户名必须在6-15位之间！</span>");
				check = false;
			}
			}
	})
	$("#password").blur(function(){
		if(jQuery.trim(this.value)=="")
		{
			$("#passw").html("<span class='red01'>密码不能为空！</span>");
			check = false;
		}else{
			var reg = /\w{6,16}/;
			if(this.value.match(reg))
			{				
					$("#passw").html("长度为6-16位的字母、数字、下划线组合。");
					check = true;				
			}
			else{
				$("#passw").html("<span class='red01'>密码必须在6-16位之间！</span>");
				check = false;
			}
		}
	})
	$("#repassword").blur(function(){
		if(jQuery.trim(this.value)!=jQuery.trim($("#password").val()))
		{
			$("#repassw").html("<span class='red01'>两次密码不一致！</span>");
			check = false;
		}
		else
		{
			$("#repassw").html("再输入一次登录密码。");
			check = true;
		}
	})
	$("#email").blur(function(){
		var emailReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
		if(this.value.match(emailReg))
		{
			check = true;
			$("#emai").html("用于接受招聘企业的面试通知。");
		}
		else{
			check = false;
			$("#emai").html("<span class='red01'>请输入正确格式的Email！</span>");
		}
		
	})
	$("#name").blur(function(){
		var chineseReg = /^[\u0391-\uFFE5]{2,6}$/;
		if(this.value.match(chineseReg))
		{
			check = true;
			$("#name1").html("*");
		}
		else
		{
			check = false;
			$("#name1").html("<span class='red01'>请输入2-6个汉字！</span>");
		}
	})
	$("#codeByNowstatus").blur(function(){
		if(this.value=="1920")
		{
			$("#codeByNowstatus1").html("<span class='red01'>请选择一种目前身份！</span>");
			check = false;
		}
		else
		{
			$("#codeByNowstatus1").html("*");
			check = true;
		}
	})
	var checkTel1 = true;
	var checkTel2 = true;
	$("#telephone").blur(function(){
		
		if(this.value.length<7)
		{
			$("#tel").html("<span class='red01'>请填写规定格式的固定电话。例：027-87581245</span>");
			checkTel1 = false;
		}
		else 
		{
			$("#tel").html("固定电话与移动电话必须填写一项。例：027-87581245");
			checkTel1 = true;
		}
	})
	$("#mobile").blur(function(){
		if(this.value.length==11)
		{
			$("#mobileMessage").html("固定电话与移动电话必须填写一项。例：1310270****");
			checkTel2 = true;
		}
		else{
			$("#mobileMessage").html("<span class='red01'>请填写正确的移动电话</span>");
			checkTel2 = false;
		}
	})
	$("#idcard").blur(function(){
		if(this.value.length>0)
		{
			if(this.value.length<18)
			{
				$("#idcardMsg").html("<span class='red01'>请填写18位身份证号！</span>");
				check = false;
			}
		}
		else
		{
			$("#idcardMsg").html("（注：18位身份证号）");
			check = true;
		}
	})
	$("#submitImage").click(function(){
		$('#username').focus();
		$('#username').blur();
		if(!check)
		{
			alert("请正确填写用户名！");
			return false;
		}
		$('#password').focus();
		$('#password').blur();
		if(!check)
		{
			alert("请正确填写密码！");
			return false;
		}
		$('#repassword').focus();
		$('#repassword').blur();
		if(!check)
		{
			alert("请正确填写密码！");
			return false;
		}
		$('#email').focus();
		$('#email').blur();
		if(!check)
		{
			alert("请正确填写邮箱！");
			return false;
		}
		$('#name').focus();
		$('#name').blur();
		if(!check)
		{
			alert("请正确填写真实姓名！");
			return false;
		}
		$('#codeByNowstatus').focus();
		$('#codeByNowstatus').blur();
		if(!check)
		{
			alert("请正确填写目前身份！");
			return false;
		}
		$('#telephone').focus();
		$('#telephone').blur();
		if(!check)
		{
			alert("请正确填写固定电话！");
			return false;
		}
		$('#mobile').focus();
		$('#mobile').blur();
		if(!check)
		{
			alert("请正确填写移动电话！");
			return false;
		}else{
			if(checkTel1||checkTel2){
				check=true;
			}else{
				alert("请至少填写一种联系方式！");
				check=false;
				return false;
			}
		}
		
		if($("#birthday").val()=="")
		{	
			alert("请填写日期！");
			$("#birthday1").html("请选择您的出生日期！");
			check = false;
			return false;
		}else{
			$("#birthday1").html("");			
		}
		
		
		if(check)
		{	
			$('form:first').attr('action',$('form:first').attr('action')+'&birthday1='+$('#birthday').val());
		}else{
			alert("请填写完整！");
			return false;
		}
	})
	$("#keydown").keydown(function(event){
					
		var currentKey = event.keyCode;
		if(currentKey==13)
		{
			$('#username').focus();
		$('#username').blur();
		if(!check)
		{
			alert("请正确填写用户名！");
			return false;
		}
		$('#password').focus();
		$('#password').blur();
		if(!check)
		{
			alert("请正确填写密码！");
			return false;
		}
		$('#repassword').focus();
		$('#repassword').blur();
		if(!check)
		{
			alert("请正确填写密码！");
			return false;
		}
		$('#email').focus();
		$('#email').blur();
		if(!check)
		{
			alert("请正确填写邮箱！");
			return false;
		}
		$('#name').focus();
		$('#name').blur();
		if(!check)
		{
			alert("请正确填写真实姓名！");
			return false;
		}
		$('#codeByNowstatus').focus();
		$('#codeByNowstatus').blur();
		if(!check)
		{
			alert("请正确填写目前身份！");
			return false;
		}
		$('#telephone').focus();
		$('#telephone').blur();
		if(!check)
		{
			alert("请正确填写固定电话！");
			return false;
		}
		$('#mobile').focus();
		$('#mobile').blur();
		if(!check)
		{
			alert("请正确填写移动电话！");
			return false;
		}else{
			if(checkTel1||checkTel2){
				check=true;
			}else{
				alert("请至少填写一种联系方式！");
				check=false;
				return false;
			}
		}
		
		if($("#birthday").val()=="")
		{	
			alert("请填写日期！");
			$("#birthday1").html("请选择您的出生日期！");
			check = false;
			return false;
		}else{
			$("#birthday1").html("");			
		}
		
		
		if(check)
		{	
			$('form:first').attr('action',$('form:first').attr('action')+'&birthday1='+$('#birthday').val());
		}else{
			alert("请填写完整！");
			return false;
		}
		}
	});
})
