﻿function checkform(){
 if (document.getElementById("divshowname").className!='ico_reg_ok')return;
 if (document.getElementById("divshowphone").className=='ico_reg_error')return;
 if (document.getElementById("divshowemail").className!='ico_reg_ok')return;
 if (document.getElementById("divshowpws").className!='ico_reg_ok')return;
 if (document.getElementById("divshowrepws").className!='ico_reg_ok')return;
    document.getElementById("imgshow").onclick=new Function("checkUserform()");
}
function checkUserform(){
  n=document.memberform
  if (n.yzm.value.length!=4){
      alert("请输入验证码");
      return false;
   }
   if((n.Sex[0].checked==false)&&(n.Sex[1].checked==false)){
      alert("请输入性别");
      return false;
   }
  n.action="Reg.html"
	n.submit()
}

function RepwsInfo(Strvalue){
  if (Strvalue.length<6){
      document.getElementById("divshowrepws").innerHTML='<font color=red>密码不能少于6位。</font>';
      document.getElementById("divshowrepws").className='ico_reg_error';
      document.getElementById("imgshow").onclick=null;
      return false;
    }
  if (Strvalue!=document.memberform.pws.value){
    document.getElementById("divshowrepws").innerHTML='<font color=red>您二次输入的密码不一样，请检查。</font>';
    document.getElementById("divshowrepws").className='ico_reg_error';
    document.getElementById("imgshow").onclick=null;
  }
  else if(Strvalue.length>0){
    document.getElementById("divshowrepws").innerHTML='填写完毕';
    document.getElementById("divshowrepws").className='ico_reg_ok';
    document.getElementById("imgshow").className='imgshowok';
    checkform();
  }
}
function ChgEmailInfo(Strvalue){
  var emailreg=/^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,5}$/;
  Strvalue=Strvalue.toLowerCase();
  if (!emailreg.test(Strvalue)){
  	  document.getElementById("divshowChgemail").innerHTML='无效的Email激活信。';
      document.getElementById("divshowChgemail").className='ico_reg_error';
      document.getElementById("imgshow").onclick=null;
    }
else{
	  while(Strvalue.indexOf(".")!=-1){
	   Strvalue=Strvalue.replace('.','%');
	  }
	  while(Strvalue.indexOf("-")!=-1){
	   Strvalue=Strvalue.replace('-',',');
	  }
	  while(Strvalue.indexOf("_")!=-1){
	   Strvalue=Strvalue.replace('_','，');
	  }
	    ShowChild("Einfo","divshowChgemail",Strvalue)
	    //alert('Einfo_'+escape(Strvalue)+'.html')
	    }
	    
    }
function EmailInfo(Strvalue){
  var emailreg=/^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,5}$/;
  if (!emailreg.test(Strvalue)){
  	  document.getElementById("divshowemail").innerHTML='无效的Email。';
      document.getElementById("divshowemail").className='ico_reg_error';
      document.getElementById("imgshow").onclick=null;
    }
else{
	   while(Strvalue.indexOf(".")!=-1){
	   Strvalue=Strvalue.replace('.','%');
	  }
	  while(Strvalue.indexOf("-")!=-1){
	   Strvalue=Strvalue.replace('-',',');
	  }
	  while(Strvalue.indexOf("_")!=-1){
	   Strvalue=Strvalue.replace('_','，');
	  }
	    ShowChild("Einfo","divshowemail",Strvalue)}
    }
function PhoneInfo(Strvalue){
  var reg=/^13\d{9}$/;  
  var reg1=/^15\d{9}$/; 
  if (!(reg.test(Strvalue)||reg1.test(Strvalue))&&Strvalue.length>0){
      document.getElementById("divshowphone").innerHTML='<font color=red>为了您的账户安全，请输入正确的手机号。</font>';
      document.getElementById("divshowphone").className='ico_reg_error';
      document.getElementById("imgshow").onclick=null;
  }
  else if(Strvalue.length>0){
  	  ShowChild("Pinfo","divshowphone",Strvalue)
  }
  else{
  	 document.getElementById("divshowphone").innerHTML='';
     document.getElementById("divshowphone").className='ico_reg_0';
     checkform();
     }
}

function PwsInfo(Strvalue){
   if (Strvalue.length<6){
       document.getElementById("divshowpws").innerHTML='<font color=red>密码不能少于6位。</font>';
       document.getElementById("divshowpws").className='ico_reg_error';
       document.getElementById("imgshow").onclick=null;
       return
    }
  if (document.memberform.rpws.value.length==0){
      document.getElementById("divshowpws").innerHTML='密码设置正确。';
      document.getElementById("divshowpws").className='ico_reg_ok';
      checkform();
   }
  else if(document.memberform.rpws.value!=Strvalue){
  	 document.getElementById("divshowpws").innerHTML='<font color=red>您二次输入的密码不一样，请检查。</font>';
     document.getElementById("divshowpws").className='ico_reg_error';
     document.getElementById("imgshow").onclick=null;
   }
  else{
  	 document.getElementById("divshowpws").innerHTML='密码设置正确。';
     document.getElementById("divshowpws").className='ico_reg_ok';
     checkform();
  }
}
function UserInfo(Str){
 if(Str.value.replace(/[0-9a-zA-Z]*$/g,"")!=""){
        document.getElementById("divshowname").innerHTML="<font color=red>用户名只能使用英文字符和数字，请修改！</font>";
				document.getElementById("divshowname").className='ico_reg_error';
				document.getElementById("imgshow").onclick=null;
				Str.value="";
        return false;
}

if(Str.value.length>4){
	   ShowChild("Sinfo","divshowname",Str.value);
	}
else{
	  document.getElementById("divshowname").innerHTML='<font color=red>用户名不能少于5位，请修改！</font>';
    document.getElementById("divshowname").className='ico_reg_error';
    document.getElementById("imgshow").onclick=null;
  }
}

function ShowChild(url,Str,sid)
{ 
	var xmlHttp
	  try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
        catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlHttp = false; } }
    if (!xmlHttp && typeof XMLHttpRequest!='undefined') { xmlHttp = new XMLHttpRequest(); } 
	if(xmlHttp)
	 {
		  xmlHttp.open('POST',url+'_'+escape(sid)+'.html',true);
		  xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		    var SendData = 'y='+Math.random();
		  xmlHttp.send(SendData);
		  xmlHttp.onreadystatechange=function()
		    {
		       if(xmlHttp.readyState==4)
		         {
			       if(xmlHttp.status==200)
			         {
							 if(xmlHttp.responseText=='0')
								{
								document.getElementById(Str).innerHTML = '填写完毕';
                document.getElementById(Str).className='ico_reg_ok';
								if (Str!="divshowChgemail")
								checkform();
								else
									document.getElementById("imgshow").onclick=new Function("checkEmailform()");
								}
               else{
								 var ttag=Showtag(url);
								 
                document.getElementById(Str).innerHTML = ttag+'<font color=red>已被使用,请换别的</font>';
                document.getElementById(Str).className='ico_reg_error';
                document.getElementById("imgshow").onclick=null;
								
								}
								
			         }
			       else
			         {
				        document.getElementById(Str).innerHTML='出错提示：'+xmlHttp.statusText;
								document.getElementById(Str).className='ico_reg_error';
								document.getElementById("imgshow").onclick=null;
								
			         }
		        }
		     else
		       {
				       document.getElementById(Str).innerHTML='验证处理中...';
							 document.getElementById(Str).className='ico_reg_0';
			      }
	  	   }
		
	    }
	  else
	    {
	 	     document.getElementById(Str).innerHTML='请使用IE6以上版本浏览器';
				 document.getElementById(Str).className='ico_reg_error';
				
	    }
}
function Showtag(czValue){

switch (czValue) {
           case 'Sinfo' :
               czStr = '用户名';break;
           case 'Pinfo' :
               czStr = '手机号';break;
           case 'Einfo' :
               czStr = '邮箱';break;
           
        }
return czStr;
}



