var xmlHttp3;      //用于保存XMLHttpRequest对象的全局变量

function createXmlHttp3() 
{
	//根据window.XMLHttpRequest对象是否存在使用不同的创建方式
	if (window.XMLHttpRequest) {
	   xmlHttp3 = new XMLHttpRequest(); //FireFox、Opera等浏览器支持的创建方式
	} else {
	   xmlHttp3 = new ActiveXObject("Microsoft.XMLHTTP");   //IE浏览器支持的创建方式
	}
}
function check_login()
{
	
	if(document.frm_reg2.accout_num.value=="")
	{
		//alert('请输入您的帐号！');
		accout_conent.innerHTML="<font color='#FF0000'>&nbsp;"+"× 请输入您的帐号"+"</font>";
		tr_submitImg.style.display='none';
		tr_cancelImg.style.display='block';
		document.frm_reg2.accout_num.focus();
		return;
	}
	if(document.frm_reg2.accout_num.value.length < 5)
	{
		//alert('请输入五位或五位以上的帐号！');
		accout_conent.innerHTML="<font color='#FF0000'>"+"× 请输入五位或五位以上的帐号"+"</font>";
		tr_submitImg.style.display='none';
		tr_cancelImg.style.display='block';
		document.frm_reg2.accout_num.focus();
		return;
	}
	if(checkNum(document.frm_reg2.accout_num.value)){
		//alert('注册帐号不能全是数字！');
		accout_conent.innerHTML="<font color='#FF0000'>&nbsp;"+"× 注册帐号不能全是数字"+"</font>";
		tr_submitImg.style.display='none';
		tr_cancelImg.style.display='block';
		document.frm_reg2.accout_num.select();
		return;
	}
	if(isChinese(document.frm_reg2.accout_num.value))
	{
		//alert('会员登录名不能为汉字！');
		accout_conent.innerHTML="<font color='#FF0000'>&nbsp;"+"× 会员登录名不能为汉字"+"</font>";
		tr_submitImg.style.display='none';
		tr_cancelImg.style.display='block';
		document.frm_reg2.accout_num.focus();
		return;	
	}
	if(!fucCheckNUM(document.frm_reg2.accout_num.value))
	{
		//alert('会员登录名不能包含非法字符！');
		accout_conent.innerHTML="<font color='#FF0000'>&nbsp;"+"× 会员登录名不能包含非法字符"+"</font>";
		tr_submitImg.style.display='none';
		tr_cancelImg.style.display='block';
		document.frm_reg2.accout_num.focus();
		return;	
	}
	createXmlHttp3(); //创建XmlHttpRequest对象
	
	var accout_num=document.frm_reg2.accout_num.value;

	var url = "ajaxReg.jsp?accout_num="+accout_num+"";
	xmlHttp3.open("POST", url, true);
	xmlHttp3.onreadystatechange = showPage3;
	xmlHttp3.setRequestHeader("Content_Type","application/x-www-form-urlencoded;");
	xmlHttp3.send(null);

}
function check_password(){
  if(document.frm_reg2.pwd.value.length<6)
	{
		document.getElementById("accout_password").style.display="none";
		document.getElementById("accout_password1").style.display="block";
		tr_submitImg.style.display='none';
		tr_cancelImg.style.display='block';
		document.frm_reg2.pwd.focus();
		return;
	}
	if(document.frm_reg2.pwd.value.length>=6)
	{
		document.getElementById("accout_password").style.display="block";
		document.getElementById("accout_password1").style.display="none";
		tr_submitImg.style.display='block';
		tr_cancelImg.style.display='none';
		document.frm_reg2.pwd.focus();
		return;
	}
}

function check_repaswword(){
 if(document.frm_reg2.assurepwd.value.length<6)
	{
		//alert('请输入六位或六位以上的密码！');
		document.getElementById("accout_repassword").style.display="none";
		document.getElementById("accout_repassword1").style.display="block";
		document.getElementById("accout_repassword2").style.display="none";
		tr_submitImg.style.display='none';
		tr_cancelImg.style.display='block';
		document.frm_reg2.assurepwd.focus();
		return;
	}
  //alert(document.frm_reg2.pwd.value!=document.frm_reg2.assurepwd.value);
  if(document.frm_reg2.pwd.value!=document.frm_reg2.assurepwd.value)
	{
		document.getElementById("accout_repassword").style.display="none";
		document.getElementById("accout_repassword1").style.display="none";
		document.getElementById("accout_repassword2").style.display="block";
		tr_submitImg.style.display='none';
		tr_cancelImg.style.display='block';
		document.frm_reg2.assurepwd.focus();
		return;
	}
	document.getElementById("accout_repassword").style.display="block";
	document.getElementById("accout_repassword1").style.display="none";
	document.getElementById("accout_repassword2").style.display="none";
	tr_submitImg.style.display='block';
	tr_cancelImg.style.display='none';
}
function check_mobile(){
	if(!checkMobile(document.frm_reg2.moblie.value)) { 
	  document.getElementById("accout_moblie").style.display="none";
	  document.getElementById("accout_moblie1").style.display="block";
	  tr_submitImg.style.display='none';
	  tr_cancelImg.style.display='block';
      document.frm_reg2.moblie.focus();
      return ;
    }
	 document.getElementById("accout_moblie").style.display="block";
	 document.getElementById("accout_moblie1").style.display="none";
	 tr_submitImg.style.display='block';
	 tr_cancelImg.style.display='none';
}

function showPage3() 
{
	  if (xmlHttp3.readyState == 4 && xmlHttp3.status == 200) 
	  {
		var restr = xmlHttp3.responseText;
		restr=restr.replace(/(^\s*)|(\s*$)/g,"");  //去掉空格和不可见字符
		var show_str=restr.split("#");
		var is_ok=show_str[0];
		if(is_ok=='false')
		{
			accout_conent.innerHTML="<font color='#FF0000'>&nbsp;"+show_str[1]+"</font>";
			tr_submitImg.style.display='none';
			tr_cancelImg.style.display='block';
		}
		else //为true
		{
			accout_conent.innerHTML="<font color='#6AD983'>&nbsp;"+show_str[1]+"</font>";
			tr_submitImg.style.display='block';
			tr_cancelImg.style.display='none';
		}
		
	  }
}
function submit_frm()
{
	
	if(document.frm_reg2.accout_num.value=="")
	{
		alert('请输入会员登陆名！');
		document.frm_reg2.accout_num.focus();
		return;
	}
	if(document.frm_reg2.accout_num.value.length < 5)
	{
		alert('请输入五位或五位以上的帐号！');
		document.frm_reg2.accout_num.focus();
		return;
	}
	if(checkNum(document.frm_reg2.accout_num.value)){
		alert('注册帐号不能全是数字！');
		document.frm_reg2.accout_num.select();
		return;
	}
	if(isChinese(document.frm_reg2.accout_num.value))
	{
		alert('会员登录名不能为汉字！');
		document.frm_reg2.accout_num.focus();
		return;	
	}
	if(!fucCheckNUM(document.frm_reg2.accout_num.value))
	{
		alert('会员登录名不能包含非法字符！');
		document.frm_reg2.accout_num.focus();
		return;	
	}
	if(document.frm_reg2.pwd.value=="")
	{
		alert('请输入登陆密码！');
		document.frm_reg2.pwd.focus();
		return;
	}
	if(document.frm_reg2.pwd.value.length < 6)
	{
		alert('请输入六位或六位以上的密码！');
		document.frm_reg2.pwd.focus();
		return;
	}
	if(!fucCheckNUM(document.frm_reg2.pwd.value))
	{
		alert('密码不能包含非法字符！');
		document.frm_reg2.pwd.focus();
		return;	
	}
	if(document.frm_reg2.pwd.value == document.frm_reg2.accout_num.value)
	{
		alert('您输入的密码不能和帐号一致！');
		document.frm_reg2.pwd.focus();
		return;
	}
	if(document.frm_reg2.pwd.value == document.frm_reg2.moblie.value)
	{
		alert('您输入的密码不能和手机号码一致！');
		document.frm_reg2.pwd.focus();
		return;
	}
	if(document.frm_reg2.pwd.value == document.frm_reg2.email.value)
	{
		alert('您输入的密码不能和电子邮箱一致！');
		document.frm_reg2.pwd.focus();
		return;
	}
	if(document.frm_reg2.pwd.value == document.frm_reg2.tel3.value)
	{
		alert('您输入的密码不能和固定电话一致！');
		document.frm_reg2.pwd.focus();
		return;
	}
	if(document.frm_reg2.pwd.value == document.frm_reg2.fax3.value)
	{
		alert('您输入的密码不能和传真一致！');
		document.frm_reg2.pwd.focus();
		return;
	}
	
	if(document.frm_reg2.assurepwd.value=="")
	{
		alert('请输入确认密码！');
		document.frm_reg2.assurepwd.focus();
		return;
	}
	if(!fucCheckNUM(document.frm_reg2.assurepwd.value))
	{
		alert('确认密码不能包含非法字符！');
		document.frm_reg2.assurepwd.focus();
		return;	
	}
	if(document.frm_reg2.pwd.value != document.frm_reg2.assurepwd.value)
	{
		alert('您输入的确认密码和密码不一致！');
		document.frm_reg2.assurepwd.focus();
		return;
	}
	if(document.frm_reg2.name.value!="" && !isChinese(document.frm_reg2.name.value))
	{
		alert('真实姓名必须为汉字！');
		document.frm_reg2.name.focus();
		return;
	}
	if(document.frm_reg2.moblie.value=="")
	{
		alert('请输入你的手机号码！');
		document.frm_reg2.moblie.focus();
		return;
	}
	if(document.frm_reg2.moblie.value.length !=11)
	{
		alert('请你输入11位手机号码！');
		document.frm_reg2.moblie.focus();
		return;
	}
	if(!checkMobile(document.frm_reg2.moblie.value)) { 
      alert("您的手机号码不合法！");
      document.frm_reg2.moblie.select();
      return ;
    }
	if(document.frm_reg2.email.value!="" && !chkEmail(document.frm_reg2.email.value))
	{
		alert('你的电子邮箱格式不正确！');
		document.frm_reg2.email.focus();
		return;
	}
	/*if(document.frm_reg2.email.value!="")
	{
		alert('请输入你的电子邮箱！');
		document.frm_reg2.email.focus();
		return;
	}
	var email=document.frm_reg2.email;
	if(email.value.toString().search(/^([a-zA-Z0-9_\.-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/ )==-1)
	{
			alert("E-mail格式不正确！");
			document.frm_reg2.email.focus();
			return;
	}*/
	if(document.frm_reg2.code.value=="")
	{
		alert('请输入验证码！');
		document.frm_reg2.code.focus();
		return;
	}else{
		createXmlHttp3(); //创建XmlHttpRequest对象
	
		var code=document.frm_reg2.code.value;
	
		var url = "ajaxCheckCode.jsp?code="+code+"";
		xmlHttp3.open("POST", url, false);
		xmlHttp3.onreadystatechange = checkCode;
		xmlHttp3.setRequestHeader("Content_Type","application/x-www-form-urlencoded;");
		xmlHttp3.send(null);
	}
	
}
function checkCode(){
	 if (xmlHttp3.readyState == 4 && xmlHttp3.status == 200) 
	  {
		var restr = xmlHttp3.responseText;
		restr=restr.replace(/(^\s*)|(\s*$)/g,"");  //去掉空格和不可见字符
		var show_str=restr.split("#");
		var is_ok=show_str[0];
		if(is_ok=='false')
		{
			alert("验证码输入错误!");
			ref_code(document.getElementById('random'));
			document.frm_reg2.code.focus();
			return;
		}else{
			document.frm_reg2.randCode.value=show_str[2];
			document.frm_reg2.submit();
		}
		
	  }
}
function ref_code(page) //重新获取验证码
{
	var now=new Date();
	page.src="code1.jsp?code="+now;
}
function change_city()
{	
	createXmlHttp3(); //创建XmlHttpRequest对象
	var provice=document.frm_reg2.provice.value; 
	
	if (xmlHttp3.readyState == 4 || xmlHttp3.readyState == 0) {
		var url = "ajaxCity.jsp?city_id="+provice;
		xmlHttp3.open("POST", url, true);
		xmlHttp3.onreadystatechange = showCity;
		xmlHttp3.setRequestHeader("Content_Type","application/x-www-form-urlencoded;");
		xmlHttp3.send(null);
	}
}
function showCity()
{
	if (xmlHttp3.readyState == 4 && xmlHttp3.status == 200) 
  	{
		document.getElementById("city").innerHTML="";
		var restr = xmlHttp3.responseText;
		restr=restr.replace(/(^\s*)|(\s*$)/g,"");  //去掉空格和不可见字符
		
		var unitys_str=restr.split("##");
		for(var i=0;i<unitys_str.length;i++)
		{
			var s_unity=unitys_str[i];
			if(s_unity!="" || s_unity!=null)
			{
				var s_type=s_unity.split("|");
				//给控件（下拉框）赋值
				var opt=document.createElement("OPTION");
				document.getElementById("city").add(opt);
				opt.value=s_type[0];
				opt.text=s_type[1];
			}
		}
		document.getElementById("city").options[0].selected=true;
	}
}
function  isChinese(name)  //中文值检测
{  
	if(name.length  ==  0)
	return  false;
	
	for(i  =  0;  i  <  name.length;  i++)  
	{  
		if(name.charCodeAt(i)  >  128)
		return  true;
	}
	return  false;
}
function chkEmail(email) //检测Email     
{
	var i=email.length;
	var temp = email.indexOf('@');    
	var tempd = email.indexOf('.');    
	if (temp>1)
	{
		if ((i-temp) > 3)
		{
			if ((i-tempd)>0)
			{
				return true;      
			}
		}
	}  
	return false;      
}
function fucCheckNUM(str)      
{
	var i,j,strTemp;
	strTemp="`~!@#$%^&*()-+=,./\<>?|";      
	for (i=0;i<str.length;i++)
	{
		j=strTemp.indexOf(str.charAt(i));      
		if (j>=0)      
		{
			//说明包含以上符号     
			return false;      
		}      
	}      
	//说明不包含以上符号     
	return true;      
}
//难是否全部是数字
 function checkNum(str){
   return str.match(/\D/)==null
 }
//验证手机号码
function checkMobile( s ){ 
	var regu =/^[1][358][0-9]{9}$/; 
	var re = new RegExp(regu);  
	if (re.test(s)) { 
	return true; 
	}else{ 
	return false; 
	} 
} 
