// 建立XMLHttpRequest对象
function getHttpRequestObject(handler) {
 var httpRequest = false;
try {
httpRequest=new XMLHttpRequest;
}
catch(e) {
try {
httpRequest=new ActiveXObject("MSXML2.XMLHTTP");
}
catch(e2) {
try {
httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e3) {
httpRequest=false;
}
}
}
if (!httpRequest) {
alert("XMLHttpRequest init Failed!");
}
     
   httpRequest.onreadystatechange = handler;
   return httpRequest;
}
// 打开和发送非同步请求
function makeRequest(httpRequest, url) {
   httpRequest.open("GET", url, true); // 打开
   httpRequest.send(null);             // 发送
}
var xmlHttp;
var xmlHttp1;
// 发送HTTP请求来验证用户名称
function validateUser(value) {
   // 建立XMLHttpRequest对象
   
   if ( value!="" && value.length < 6 )
   {
	   websen[0]="2"
	   document.getElementById("dui").innerHTML=""
	   
	//document.getElementById("result").innerHTML="<font color=#FF0000>会员登录名只能由6-15个英文字母和数字组成,请重新填写.</font>";   
	document.getElementById("result").innerHTML="<table   border=1 cellpadding=0 cellspacing=0 ><tr><td valign=middle bordercolor=#FF0000 bgcolor=#FFF5D8><img src='../images/websen.gif' width=16 height=16><font color=#000000>会员登录名只能由6-15个英文字母和数字组成,请重新填写.</font></td></tr></table>"
   }
   else
   {
  // document.getElementById("result").innerHTML="&nbsp;&nbsp;正在更新....";
   document.getElementById("result").innerHTML="&nbsp;<img src="+loading+" width=\"19\" height=\"16\" align=\"absmiddle\"> "
   xmlHttp = getHttpRequestObject(showUser);
   if ( xmlHttp != null ) 
   {
      var url = "validateUser.asp";  // 建立URL网址
      url = url + "?user=" + value;
      randNo = parseInt(Math.random()*999999999);
      // 新增随机数避免缓冲区问题
      url = url + "&rand=" + randNo;      
      makeRequest(xmlHttp, url); // 建立HTTP请求
   }
   else 
   {
      alert ("错误! 浏览程序不支持XMLHttpRequest对象!");
      return;
   }
   }
      
}

function  websenwt(value){
	 xmlHttp1 = getHttpRequestObject(xianshi);
	 if ( xmlHttp1 != null ) 
   {
	
	 var dul="YanZheng.asp";
	 dul=dul+"?yanzhen="+value;
	 
	  makeRequest(xmlHttp1, dul);
	  }
	  else{
		   alert ("错误!浏览程序不支持XMLHttpRequest对象!");
           return;
		  }
}

////
function  websenwt1(){
	 xmlHttp1 = getHttpRequestObject(yinchang);
	 if ( xmlHttp1 != null ) 
   {
	
	 var dul="YanZheng.asp";
	
	 
	  makeRequest(xmlHttp1, dul);
	  }
	  else{
		   alert ("错误!浏览程序不支持XMLHttpRequest对象!");
           return;
		  }
}

function  yinchang()
{ 
  if ( xmlHttp1.readyState == 4 ) 
	   
	   {
		 var dui=document.getElementById("demoHTML");   
	   var xmlResult = xmlHttp1.responseXML;
       var str = xmlResult.getElementsByTagName("msg1")[0];
	   var yonghu=str.childNodes[0].nodeValue
	   
	    dui.innerHTML=str.childNodes[0].nodeValue
	  }
	
}

function xianshi(){
	
	   if ( xmlHttp1.readyState == 4 ) 
	   
	   {
		 var dui=document.getElementById("websenid");   
	   var xmlResult = xmlHttp1.responseXML;
       var str = xmlResult.getElementsByTagName("mssg")[0];
	   var yz=str.childNodes[0].nodeValue
	    
		if (yz==1)
		{
		dui.innerHTML=" <table   border=1 cellpadding=0 cellspacing=0 ><tr><td valign=middle bordercolor=#FF0000 bgcolor=#FFF5D8><img src='../images/websen.gif' width=16 height=16><font color=#000000>验证码不能为空！</font></td></tr></table>"
		}else if(yz==2)
		{dui.innerHTML=" <font color=#999999>输入符合规范<font>"}
		else
		{
			dui.innerHTML=" <table   border=1 cellpadding=0 cellspacing=0 ><tr><td valign=middle bordercolor=#FF0000 bgcolor=#FFF5D8><img src='../images/websen.gif' width=16 height=16><font color=#000000>验证码输入有误！</font></td></tr></table>"
		}
	  }
	}

// 显示用户是否已经存在
var websen =Array();
 websen[0]="0";
  websen[1]="0";
function showUser() {
	
	websen[0]=0
	var rightIcon="../images/icon.gif"
	var result=document.getElementById("result");
	result.style.display="block";
   if ( xmlHttp.readyState == 4 ) {
      // 获取响应
	  var dui=document.getElementById("dui");
      var xmlResult = xmlHttp.responseXML;
      var str = xmlResult.getElementsByTagName("msg")[0];
	  var yonghu=str.childNodes[0].nodeValue
	 
		  
		  
	   if (yonghu=="用户名已存在!" ){
		   
		    dui.style.display="";
			document.getElementById("dui").innerHTML=""
	 document.getElementById("result").innerHTML =" <table   border=1 cellpadding=0 cellspacing=0 ><tr><td valign=middle bordercolor=#FF0000 bgcolor=#FFF5D8><img src='../images/websen.gif' width=16 height=16><font color=#000000>"+str.childNodes[0].nodeValue+"</font></td></tr></table>"
	  websen[0]="3";
	   }
	   if(yonghu=="输入符合规范")
	   {
		   
		  document.getElementById("result").innerHTML ="<font color=#999999>"+str.childNodes[0].nodeValue+"<font>";
		  
	   document.getElementById("dui").innerHTML="&nbsp;<img src="+rightIcon+" width=\"19\" height=\"16\" align=\"absmiddle\"> "
		   }
	   if (yonghu=="用户名不能为空!")
	   { websen[0]="1";
	   dui.style.display="";
	   document.getElementById("dui").innerHTML=""
		   document.getElementById("result").innerHTML =" <table   border=1 cellpadding=0 cellspacing=0 ><tr><td valign=middle bordercolor=#FF0000 bgcolor=#FFF5D8><img src='../images/websen.gif' width=16 height=16><font color=#000000>"+str.childNodes[0].nodeValue+"</font></td></tr></table>"
		   }
		if(yonghu=="用户名不能注册!")
		{
	   document.getElementById("dui").innerHTML=""
		   document.getElementById("result").innerHTML =" <table   border=1 cellpadding=0 cellspacing=0 ><tr><td valign=middle bordercolor=#FF0000 bgcolor=#FFF5D8><img src='../images/websen.gif' width=16 height=16><font color=#000000>用户名不能注册!</font></td></tr></table>"
			 return false;
			}
		
   }
}
