function getXMLRequester( ){
var RegXmlhttp=false;
    try{
        if( window.ActiveXObject ){
            for( var i = 5; i; i-- ){
                try{
                    if( i == 2 ){
RegXmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );    
                    }else{
RegXmlhttp = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );	
RegXmlhttp.setRequestHeader("Content-Type","text/xml");
RegXmlhttp.setRequestHeader("Content-Type","gb2312");
RegXmlhttp.setRequestHeader("Content-Type","utf-8");
                 }
break;}
                catch(e){                        
                    RegXmlhttp = false;
                }
            }
        }else if( window.XMLHttpRequest ){
            RegXmlhttp = new XMLHttpRequest();
            if (RegXmlhttp.overrideMimeType) {
                RegXmlhttp.overrideMimeType('text/xml');
            }
        }
    }catch(e){
        RegXmlhttp = false;
    }
    return RegXmlhttp ;
}

 function CheckUserid()
{
	
   if(checkspace(document.userinfo.username.value)) {
	document.userinfo.username.focus();
	//alert("用户名不能为空，请您重新输入，谢谢^_^!");
   document.getElementById("ShowLogin").innerHTML="<div class='UserInputCheckErr'>用户名不能为空，请重新输入，谢谢！</div>";
	return false;}
	
var str=document.userinfo.username.value;
if(/^[a-zA-Z0-9\u4e00-\u9fa5]{1}([\u4e00-\u9fa5\a-zA-Z0-9]|[_]){2,15}$/.test(str)==false)
{ 
//alert("用户名只能为英文和中文和下划线"); 
document.userinfo.username.focus();
document.getElementById("ShowLogin").innerHTML="<div class='UserInputCheckErr'>您输入的用户名中有非法字符或用户名长度小于4或大于16，请重新输入，谢谢！</div>";
return false; }

	
 RegXmlHttp=getXMLRequester();
 
//var username=document.getElementById("username").value;
    var username=document.userinfo.username.value
 
//alert("check_id.asp?username="+username);
 
 RegXmlHttp.open("post","check_id.asp?username="+username,true);
 RegXmlHttp.onreadystatechange= RegStateChange;
 
//alert(RegXmlHttp.setRequestHeader("content","100"));
//loginXmlHttp.setRequestHeader("content","100");
 RegXmlHttp.send("content");
}


function RegStateChange()
{
  	if (RegXmlHttp.readyState == 4)
	{
    	document.getElementById("ShowLogin").innerHTML=RegXmlHttp.responseText;
	}
	else
	document.getElementById("ShowLogin").innerHTML="<div class='UserInputCheckTip'>正在验证中，请稍后...</div>";
}




// check space 

function checkspace(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}
function checkuu()
{
   if(checkspace(document.userinfo.username.value)) {
	document.userinfo.username.focus();
	//alert("用户名不能为空，请您重新输入，谢谢^_^!");
   document.getElementById("ShowLogin").innerHTML="<div class='UserInputCheckErr'>用户名不能为空，请重新输入，谢谢！</div>";
	return false;}
	
var str=document.userinfo.username.value;
if(/^[a-zA-Z0-9\u4e00-\u9fa5]{1}([\u4e00-\u9fa5\a-zA-Z0-9]|[_]){2,15}$/.test(str)==false)
{ 
//alert("用户名只能为英文和中文和下划线"); 
document.userinfo.username.focus();
document.getElementById("ShowLogin").innerHTML="<div class='UserInputCheckErr'>您输入的用户名中有非法字符或用户名长度小于4或大于16，请重新输入，谢谢！</div>";
return false; }
//else{
	// document.getElementById("ShowLogin").innerHTML="<div class='UserInputCheckOk'><img src='/images/alert/CheckOk.gif' />&nbsp;该用户名格式正确，赶紧注册吧！</div>";}

//var Ustr=document.userinfo.username.value;
//if(Ustr.length<4 || Ustr.length>20)
//{
//alert("4-20"); 
//document.userinfo.username.focus();
//document.getElementById("ShowLogin").innerHTML="<div class='UserInputCheckErr'><img src='/images/alert/Err.gif' /> &nbsp;用户名长度不能小于4或者大于20，请重新输入，谢谢！</div>";
//return false;}



var Pwdstr=document.userinfo.Pwd.value;
var restr=/^[a-zA-Z0-9\.\!\_\+\-\,\\\/\;\']{6,16}$/;
if(restr.test(Pwdstr)==false)//^[a-zA-Z][\w-]{4,19}$//^(\w){6,20}$/
{
//alert("4-20");
document.userinfo.Pwd.focus();
document.getElementById("ShowPwd").innerHTML="<div class='UserInputCheckErr'>密码只用字母、数字或符号，长度不能小于6或者大于16，请重新输入，谢谢！</div>";
return false;}
  
if(document.userinfo.Pwd.value != document.userinfo.PwdRe.value) {
	//document.userinfo.UserPassword.focus();
	//document.userinfo.UserPassword.value = '';
	//document.userinfo.UserPassword1.value = '';
	document.userinfo.PwdRe.focus();
	document.getElementById("ShowPwdRe").innerHTML="<div class='UserInputCheckErr'>您两次输入的密码不同，请重新输入，谢谢！</div>";
    //alert("很抱歉！您两次输入的密码不同，请重新输入，谢谢^_^!");\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*///^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
	return false;
  }

var Emailstr=document.userinfo.EmailAddress.value;
var Estr=/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
if(Estr.test(Emailstr)==false)
{
document.userinfo.EmailAddress.focus();
document.getElementById("ShowEmail").innerHTML="<div class='UserInputCheckErr'>电子邮件格式不正确,请输入正确的电子邮件地址。正确的例子如：myname@163.com</div>";
return false;}
//var pwd=document.getElementById("Pwd").value.toString();
//var check_pwd=document.getElementById("PwdRe").value.toString();
//if(pwd==check_pwd){
//document.getElementById("ShowPwdRe").innerHTML="<div class='UserInputCheckOk'><img src='/images/alert/CheckOk.gif' /> 密码可以使用</div>";
//else{
//document.getElementById("ShowPwdRe").innerHTML="<div class='UserInputCheckErr'><img src='/images/alert/Err.gif' /> 两次密码不相同</div>";
//return false;}

if(checkspace(document.userinfo.UserQuestion.value)) {
	document.userinfo.UserQuestion.focus();
	//alert("用户名不能为空，请您重新输入，谢谢^_^!");
   document.getElementById("ShowUserQuestion").innerHTML="<div class='UserInputCheckErr'>至少选择一个安全问题，请重新选择，谢谢！</div>";
	return false;}
	else{
	document.getElementById("ShowUserQuestion").innerHTML="<div class='UserInputCheckOk'>已经正确选择安全提示问题！谢谢！</div>";}

if(checkspace(document.userinfo.UserAnswer.value)) {
	document.userinfo.UserAnswer.focus();
   document.getElementById("ShowUserAnswer").innerHTML="<div class='UserInputCheckErr'>答案不能为空，请重新输入，谢谢！</div>";
	return false;}
	else{
	document.getElementById("ShowUserAnswer").innerHTML="<div class='UserInputCheckOk'>安全提示问题输入正确！谢谢</div>";}



var ChkNumStr=document.userinfo.ChkNum.value;
var ChkStr=/^[0-9]{1,5}$/;
//if(ChkStr.test(ChkNumStr)==false)
if(checkspace(document.userinfo.ChkNum.value))
{
document.userinfo.ChkNum.focus();
 document.getElementById("ShowChkNum").innerHTML="<div class='UserInputCheckErr'>验证码不能为空，请重新输入，谢谢！</div>";
return false;}
else{
	document.getElementById("ShowChkNum").innerHTML="<div class='UserInputCheckOk'>验证码格式输入正确！谢谢！</div>";}
}








// JavaScript Document
//密码强度;
function PasswordStrength(showed){	
	this.showed = (typeof(showed) == "boolean")?showed:true;
	this.styles = new Array();	
	this.styles[0] = {backgroundColor:"#EBEBEB",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #BEBEBE",borderBottom:"solid 1px #BEBEBE"};	
	this.styles[1] = {backgroundColor:"#FF4545",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #BB2B2B",borderBottom:"solid 1px #BB2B2B"};
	this.styles[2] = {backgroundColor:"#FFD35E",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #E9AE10",borderBottom:"solid 1px #E9AE10"};
	this.styles[3] = {backgroundColor:"#95EB81",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #3BBC1B",borderBottom:"solid 1px #3BBC1B"};
	
	this.labels= ["一般","很好","极好"];

	this.divName = "Pwd_div_"+Math.ceil(Math.random()*100000);
	this.minLen = 6;
	
	this.width = "160px";
	this.height = "16px";
	
	this.content = "";
	
	this.selectedIndex = 0;
	
	this.init();	
}
PasswordStrength.prototype.init = function(){
	var s = '<table cellpadding="0" id="'+this.divName+'_table" cellspacing="0" style="width:'+this.width+';height:'+this.height+';">';
	s += '<tr>';
	for(var i=0;i<3;i++){
		s += '<td id="'+this.divName+'_td_'+i+'" width="33%" align="center"><span style="font-size:1px">&nbsp;</span><span id="'+this.divName+'_label_'+i+'" style="display:none;font-family: Courier New, Courier, mono;font-size: 12px;color: #000000;">'+this.labels[i]+'</span></td>';
	}	
	s += '</tr>';
	s += '</table>';
	this.content = s;
	if(this.showed){
		document.write(s);
		this.copyToStyle(this.selectedIndex);
	}	
}
PasswordStrength.prototype.copyToObject = function(o1,o2){
	for(var i in o1){
		o2[i] = o1[i];
	}
}
PasswordStrength.prototype.copyToStyle = function(id){
	this.selectedIndex = id;
	for(var i=0;i<3;i++){
		if(i == id-1){
			this.$(this.divName+"_label_"+i).style.display = "inline";
		}else{
			this.$(this.divName+"_label_"+i).style.display = "none";
		}
	}
	for(var i=0;i<id;i++){
		this.copyToObject(this.styles[id],this.$(this.divName+"_td_"+i).style);			
	}
	for(;i<3;i++){
		this.copyToObject(this.styles[0],this.$(this.divName+"_td_"+i).style);
	}
}
PasswordStrength.prototype.$ = function(s){
	return document.getElementById(s);
}
PasswordStrength.prototype.setSize = function(w,h){
	this.width = w;
	this.height = h;
}
PasswordStrength.prototype.setMinLength = function(n){
	if(isNaN(n)){
		return ;
	}
	n = Number(n);
	if(n>1){
		this.minLength = n;
	}
}
PasswordStrength.prototype.setStyles = function(){
	if(arguments.length == 0){
		return ;
	}
	for(var i=0;i<arguments.length && i < 4;i++){
		this.styles[i] = arguments[i];
	}
	this.copyToStyle(this.selectedIndex);
}
PasswordStrength.prototype.write = function(s){
	if(this.showed){
		return ;
	}
	var n = (s == 'string') ? this.$(s) : s;
	if(typeof(n) != "object"){
		return ;
	}
	n.innerHTML = this.content;
	this.copyToStyle(this.selectedIndex);
}
PasswordStrength.prototype.update = function(s){
	if(s.length < this.minLen){
		this.copyToStyle(0);
		return;
	}
	var ls = -1;
	if (s.match(/[a-z]/ig)){
		ls++;
	}
	if (s.match(/[0-9]/ig)){
		ls++;
	}
 	if (s.match(/(.[^a-z0-9])/ig)){
		ls++;
	}
	if (s.length < 6 && ls > 0){
		ls--;
	}
	 switch(ls) { 
		 case 0:
			 this.copyToStyle(1);
			 break;
		 case 1:
			 this.copyToStyle(2);
			 break;
		 case 2:
			 this.copyToStyle(3);
			 break;
		 default:
			 this.copyToStyle(0);
	 }
}
