var validateInput = true;
var checkCheck = true;
	$(document).ready(function(){
    $("#orguserNameID").blur(function(){
        var value = $.trim(this.value);
		var pattern=/^[a-zA-Z][a-zA-Z0-9_]{5,15}$/;
		if(!pattern.test(value)){ 
             $('#username_error').addClass("Reg_Err_1");
			 $('#username_error').html('用户名必须是以字母开头,长度为6-15位的字母、数字、下划线组合');
             validateInput = false;
        }else{
             $.ajax({
                    type:'post',
                    url:'acc/hasEmailAccountInfo.html',
                    data:'userName='+$("#orguserNameID").val(),
                    success:function(data){
                     if(data=='true'){
                         $('#username_error').addClass("Reg_Err_1");
                         $('#username_error').html('用户名已近存在，请更换一个用户名。');               
                          validateInput = false;
                      }else{
                        validateInput = true;
                      } 
                    }
             });
        }
	});
    
	$("#orguserNameID").focus(function(){//获得焦点
            $("#username_error").attr("class", "Reg_Err_0");
	        $("#username_error").html("&nbsp;");	
		    validateInput = true;
	});
			
			//密码验证
			$("#passwordID").blur(function(){
			    var value = $.trim(this.value);
				var pattern=/^[a-zA-Z0-9_]{6,15}$/;
				if(!pattern.test(value)){ 
					  $("#password_error").attr("class", "Reg_Err_1");
					  $("#password_error").html("请用6位以上的文母,数字或下划线。");
                      validateInput = false;
				 }
			});
			$("#passwordID").focus(function(){
				$("#password_error").attr("class", "Reg_Err_0");
				$("#password_error").html("&nbsp;");
				validateInput = true;
			});			
			
			//确认密码验证
			$("#password2ID").blur(function(){ 
			    var value = $.trim(this.value);
				var pattern=  $.trim($("#passwordID").val()) ;
				if(pattern!=value){ 
					  $("#password2_error").attr("class", "Reg_Err_1");
		              $("#password2_error").html("两次密码不一样。");
					  validateInput = false;
				 }
			});
			$("#password2ID").focus(function(){
				$("#password2_error").attr("class", "Reg_Err_0");
		        $("#password2_error").html("&nbsp;");		
				validateInput = true;
			});	
			
			
			//公司名称验证
			$("#orgNameID").blur(function(){ 
			    var value = $.trim(this.value);
				var pattern = /^[a-zA-Z\u0391-\uFFE5]{2,50}$/;
				if(!value.match(pattern)){ 
					  $("#orgName_error").attr("class", "Reg_Err_1");
					  $("#orgName_error").html("公司名称为2到50个字母或汉字。");
					  validateInput = false;
				 }
			});
			$("#orgNameID").focus(function(){
				$("#orgName_error").attr("class", "Reg_Err_0");
				$("#orgName_error").html("&nbsp;");
				validateInput = true;
			});				
			
			
			//联系人验证
			$("#linkManID").blur(function(){ 
			    var value = $.trim(this.value);
				var pattern = /^[\u0391-\uFFE5]{2,6}$/;
				if(!value.match(pattern)){ 
					  $("#linkMan_error").attr("class", "Reg_Err_1");
					  $("#linkMan_error").html("联系人名称为2到6个汉字。");
					  validateInput = false;
				 }
			});
			$("#linkManID").focus(function(){
				$("#linkMan_error").attr("class", "Reg_Err_0");
				$("#linkMan_error").html("&nbsp;");
				validateInput = true;
			});	
			
			
			//联系电话
		   $("#phoneID").blur(function(){ 
			    var value = $.trim(this.value);
				if(value == ''){ 
					  $('#phone_error').attr("class", "Reg_Err_1");
					  $('#phone_error').html("请输入电话号码");
					  validateInput = false;
				 }
			});
			$("#phoneID").focus(function(){
				$('#phone_error').attr("class", "Reg_Err_0");
		        $('#phone_error').html("&nbsp;");		
				validateInput = true;
			});					
			
			//邮箱验证
		   $("#orgemailID").blur(function(){  
			    var value = $.trim(this.value);
				var pattern =/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
				if(!value.match(pattern)){ 
					  $("#email_error").attr("class", "Reg_Err_1");
		              $("#email_error").html("请输入你的邮箱,非常重要的联系方式，如*****@***.com");		
					  validateInput = false;
				 }
			});
			$("#orgemailID").focus(function(){
				$("#email_error").attr("class", "Reg_Err_0");
		        $("#email_error").html("&nbsp;");		
				validateInput = true;
			});	
			
			//企业地址验证
		   $("#addressID").blur(function(){  
			    var value = $.trim(this.value);
				var pattern = /^[a-zA-Z\u0391-\uFFE5\d]{2,50}$/;
				if(!value.match(pattern)){ 
					  $("#address_error").attr("class", "Reg_Err_1");
		              $("#address_error").html("请输入企业的地址");		
					  validateInput = false;
				 }
			});
			$("#addressID").focus(function(){
				$("#address_error").attr("class", "Reg_Err_0");
		        $("#address_error").html("&nbsp;");		
				validateInput = true;
			});			
			
			
			//验证码
		   $("#verifyCodeID").blur(function(){   
			    var value = $.trim(this.value);
				var pattern =/^[0-9]{5,5}$/;
				if(!value.match(pattern)){ 
					  $('#verifyCode_error').attr("class", "Reg_Err_1");
					  $('#verifyCode_error').html("请输入五位数字的验证码");
					  validateInput = false;
				 }
			});
			$("#verifyCodeID").focus(function(){
					  $('#verifyCode_error').attr("class", "Reg_Err_0");
					  $('#verifyCode_error').html("&nbsp;");		
				      validateInput = true;
			});
});

		function checkMessage2(){
			if($("#readMessage").attr("checked")==true){ 
		           $('#readMessage_error').attr("class", "Reg_Err_0");
		           $('#readMessage_error').html("&nbsp;");		
		           checkCheck = true;
			}else{
					$('#readMessage_error').attr("class", "Reg_Err_1");
           			$('#readMessage_error').html("请先阅读个人会员服务条款。");		
           			checkCheck = false;
			}
		}


function checkForm(){
    $("#orguserNameID").blur();
	$("#passwordID").blur();
	$("#password2ID").blur();
	$("#orgNameID").blur();
	$("#linkManID").blur();
	$("#phoneID").blur();
	$("#orgemailID").blur();
    $("#addressID").blur()
	$("#verifyCodeID").blur();
	var yzm = $("#verifyCodeID").val();
	checkMessage2();
	if(!checkCheck)
	return false;
    if(!validateInput){
        return false;   
    }
	if(viableTextOrg!=yzm){
	    $('#verifyCode_error').attr("class", "Reg_Err_1");
	    $('#verifyCode_error').html("验证码输入错误");
		return false;
	}
//    $("#addOrgForm").submit();
}
