// JavaScript Document

function checkform(form){
// Email 50
  if(form.Email.value=='')
  {alert("账号不能为空,要填写!");
  form.Email.focus();
  return false;
  }
  if(form.Email.value!=''&&checkemail(form.Email.value))
  {alert("账号输入有错误！");
  form.Email.focus();
  return false;
  }
  if(form.Email.value!=''&&form.Email.value.length>250)
  {alert("账号字数超过了250个！");
  form.Email.focus();
  return false;
  }
// pwd1 50
  if(form.pwd1.value=='')
  {alert("密码不能为空,要填写!");
  form.pwd1.focus();
  return false;
  }
  if(form.pwd1.value!=''&&form.pwd1.value.length>50)
  {alert("您的密码长度超过了50个字符！");
  form.pwd1.focus();
  return false;
  }  
// pwd2 50
  if(form.pwd2.value=='')
  {alert("再次输入密码不能为空,要输入验证密码!");
  form.pwd2.focus();
  return false;
  }
  if(form.pwd2.value!=''&&form.pwd2.value.length>50)
  {alert("您的密码长度超过了50个字符！");
  form.pwd2.focus();
  return false;
  }
  if(!compareStr(form.pwd1.value,form.pwd2.value))
  {alert("您两次输入的密码不一样^_^");
  form.pwd1.focus();
  return false;
  }
  return true;
 }


function checkPwd(pwd){

if (pwd == "") {
$("chkpswd").className = "psdiv0";
$("chkpswdcnt").innerHTML = "";
} else if (pwd.length < 3) {
$("chkpswd").className = "psdiv1";
$("chkpswdcnt").innerHTML = "太短";
} else if(!isPassword(pwd) || !/^[^%&]*$/.test(pwd)) {
$("chkpswd").className = "psdiv0";
$("chkpswdcnt").innerHTML = "";
} else {
var csint = checkStrong(pwd);
switch(csint) {
case 1:
$("chkpswdcnt").innerHTML = "很弱";
$( "chkpswd" ).className = "psdiv"+(csint + 1);
break;
case 2:
$("chkpswdcnt").innerHTML = "一般";
$( "chkpswd" ).className = "psdiv"+(csint + 1);
break;
case 3:		
$("chkpswdcnt").innerHTML = "很强";
$("chkpswd").className = "psdiv"+(csint + 1);
break;
}
}
}

function isPassword(str){
if (str.length < 3) return false;
var len;
var i;
len = 0;
for (i=0;i<str.length;i++){
if (str.charCodeAt(i)>255) return false;
}
return true;
}
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(pwd){ 
modes=0; 
for (i=0;i<pwd.length;i++){ 
//测试每一个字符的类别并统计一共有多少种模式. 
modes|=charMode(pwd.charCodeAt(i)); 
} 
return bitTotal(modes);
}

