function Createregxml()
{
	try{
		regxml = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){
		try{
 
		regxml = new ActiveXObject("Msxm12.XMLHTTP");
		}catch(E){
		    regxml = false;
		}
	}
	
	if(!regxml && typeof XMLHttpRequest != 'undefined')
	{
	 regxml =new XMLHttpRequest();
	}
	return regxml;
}
 
function returnI()
{
	if(regxml.readyState == 4)
	{
	    var Data = regxml.responseText;
		if( Data == "ok")
		{
		  var divobj = document.getElementById("divusername");  
		   divobj.innerHTML = "<font color=greed>√</font>不存在，可注册为通行证";
		}
		else
		{
		   var divobj = document.getElementById("divusername");
		   divobj.style.display = "block";
		   divobj.innerHTML = "<font color=red>√</font>存在，请输入登陆密码";
		}
	}
}
 
function checkabc(tempstr)
{
	ptempstr=new String("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
	for(i=0;i<tempstr.length;i++)
	{
		if(ptempstr.indexOf(tempstr.charAt(i))==-1)
		{
			return false;
		}
	}
	
	return true;
}
function checkusername(name)
{
	if (name.length>14 |name.length<5)
	{
	   var divobj = document.getElementById("divusername");
       divobj.innerHTML = "<font color=red>X</font>通行证长度需要在5-14之间!";
 
	}
	else
	{
		if(checkabc(name))
		{
			regxml = Createregxml();
			regxml.onreadystatechange=returnI;
			var url = "http://www.melyyidc.com/user/checkusername.asp?";
			regxml.open("POST",url+"username="+name);
			regxml.send(null);
 
			 
		}
		else
		{
		   var divobj = document.getElementById("divusername");
		   divobj.innerHTML = "<font color=red>×</font>通行证只能包含数字和字母";
		}
	}
}
function Iusername()
{
		  var divobj = document.getElementById("divusername");
		  divobj.innerHTML = "提醒：5-14个数字和字母。";
}
 
function returnP()
{
	if(regxml.readyState == 4)
	{
	    var Data = regxml.responseText;
		if( Data == "yesyes")
		{
		  document.reguserform.openX.disabled=false
		  var divobj = document.getElementById("divpassword");  
		   divobj.innerHTML = "<font color=blue>√</font>密码匹配成功，继续下一步。";
		}
		else if( Data == "yes")
		{
		  document.reguserform.openX.disabled=true
		  var divobj = document.getElementById("divpassword");  
		   divobj.innerHTML = "<font color=red>×</font>密码匹配失败，重试密码或注册新通行证。";
		}
		else
		{
		   document.reguserform.openX.disabled=false
		   var divobj = document.getElementById("divpassword");
		   divobj.style.display = "block";
		   divobj.innerHTML = "<font color=blue>√</font>注册新通行证，继续下一步。";
		}
	}
}
 
function checkpassword(pwd)
{
    var username = document.reguserform.username.value
	if (username.length>14 |username.length<5)
	{
	   var divobj = document.getElementById("divpassword");
       divobj.innerHTML = "<font color=red>X</font>请先输入通行证!";
 
	}
	else
	{
		if (pwd.length>16 |pwd.length<6)
		{
		   var divobj = document.getElementById("divpassword");
		   divobj.innerHTML = "<font color=red>X</font>密码长度需要在6-16之间!";
	
		}
		else
		{
			if(checkabc(pwd))
			{
				regxml = Createregxml();
				regxml.onreadystatechange=returnP;
				var url = "/user/checkusername.asp?";
				regxml.open("POST",url+"username="+username+"&password="+pwd);
				regxml.send(null);	 
			}
			else
			{
			   var divobj = document.getElementById("divpassword");
			   divobj.innerHTML = "<font color=red>×</font>密码只能包含数字和字母";
			}
		}
	}
}
function Ipassword()
{
		  var divobj = document.getElementById("divpassword");
		  divobj.innerHTML = "提醒：6-16个数字和字母。";
}
 
function CheckForm()
{
  if (document.reguserform.username.value==""){
    alert("请输入通行证！");
    document.reguserform.username.focus();
    return false;
  }
  else if (document.reguserform.Ftppassword.value==""){
    alert("请输入密码！");
    document.reguserform.Ftppassword.focus();
    return false;
  }
  else if (document.reguserform.year.value==0){
    alert("请选择有效期限！");
    document.reguserform.year.focus();
    return false;
  }
  else
  {
  document.reguserform.openX.value ='请等待不要重复刷新！....';
  document.reguserform.openX.disabled=true;
  document.reguserform.submit();
  }
}  