



/**社会人士与毕业生导航栏切换*/
function changeDisplay(){
	$("#com_man").click(function(){
			$("#grtip").hide();
			$("#mem_nav").css({"display":"block"});
			$("#stu_nav").css({"display":"none"});
			$("#memberClass").val("0");
	});
	
	$("#ent_man").click(function(){
			$("#grtip").show();
			$("#mem_nav").css({"display":"none"});
			$("#stu_nav").css({"display":"block"});
			$("#memberClass").val("1");
	});
}

/**所有Email 提示信息 div*/
var emailDivs = new Array(5);
emailDivs[0]="div_email_rule";
emailDivs[1]="div_email_ok";
emailDivs[2]="div_email_no";
emailDivs[3]="div_email_err";
emailDivs[4]="div_email_exist";


/**所有password 提示信息div*/
var passwordDivs = new Array(4);
passwordDivs[0]="div_password_rule";
passwordDivs[1]="div_password_ok";
passwordDivs[2]="div_password_no";
passwordDivs[3]="div_password_err";

var password2Divs = new Array(3);
password2Divs[0]="div_password2_rule";
password2Divs[1]="div_password2_ok";
password2Divs[2]="div_password2_err";

function setDivShow(arr,id){
	for(var i=0;i<arr.length;i++){
		var div = arr[i];
		var obj_div = document.getElementById(div);
		if(id==div){
			obj_div.style.display = "block";
		} else {
			obj_div.style.display = "none";
		}
	}
}

function showEmailDiv(id){
	setDivShow(emailDivs,id);
}

function showPasswordDiv(id){
	setDivShow(passwordDivs,id);
}

function showPassword2Div(id){
	setDivShow(password2Divs,id);
}

/**重置表单*/
function resetForm(){
	showEmailDiv(emailDivs[0]);
	showPasswordDiv(passwordDivs[0]);
	showPassword2Div(password2Divs[0]);
	document.getElementById("thisForm").reset();
}


/**验证Email*/
function checkEmail(){
	var email = document.getElementById("email").value;
	if(email==""){
		showEmailDiv("div_email_rule");
		return false;
	}
	else{
		if(isEmail(email)){
			if(checkEmailExist(email)){
				showEmailDiv("div_email_ok");
				return true;
			}
			else {
				showEmailDiv("div_email_exist");
				return false;
			}
		}
		else {
			showEmailDiv("div_email_err");
			return false;
		}
	}
}

/**判断Email是否存在*/
function checkEmailExist(email){
	var result = false;
	$.ajax({
		   type:"post",
		   url: "/personal/user_emailCheck.do",
		   async:false, //同步调用
		   data: "email="+email+"&flag=2",
		   success: function(msg){
		   if(msg=="false"){
			   result = true;
		   }
		   else{
			   result = false;
		   }
		}
	}); 
	return result;
}

/**验证Password*/
function checkPassword(){
	var password = document.getElementById("password").value;
	if(password==""){
		showPasswordDiv("div_password_rule");
		return false;
	}
	else {
		if(isPassword(password) && !isSameEamil(password)){
			showPasswordDiv("div_password_ok");
			return true;
		}
		else {
			showPasswordDiv("div_password_err");
			return false;
		}
	}
}

/**查看域名是否与邮箱名相同*/
function isSameEamil(password){
	var email = document.getElementById("email").value;
	if(isEmail(email)){
	 	email = email.substring(0,email.indexOf("@"));
	 	if(email==password){
			return true;
		}
		else {
			return false;
		}
	}
	else {
		return true;
	}
}

function checkPassword2(){
	var password = document.getElementById("password").value;
	var password2 = document.getElementById("password2").value;
	if(password2==""){
		showPassword2Div("div_password2_rule");
		return false;
	}
	else {
		if(password == password2){
			showPassword2Div("div_password2_ok");
			return true;
		}
		else {
			showPassword2Div("div_password2_err");
			return false;
		}
	}
}


function submitForm(){
	var email = document.getElementById("email").value;
	if(email==""){
		showEmailDiv("div_email_no");
		return;
	}
	var password = document.getElementById("password").value;
	if(password==""){
		showPasswordDiv("div_password_no");
		return;
	}
	var password2 = document.getElementById("password2").value;
	if(password2==""){
		showPassword2Div("div_password2_err");
		return;
	}
	
	if(checkEmail() && checkPassword() && checkPassword2()){
		var agreePro = document.getElementById("agreePro").checked;
		if(!agreePro){
			alert("您只有同意我们的服务条款,才能进行下一步的会员注册!");
			return;
		}
		document.getElementById("thisForm").submit();
	}
}
