﻿function blankArray(n) {

for (var i=0; i < n; i++)

this[i] = null;

this.length = n;

}
function getObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId);
	} else if (document.all && document.all(objectId)) {
		return document.all(objectId);
	} else if (document.layers && document.layers[objectId]) {
		return document.layers[objectId];
	} else {
		return false;
	}
}

var myArray = new blankArray(4);


function callServer(pd) {
  if (pd=="true"){
	  DivVis('test1','false','#009900','恭喜！用户名可以注册');
	  myArray[0]=pd;
	  return true;
  }else if(pd=="false"){
	  DivVis('test1','false','#FF3300','用户名以存在！');
	  myArray[0]=pd;	  
	  return false;
  }
 var u_name = document.getElementById("txtUserID").value;
 if(checkspace(u_name))
	{
	DivVis('test1','false','#FF3300','请输入6位以上用户名！');
	 myArray[0]="false";
	   return false;
    }
    if(checkspace(u_name) || u_name.length < 6)
	{
	   DivVis('test1','false','#FF3300','用户名长度不能小于6');
	   myArray[0]="false";
	   return false;
    }
  else
  {
		
        var url = '/Assistant/ajaxRegisterArray.aspx'; 
        var strParams = 'name=' + u_name + "&pd=" + "username";
		  
        var loader1 = new net.ContentLoader(url,FillDropDown,null,"POST",strParams); 	
		DivVis('test1','false','#FF3300','LOADING...');
 }
}

  function FillDropDown(){
  
	var xmlDoc = this.req.responseXML.documentElement;              

	var xSel = xmlDoc.getElementsByTagName('entry')[0];                   
	var strFName = xSel.childNodes[0].firstChild.nodeValue;
	if (strFName=="true"){
		callServer(strFName);
	}else if (strFName=="false"){
		callServer(strFName);
	}                
  }           

function checkspace(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}


function CharMode(iN){
if (iN>=48 && iN <=57)
return 1; 
if (iN>=65 && iN <=90)
return 2;
if (iN>=97 && iN <=122)
return 4;
else
return 8;
}
function bitTotal(num){
modes=0;
for (i=0;i<4;i++){
if (num & 1) modes++;
num>>>=1;
}
return modes;
}
function checkStrong(sPW){
if (sPW.length<=4)
return 0;
Modes=0;
for (i=0;i<sPW.length;i++){
Modes|=CharMode(sPW.charCodeAt(i));
}

return bitTotal(Modes);

} 

function pwStrength(pwd){
O_color="#eeeeee";
L_color="#FF0000";
M_color="#FF9900";
H_color="#33CC00";
O_meas="密码不能小于6位";
L_meas="不安全";
M_meas="一般";
H_meas="极佳";
if (pwd==null||pwd==''){
Lcolor=Mcolor=Hcolor=O_color;
LMeascolor=L_color;
infops.innerHTML=O_meas;
} 
else{
S_level=checkStrong(pwd);
switch(S_level) {
case 0:
Lcolor=Mcolor=Hcolor=O_color;
LMeascolor=L_color;
infops.innerHTML=O_meas;
case 1:
Lcolor=L_color;
Mcolor=Hcolor=O_color;
LMeascolor=L_color;
infops.innerHTML=L_meas;
break;
case 2:
Lcolor=Mcolor=M_color;
Hcolor=O_color;
LMeascolor=M_color;
infops.innerHTML=M_meas;
break;
default:
Lcolor=Mcolor=Hcolor=H_color;
LMeascolor=H_color;
infops.innerHTML=H_meas;
}
} 
document.getElementById("strength_L").style.background=Lcolor;
document.getElementById("strength_M").style.background=Mcolor;
document.getElementById("strength_H").style.background=Hcolor;
document.getElementById("infops").style.color=LMeascolor;
return;
}
function callPas()
{
var FristPsw = document.getElementById("txtPWord").value;
var LastPsw = document.getElementById("txtPwCheck").value;
if(FristPsw!="" || LastPsw!=""){
	if(FristPsw!=LastPsw){
			DivVis('pswtest1','false','#FF3300','两次输入不一致！');
			return false;
		}
		else
		{
			DivVis('pswtest1','false','#009900','正确！两次的输入一致');
			return true;
		}
	}
	else
	{
   		    DivVis('pswtest1','false','#FF3300','请输入密码！');
			return false;

		}
}

/*用于 提示信息的显示、色、, DivID为ID,TorF为真假，BakColor为颜色，txtmes为提示信息  @2007-3-29 by Jiew*/
function DivVis(DivID,TorF,BakColor,txtmes){
	getObject(DivID).style.display="";
	if (TorF=="true"){
		getObject(DivID).style.background=BakColor;
		getObject(DivID).innerHTML=txtmes;
	}
	else if(TorF=="false"){
		getObject(DivID).style.background=BakColor;
		getObject(DivID).innerHTML=txtmes;		
	}
}
function callEmail(pd)
{
	var userEml = document.getElementById("txtEmail").value;
	  if (pd=="true"){
		  DivVis('emailtest1',pd,'#009900','Email可以使用');
		  myArray[1]=pd;
	      return true;
  	  }else if(pd=="false"){
	 DivVis('emailtest1',pd,'#FF3300','邮箱以经存在！');
	  myArray[1]=pd;
	  return false;
      }

if(userEml!=0)
  {
    if (userEml.charAt(0)=="." || userEml.charAt(0)=="@"|| userEml.indexOf('@', 0) == -1 || userEml.indexOf('.', 0) == -1 || userEml.lastIndexOf("@")==userEml.length-1 || userEml.lastIndexOf(".")==userEml.length-1)
     {
	  DivVis('emailtest1','false','#FF3300','格式不正确！');
	  myArray[1]="false";
	   return false;
      }
	  else
	  {
		var url = '/Assistant/ajaxRegisterArray.aspx';
        var strParams = 'name=' + userEml + "&pd=" + "email";
        var loader1 = new net.ContentLoader(url,FillDropDown_Email,null,"POST",strParams); 
		DivVis('emailtest1','false','#FF3300','Logining...');
	  }
   }
 else
  {
	DivVis('emailtest1','false','#FF3300','Email不能为空！');

   return false;
   }
}
  function FillDropDown_Email(){
  
	var xmlDoc = this.req.responseXML.documentElement;              
	var xSel = xmlDoc.getElementsByTagName('entry')[0];                   
	var strFName = xSel.childNodes[0].firstChild.nodeValue;
	if (strFName=="true"){
		callEmail(strFName);
	}else{
		callEmail(strFName);
	}                
  }    
  
  /*身份证判断*/
function checkIdcard(){
	var Errors=new Array("验证通过!","身份证号码位数不对!请重新输入","身份证号码出生日期超出范围或含有非法字符!请重新输入","身份证号码校验错误!请重新输入","身份证地区非法!请重新输入");
	var area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}
	var idcard = document.getElementById("txtIdNum").value;
	var Y,JYM;
	var S,M;
	var idcard_array = new Array();
	idcard_array = idcard.split("");
	if(area[parseInt(idcard.substr(0,2))]==null) return sfztest1.innerHTML=Errors[4];
	switch(idcard.length){
		case 15:
			if ((parseInt(idcard.substr(6,2))+1900) % 4 == 0 || ((parseInt(idcard.substr(6,2))+1900) % 100 == 0 && (parseInt(idcard.substr(6,2))+1900) % 4 == 0 )){
				ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;
			}
			else{
				ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;
			}
			if(ereg.test(idcard))
				return sfztest1.innerHTML= Errors[0];
			else
				return  sfztest1.innerHTML= Errors[2];
		break;
	case 18:
		if ( parseInt(idcard.substr(6,4)) % 4 == 0 || (parseInt(idcard.substr(6,4)) % 100 == 0 && parseInt(idcard.substr(6,4))%4 == 0 )){
			ereg = /^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;
		}
		else{
		ereg = /^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;
		}
		if(ereg.test(idcard)){
			S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7 + (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9 + (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10 + (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5 + (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8 + (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4 + (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2 + parseInt(idcard_array[7]) * 1 + parseInt(idcard_array[8]) * 6 + parseInt(idcard_array[9]) * 3 ;
			Y = S % 11;
			M = "F";
			JYM = "10X98765432";
			M = JYM.substr(Y,1);
			if(M == idcard_array[17])
				return  sfztest1.innerHTML= Errors[0];
			else
				return  sfztest1.innerHTML= Errors[3];
		}
		else
			return  sfztest1.innerHTML= Errors[2];
		break;
	default:
		return  sfztest1.innerHTML= Errors[1];
		break;
	}
}

function btton()
{
	if (myArray[0]=="false"||document.getElementById("txtUserID").value=="")
	{
		 document.getElementById("txtUserID").focus();
		 document.execCommand('Stop');
		 return false;

		}
	if (callPas()==false)
	{
		document.getElementById("txtPWord").focus();
		document.execCommand('Stop');
		 return false;
		}
	if (myArray[1]=="false"||document.getElementById("txtEmail")=="value")
	{
		document.getElementById("txtEmail").focus();
		document.execCommand('Stop');
		 return false;
		}
				return true;

		
	}
