

function hideAllSteps()
{
	document.getElementById("div_step1_content").style.display = "none";
	document.getElementById("div_step2_content").style.display = "none";
	document.getElementById("div_step3_content").style.display = "none";
	document.getElementById("div_step1_title").style.color = "black";
	document.getElementById("div_step2_title").style.color = "black";
	document.getElementById("div_step3_title").style.color = "black";
	document.getElementById("div_step4_title").style.color = "black";
	
}

function hideAllSteps2()
{
    document.getElementById("div_step1_content").style.display = "none";
	document.getElementById("div_step2_content").style.display = "none";
	document.getElementById("div_step3_content").style.display = "none";
	document.getElementById("div_step4_content").style.display = "none";
	document.getElementById("div_step5_content").style.display = "none";
	document.getElementById("div_step1_title").style.color = "black";
	document.getElementById("div_step2_title").style.color = "black";
	document.getElementById("div_step3_title").style.color = "black";
	document.getElementById("div_step4_title").style.color = "black";
   
}

function step2()
{
	hideAllSteps();
	document.getElementById("div_step2_content").style.display = "";
	document.getElementById("div_step2_title").style.color = "red";
}

function step1()
{
	hideAllSteps();
	document.getElementById("div_step1_content").style.display = "";
	document.getElementById("div_step1_title").style.color = "red";
}
	
function step3()
{	
	if(checkStep2()==true)
	{
		hideAllSteps();
		document.getElementById("div_step3_content").style.display = "";
		document.getElementById("div_step3_title").style.color = "red";	
	}
}

function step4()
{	
	if(checkStep3()==true)
	{
		document.getElementsByName("form1")[0].submit();
	}
}


function step5()
{	
 if(checkStep5()==true)
	{
	    hideAllSteps2();
		var obj = document.getElementById("select_tborga_property");
		if(obj.value == 3)
		{
		  document.getElementById("div_step3_content").style.display = "";
		  document.getElementById("div_step4_content").style.display = "";
		}
		else
		{
		  document.getElementById("div_step3_content").style.display = "";
		}
		document.getElementById("div_step5_content").style.display = "";
		document.getElementById("div_step3_title").style.color = "red";	
		
	}
}


function step6()
{	
	if(checkStep6()==true)
	{
	document.getElementsByName("form1")[0].submit();
	}
}


function hideValidate()
{
	document.getElementById("div_user_name").style.display = "none";
	document.getElementById("div_user_pwd").style.display = "none";
	document.getElementById("div_user_pwd_check").style.display = "none";
	document.getElementById("div_user_email").style.display = "none";
	document.getElementById("div_imagecode").style.display = "none";
	document.getElementById("div_user_question1").style.display = "none";
	document.getElementById("div_user_question2").style.display = "none";
	document.getElementById("div_user_answer1").style.display = "none";
	document.getElementById("div_user_answer2").style.display = "none";
	//document.getElementById("div_error").innerHTML = '';

}

/**
 * 验证表单步骤2
 * @return bool 
 * */
 
 function checkStep2()
 {
    hideValidate();
    var error = '';
	var count = 0;
	if(isEmpty('input_user_name')==false){
	 
		count ++;
		error = error + '\n' + '请输入用户名';
		document.getElementById("div_user_name").style.display = "";
	}
	else if(checkLength('input_user_name',4,16)==false)
	{
		count ++;
		error = error + '\n' + '用户名长度错误,必须在4到16位之间';
		document.getElementById("div_user_name").style.display = "";
	}
	else
	{
		if(isAlphaNumX('input_user_name')==false){
			count ++;
			error = error + '\n' + '用户名格式错误';
			document.getElementById("div_user_name").style.display = "";
		}
	}
	if(isEmpty('input_password')==false){
		count ++;
		error = error + '\n' + '请输入密码';
		document.getElementById("div_user_pwd").style.display = "";
	}	
	else
	{
		if(checkLength('input_password',4,16)==false){
			count ++;
			error = error + '\n' +'密码长度错误,必须在4到16位之间';
			document.getElementById("div_user_pwd").style.display = "";
		}	
	}
	
	if(isEmpty('input_user_pass_confirm')==false){
		count ++;
		error = error + '\n' + '请输密码验证';
		document.getElementById("div_user_pwd_check").style.display = "";
	}
	else
	{
		if(isEqual('input_password','input_user_pass_confirm')==false){
			count ++;
			error = error + '\n' + '两次密码输入不同';
			document.getElementById("div_user_pwd_check").style.display = "";
		}	
	}
	
	if(isEmpty('input_chknum')==false){
		count ++;
		error = error + '\n' + '请输图片验证码';
		document.getElementById("div_imagecode").style.display = "";
	}
	else if(isAlphaNumX('input_chknum')==false)
	{
			count ++;
			error = error + '\n' + '图片验证码格式错误';
			document.getElementById("div_imagecode").style.display = "";
	}
	
	if(isSelectSelected('select_user_question1')==false){
		count ++;
		error = error + '\n' + '请选择密码提示问题1';
		document.getElementById("div_user_question1").style.display = "";
	}
	else
	{
		if(isEmpty('input_user_answer1')==false){
			count ++;
			error = error + '\n' + '请输入密码密码提示答案1';
			document.getElementById("div_user_answer1").style.display = "";
		}	
	}
	
	if(isSelectSelected('select_user_question2')==false){
		count ++;
		error = error + '\n' + '请选择密码提示问题2';
		document.getElementById("div_user_question2").style.display = "";
	}
	else if(isEmpty('input_user_answer2')==false)
	{
			count ++;
			error = error + '\n' + '请输入密码密码提示答案2';
			document.getElementById("div_user_answer2").style.display = "";
	}	
	else
	{
	    if(isEqual('select_user_question1','select_user_question2')==true){
			count ++;
			error = error + '\n' + '两个密码提示问题不能一样';
			document.getElementById("div_user_question2").style.display = "";
		}	
	}
	
	if(isEmpty('input_user_email')==false){
		count ++;
		error = error + '\n' + '请输入电子邮箱';
		document.getElementById("div_user_email").style.display = "";
	}
	else
	{
		if(checkEmail('input_user_email')==false){
			count ++;
			error = error + '\n' + '请输入正确的邮件地址格式';
			document.getElementById("div_user_email").style.display = "";
		}	
	}
	if(count>0){
	alert(error);
		return false;
	}else{
		return true;
	}	
 }
function hideValidate2()
{   
	document.getElementById("div_tbdepa_name").style.display = "none";
	document.getElementById("div_thproj_threg_type").style.display = "none";
	document.getElementById("div_thproj_threg_type").style.display = "none";
	document.getElementById("div_user_name").style.display = "none";
	document.getElementById("div_user_password").style.display = "none";
	document.getElementById("div_chknum").style.display = "none";
	document.getElementById("div_first_question").style.display = "none";
	document.getElementById("div_first_answer").style.display = "none";
	document.getElementById("div_second_question").style.display = "none";
	document.getElementById("div_second_answer").style.display = "none";
	document.getElementById("div_error").innerHTML = '';

}

/**
 * 验证表单步骤2
 * @return bool 
 * */
function checkStep5()
 {
 
	hideValidate2();
	var error = '';
	var count = 0;
	
	if(isEmpty('input_tbdepa_name')==false){
		count ++;
		error = error + '\n' + '请点击右边按钮选择所属归口！';
		document.getElementById("div_tbdepa_name").style.display = "";
	}
	
	if(isEmpty('select_tborga_property')==false){
	 
		count ++;
		error = error + '\n' + '请选择单位性质！';
		document.getElementById("div_tborga_property").style.display = "";
	}
	
	if(isEmpty('input_thproj_threg_type')==false){
	 
		count ++;
		error = error + '\n' + '请选择工商注册登记类型！';
		document.getElementById("div_thproj_threg_type").style.display = "";
	}
	
	if(isEmpty('input_user_name')==false){
	 
		count ++;
		error = error + '\n' + '请输入用户名！';
		document.getElementById("div_user_name").style.display = "";
	}
	else if(checkLength('input_user_name',4,16)==false)
	{
		count ++;
		error = error + '\n' + '用户名长度错误,必须在4到16位之间';
		document.getElementById("div_user_name").style.display = "";
	}
	else
	{
		if(isAlphaNumX('input_user_name')==false){
			count ++;
			error = error + '\n' + '用户名格式错误';
			document.getElementById("div_user_name").style.display = "";
		}
	}
	
	if(isEmpty('input_tborga_user_password')==false){
		count ++;
		error = error + '\n' + '请输入密码';
		document.getElementById("div_user_password").style.display = "";
	}	
	else
	{
		if(checkLength('input_tborga_user_password',4,16)==false){
			count ++;
			error = error + '\n' +'密码长度错误,必须在4到16位之间';
			document.getElementById("div_user_password").style.display = "";
		}	
	}
	
	if(isEmpty('input_tborga_user_repassword')==false){
		count ++;
		error = error + '\n' + '请输密码验证';
		document.getElementById("div_user_repassword").style.display = "";
	}
	else
	{
		if(isEqual('input_tborga_user_repassword','input_tborga_user_repassword')==false){
			count ++;
			error = error + '\n' + '两次密码输入不同';
			document.getElementById("div_user_repassword").style.display = "";
		}	
	}
	
	if(isEmpty('input_chknum')==false){
		count ++;
		error = error + '\n' + '请输图片验证码';
		document.getElementById("div_chknum").style.display = "";
	}
	else if(isAlphaNumX('input_chknum')==false)
	{
			count ++;
			error = error + '\n' + '图片验证码格式错误';
			document.getElementById("div_chknum").style.display = "";
	}	
	
	if(isSelectSelected('select_first_question')==false){
		count ++;
		error = error + '\n' + '请选择密码提示问题1';
		document.getElementById("div_first_question").style.display = "";
	}
	else
	{
		if(isEmpty('input_first_answer')==false){
			count ++;
			error = error + '\n' + '请输入密码密码提示答案1';
			document.getElementById("div_first_answer").style.display = "";
		}	
	}
	
	if(isSelectSelected('select_second_question')==false){
		count ++;
		error = error + '\n' + '请选择密码提示问题2';
		document.getElementById("div_second_question").style.display = "";
	}
	else if(isEmpty('select_second_question')==false)
	{
		count ++;
		error = error + '\n' + '请输入密码密码提示答案2';
		document.getElementById("div_second_answer").style.display = "";
	}
	else
	{
		if(isEqual('select_first_question','select_second_question')==true){
			count ++;
			error = error + '\n' + '两个密码提示问题不能一样';
			document.getElementById("div_second_question").style.display = "";
		}	
	}	

	if(isEmpty('input_user_email')==false){
		count ++;
		error = error + '\n' + '请输入电子邮箱';
		document.getElementById("div_user_email").style.display = "";
	}
	else
	{
		if(checkEmail('input_user_email')==false){
			count ++;
			error = error + '\n' + '请输入正确的邮件地址格式';
			document.getElementById("div_user_email").style.display = "";
		}	
	}
	
  
	
	if(count>0){
	alert(error);
		return false;
	}else{
		return true;
	}	
																		
}

/**
 * 验证表单步骤3
 * @return bool 
 * */
function checkStep3() 
{
	var error = '';
	var count = 0;
	
	if(isEmpty('input_departsCode_name')==false)
	{
		count ++;
		error = error + '\n' +'请选择你的所属单位！';
	}
	
	if(isEmpty('input_tbusin_personname')==false)
	{
		count ++;
		error = error + '\n' +'请填写你的姓名！';
	}
	
	if(isEmpty('input_tbusin_sex')==false)
	{
		count ++;
		error = error + '\n' +'请选择你的性别！';
	}
	else if(isSelectSelected('input_tbusin_sex') == false)
	{
	   count ++;
	   error = error + '\n' +'你没有选择任何选项,请选择你的性别！';
	}
	
	if(isEmpty('input_tbusin_id_card')==false)
	{
		count ++;
		error = error + '\n' +'请填写你的身份证号！';
	}
	else if(isIDCard('input_tbusin_id_card') == false)
	{
	   count++;
	   error = error + '\n' +'你的身份证号格式不对！';
	}
	else if(checkLength('input_tbusin_id_card',15,18) == false)
	{
	   count++;
	   error = error + '\n' +'你的身份证号长度不对！';
	}
	
	if(isEmpty('input_tbusin_degree')==false)
	{
		count ++;
		error = error + '\n' +'请选择你的学位！';
	}
	else if(isSelectSelected('input_tbusin_degree') == false)
	{
	    count ++;
		error = error + '\n' +'你没有选择任何选项,请选择你的学位！';
	}
	
	if(isEmpty('input_tbusin_honor')==false)
	{
		count ++;
		error = error + '\n' +'请选择你的职称！';
	}
	else if(isSelectSelected('input_tbusin_honor') == false)
	{
	   count ++;
	   error = error + '\n' +'你没有选择任何选项,请选择你的职称！';
	}
	
	if(isEmpty('input_tbusin_birthday')==false)
	{
		count ++;
		error = error + '\n' +'请选择你的出生日期！';
	}
	else if(isDate('input_tbusin_birthday') == false)
	{
	   count++;
	   error = error + '\n' +'请选择你的出生日期格式不正确,请重新选择！';
	}
	
	if(isEmpty('input_tbusin_occupation')==false)
	{
		count ++;
		error = error + '\n' +'请填写你的职务！';
	}
	
	if(isEmpty('input_tbusin_work')==false)
	{
		count ++;
		error = error + '\n' +'请选择你的从事专业！';
	}
	
	if(isEmpty('input_tbusin_graduate')==false)
	{
		count ++;
		error = error + '\n' +'请填写你的毕业院校！';
	}
	
	if(isEmpty('input_tbusin_graduate_date')==false)
	{
		count ++;
		error = error + '\n' +'请选择你的毕业时间！';
	}
	
	if(isEmpty('input_tbusin_home_address')==false)
	{
		count ++;
		error = error + '\n' +'请填写你的家庭住址！';
	}
	
	if(isEmpty('input_tbusin_phone_qh')==false)
	{
		count ++;
		error = error + '\n' +'请填写你的固定电话区号！';
	}
	
	if(isEmpty('input_tbusin_phone_dh')==false)
	{
		count ++;
		error = error + '\n' +'请填写你的固定电话！';
	}
	
	if(isEmpty('input_tbusin_mobile')==false)
	{
	  count ++;
	  error = error + '\n' +'请填写你的移动电话！';
	}
	else if(isCellPhone('input_tbusin_mobile')==false)
	{
	  count ++;
	  error = error + '\n' +'你填写的移动电话格式不正确！';
	}
	
	if(isEmpty('input_tbusin_email')==false)
	{
		count ++;
		error = error + '\n' +'请填写你的电子邮件！';
	}
	else if(isEmail('input_tbusin_email') == false)
	{
	   count ++;
	   error = error + '\n' +'请填写你的电子邮件格式不正确！';
	}
	
	if(isEmpty('input_tbusin_summary') == false)
	{
		count ++;
		error = error + '\n' +'请填写你的个人简介！';
	}

	/* var val1 = document.getElementById('gradeOne').value;
	if(val1=="0")
	{
		count ++;
		error = error + '\n' +'必须选择研究领域';
	} */
	
	if(count>0){
		alert(error);
		return false;
	}else{
		return true;
	}	
}



/**
 * 验证表单步骤3
 * @return bool 
 * */
function checkStep6() 
{
	var error = '';
	var count = 0;
	
	if(isEmpty('input_tborga_name')==false)
	{
		count ++;
		error = error + '\n' +'请输入你的单位名称！';
	}
	else if(checkOrganName() == false)
	{
	    count ++;
		error = error + '\n' +'你输入的单位名称已经存在，请重新输入！';
	}
	
	if(isEmpty('input_tborga_code')==false)
	{
		count ++;
		error = error + '\n' +'请填写你的组织机构代码！';
	}
	/* else if(checkOrganCode() == false)
	{
	    count ++;
		error = error + '\n' +'你输入的组织机构代码已经存在，请重新输入！';
	} */
	
	if(isEmpty('input_tborga_bank_name')==false)
	{
		count ++;
		error = error + '\n' +'请输入开户银行！';
	}
	
	if(isSelectSelected('input_tborga_bank_id') == false)
	{
	   count ++;
	   error = error + '\n' +'请输入开户银行帐号！';
	}
	else if(isNumber('input_tborga_bank_id') == false)
	{
	   count ++;
	   error = error + '\n' +'你输入的开户银行帐号格式不正确,请重新输入！';
	}
	
	if(isEmpty('input_tborga_principal')==false)
	{
		count ++;
		error = error + '\n' +'请输入法定代表人姓名！';
	}
	
	if(isEmpty('input_tborga_principal_phone') == false)
	{
	   count++;
	   error = error + '\n' +'请输入法定代表电话！';
	}
	
	
	if(isEmpty('input_tborga_address')==false)
	{
		count ++;
		error = error + '\n' +'请输入单位地址！';
	}
	
	if(isEmpty('input_tborga_postalcode')==false)
	{
		count ++;
		error = error + '\n' +'请输入邮政编码！';
	}
	else if(CheckZipCode('input_tborga_postalcode') == false)
	{
	   count ++;
	   error = error + '\n' +'你输入的邮政编码格式不正确！';
	}
	
	if(isEmpty('input_tborga_linkman')==false)
	{
		count ++;
		error = error + '\n' +'请输入联系人姓名！';
	}
	
	if(isEmpty('input_tborga_phone')==false)
	{
		count ++;
		error = error + '\n' +'请输入联系人固定电话！';
	}
	
	if(isEmpty('input_tborga_mobile')==false)
	{
		count ++;
		error = error + '\n' +'请输入联系人移动电话！';
	}
	else if(isCellPhone('input_tborga_mobile') == false)
	{
	   count ++;
	   error = error + '\n' +'你填写的联系人移动电话格式不正确！';
	}
	if(isEmpty('input_tborga_linkman_email')==false)
	{
		count ++;
		error = error + '\n' +'请填写你的电子邮件！';
	}
	else if(isEmail('input_tborga_linkman_email') == false)
	{
	   count ++;
	   error = error + '\n' +'请填写你的电子邮件格式不正确！';
	}
	if(isEmpty('input_tborga_linkman_fax')==false)
	{
		count ++;
		error = error + '\n' +'请输入联系人传真！';
	}
	
	if(count>0){
		alert(error);
		return false;
	}else{
		return true;
	}	
}


function checkUserName()
{
	var xmlhttp =initxmlhttp();
	var obj = document.getElementById("input_user_name");
	var user_name = obj.value;	
	var url = "index.php?module=register&act=CheckUsername&user_name="+user_name;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState == 4) { 
			if (xmlhttp.status == 200) { 
			
				if(xmlhttp.responseText==false){
					document.getElementById("input_user_name").value = "用户名被占用,换一个!";
				}
			}
		}			
	}
	xmlhttp.send(null);
}

function checkExpertUserName()
{
    var xmlhttp =initxmlhttp();
	var obj = document.getElementById("input_tbexus_user_username");
	var tbexus_user_username = obj.value;	
	var url = "index.php?module=expert_apply&act=CheckExpertUserName&tbexus_user_username="+tbexus_user_username;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState == 4) { 
			if (xmlhttp.status == 200) { 
			
				if(xmlhttp.responseText==false){
					document.getElementById("input_tbexus_user_username").value = "用户名被占用,换一个!";
				}
			}
		}			
	}
	xmlhttp.send(null);
}

function checkImageCode()
{
	var xmlhttp =initxmlhttp();
	var obj = document.getElementById("input_chknum");
	var chknum = obj.value;
	var url = "index.php?module=register&act=CheckImageCode&chknum="+chknum;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState == 4) { 
			if (xmlhttp.status == 200) { 
				if(xmlhttp.responseText==false){
					document.getElementById("input_chknum").value = "验证码错误!";
				}
			}
		}			
	}
	xmlhttp.send(null);
}

function checkExpertImageCode()
{
	var xmlhttp =initxmlhttp();
	var obj = document.getElementById("input_chknum");
	var chknum = obj.value;
	var url = "index.php?module=expert_apply&act=CheckExpertImageCode&chknum="+chknum;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState == 4) { 
			if (xmlhttp.status == 200) { 
				if(xmlhttp.responseText==false){
					document.getElementById("input_chknum").value = "验证码错误!";
				}
			}
		}			
	}
	xmlhttp.send(null);
}


function checkOrganName()
{
	var xmlhttp =initxmlhttp();
	var obj = document.getElementById("input_tborga_name");
	var tborga_name = obj.value;
	var url = "index.php?module=register&act=CheckOrganName&tborga_name="+encodeURI(tborga_name);
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState == 4) { 
			if (xmlhttp.status == 200) { 
				if(xmlhttp.responseText==false){
					document.getElementById("input_tborga_name").value = "单位名称已经存在!";
				}
			}
		}			
	}
	xmlhttp.send(null);
}



function checkOrganCode()
{
	var xmlhttp =initxmlhttp();
	var obj = document.getElementById("input_tborga_code");
	var tborga_code = obj.value;
	var url = "index.php?module=register&act=CheckOrganCode&tborga_code="+encodeURI(tborga_code);
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState == 4) { 
			if (xmlhttp.status == 200) { 
				if(xmlhttp.responseText==false){
					document.getElementById("input_tborga_code").value = "组织机构代码已经存在!";
				}
			}
		}			
	}
	xmlhttp.send(null);
}

function isExitCard()
{
    var xmlhttp =initxmlhttp();
	var obj = document.getElementById("input_tbusin_id_card");
	var tbusin_id_card = obj.value;
	var url = "index.php?module=register&act=IsExitCard&tbusin_id_card="+tbusin_id_card;
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState == 4) { 
			if (xmlhttp.status == 200) { 
				if(xmlhttp.responseText==false){
					document.getElementById("input_tbusin_id_card").value = "身份证号已经存在!";
				}
			}
		}			
	}
	xmlhttp.send(null);
}
/**
 * 页面导入的时候初始化
 * */
function onPageLoaded()
{
	restrictInput("input_user_name");
	restrictInput("input_user_pwd");
	restrictInput("input_user_pwd_check");
	restrictInput("input_imagecode");
	step1();
	initEvents();
	hideValidate();
}

