﻿var a = false;
var b = false;
var c = false;
var d = false;
var e=false;
var f=false;var g=false;var h=false;
var xmlHttpUserName;
function checkusername(){
	var username = document.getElementById("userName")
	if(window.ActiveXObject){
		xmlHttpUserName = new ActiveXObject("Microsoft.XMLHttp");
	}else if(window.xmlHttpRequest){
		xmlHttpUserName = new xmlHttpRequest();
	}
	document.getElementById("userName_show").innerHTML="检查中。。。";
	if(nameformat()){					
		xmlHttpUserName.onreadystatechange = stateusername;
		xmlHttpUserName.open("post","../servlet/CheckUsername?username="+username.value);
		xmlHttpUserName.send(null);
	}
	else{
		document.getElementById("userName_show").innerHTML = "请正确填写用户名！";
	}	
}

//验证email
		function checkemail()
		{
			var email=document.getElementById("email").value;
			if(email.length<=0){
				document.getElementById("email_show").innerHTML='<font color="red">邮箱号不能为空</font>';
			}else if(email.indexOf("@",0)==-1||email.indexOf(".",0)==-1){
				document.getElementById("email_show").innerHTML='<font color="red">邮箱地址必须包含@和·</font>';
			}else if(email.indexOf("@",0)>email.indexOf(".",0)){
				document.getElementById("email_show").innerHTML='<font color="red">@符号必须在·符号之前</font>';
			}else if(email.indexOf("@",0)==0||email.indexOf(".",0)==email.length-1){
				document.getElementById("email_show").innerHTML='<font color="red">@符号不能是第一位，·符号不能是最后一位</font>';
			}
			else
			{
				document.getElementById("email_show").innerHTML='邮箱号验证通过';
				b=true;
			}
		}

function checkpassword()
{
	  var p=/^(\w){5,20}$/;
      if(p.test(document.getElementById("password").value))
	  {
	     document.getElementById("password_show").innerHTML = "请牢记你的密码！";
	     c = true;
	  }
	  else
	  {
	        document.getElementById("password_show").innerHTML = "请输入正确的密码格式和长度,长度在5-20之间！";
	  }
}
function checkpassword1()
{
			if(document.getElementById("password").value!=document.getElementById("password1").value)
			{
				  document.getElementById("password1_show").innerHTML = "确认密码不正确！"; 
			}
			else
			{
				   document.getElementById("password1_show").innerHTML = "确认密码正确！";
				   d = true;
			}
}

function nameformat(){
	var p=/^[\u4e00-\u9fa5_a-zA-Z0-9]{1,25}/;
	return p.test(document.getElementById("userName").value); 
}
function emailformat()
{  
	var p=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	return p.test(document.getElementById("email").value);
}
function stateusername()
{      
      if(xmlHttpUserName.readyState == 4)
	  {
	        if(xmlHttpUserName.status == 200)
			{
				if(xmlHttpUserName.responseText=="true")
				{
			          document.getElementById("userName_show").innerHTML = "恭喜！该用户名可以正常使用";
			          a = true;
				}
				else
				{     
				      document.getElementById("userName_show").innerHTML = "该用户名已经被使用！";
				}
			}
	  }
}

function checkTel() {
var tel=document.getElementById('telephone').value;
  if(/^13\d{9}$/g.test(tel)||(/^15[8,9]\d{8}$/g.test(tel))) {
document.getElementById("tel_show").innerHTML = "恭喜！电话号码格式正确！";
		e=true;	
  } else {    
document.getElementById("tel_show").innerHTML = "电话号码填写错误!";
  }
}

function checkTrueName()
{
	 if(document.getElementById('trueName').value=="")
	   {	
		document.getElementById("trueName_show").innerHTML = "必须填写真实姓名!";
	   }
	   else
	   {document.getElementById("trueName_show").innerHTML = "真实姓名正确";
		f=true;		
	   }  
}
function checkAddress()
{
	 if(document.getElementById('trueName').value=="")
	   {	
		document.getElementById("address_show").innerHTML = "必须填写地址!";
	   }
	   else
	   {document.getElementById("address_show").innerHTML = "地址填写正确";
		g=true;		
	   }  
}
var times=0;
function subform(){
	var gtext=this.req.responseText;
	var info=document.getElementById("info");
	if(gtext.indexOf("validate_successful")!=-1){
		info.innerHTML="<font color=green>验证码通过</font>";
		//document.forms["myform"].submit();
		h=true;
		//当得到的值表示合法，则验证码通过。
	}
	else{
		times++;
		if(times>=3){
			info.innerHTML="接连3次输入错误。更新验证码，请重新输入";
			document.forms["regFrm"].num.value="";
			show(document.getElementById('random'));
			times=0;
		}else{
			info.innerHTML="第"+times+"次验证码错误,请注意区分大小写 ";
			}
			document.forms["regFrm"].num.select();
		h=false;
		}
}
function validata(){		
		var url="../validate/num.jsp?num="+regFrm.num.value;
		var newxmlhttp=new net.ContentLoader(url,subform,"","get",null,null); 
		return true;
		
	}
function show(o){
	var timenow = new Date().getTime();
	o.src="../validate/random.jsp?d="+timenow;
}
function submitform(){
	if(a&&b&&c&&d&&e&&f&&g&&h){
		regFrm.submit();
	}else{
		alert("请正确填写以上信息！");
	}
}
//修改密码
function submitpwd(){
	if(c&&d&&h){
		regFrm.submit();
	}else{
		alert("请正确填写以上信息！");
	}
}
//修改个人基本信息
function submituser(){
	if(b&&e&&f&&g&&h){
		regFrm.submit();
	}else{
		alert("请正确填写以上信息！");
	}
}
