﻿/**************************************************************
 * <p>网站JavaScript Document</p>
 *  @Author:Summer-1900
 *  @Desc: 密码强度检测
 **************************************************************/

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;
}

// @param sPW 密码字符串
function checkStrong(sPW){
	if (sPW.length<6)
		return 0;  //密码太短
	Modes=0;
	for (i=0;i<sPW.length;i++){
		Modes|=CharMode(sPW.charCodeAt(i));
	}

	return bitTotal(Modes);
	
}	

function pwStrength(pwd){
	LeastMsg = "至少输入 6 位以上密码 &nbsp;";
	if (pwd==null||pwd==''){
		Lcolor="";
		TextMsg = LeastMsg;
		$("chk_password1").innerHTML = getWidthTipFrame(Lcolor, TextMsg, regMsgLen);
		return;
	}	
	else{
		if (pwd.length>=6) {
		S_level=checkStrong(pwd);
		switch(S_level)	 {
			case 0:
				Lcolor="red";
				TextMsg = LeastMsg;
			case 1:
				Lcolor="red";						
				TextMsg="您的密码很不安全!";
				break;
			case 2:
				Lcolor="blue";					
				TextMsg="您的密码比较安全!";
				break;
			default:	
				Lcolor="right";
				TextMsg="您的密码很安全!";				
				}
		}
		else {
			$("chk_password1").innerHTML = getWidthTipFrame("red", LeastMsg, regMsgLen);
			return;
			}
	 }
	
	$("chk_password1").innerHTML = getWidthTipFrameInPass(Lcolor,  TextMsg, regMsgLen);
	
	return;
}

function getWidthTipFrameInPass(color,msg,allwidth)
{
    var remsg="";
	    if(color=='blue')
        remsg="<table width="+allwidth+" border=0 cellPadding=0  cellSpacing=2 bgcolor='#E2F5FF'  style='BORDER-RIGHT: #00A8FF 1px solid; BORDER-TOP: #00A8FF 1px solid; BORDER-LEFT: #00A8FF 1px solid; BORDER-BOTTOM: #00A8FF 1px solid'><TR><TD width='24' height='20' class=l20><div align='center'><img src='/images/01.gif' width='14' height='14'></div></TD> <TD  class=commonly>"+msg+"</TD> </TR> </TABLE>";
        else if(color=='red')
		remsg="<table width="+allwidth+" border=0 cellPadding=0 cellSpacing=2 bgcolor='#FFF2E9' style='BORDER-RIGHT: #FF6600 1px solid; BORDER-TOP: #FF6600 1px solid; BORDER-LEFT: #FF6600 1px solid; BORDER-BOTTOM: #FF6600 1px solid'><TR><TD width='21' height='20' class=l20><div align='center'><img src='/images/02.gif' width='14' height='14'></div></TD><TD  class='danger'>"+msg+"</TD></TR> </TABLE></body>";
        else if(color=='right')
		remsg="<table width="+allwidth+" border=0 cellPadding=0 cellSpacing=2 bgcolor='#DDF1D8' style='BORDER-RIGHT: #58CB64 1px solid; BORDER-TOP: #58CB64 1px solid; BORDER-LEFT: #58CB64 1px solid; BORDER-BOTTOM: #58CB64 1px solid'><TR><TD width='22' height='20' class=l20><div align='center'><img src='/images/03.gif' width='14' height='14'></div></TD><TD  class=strong>"+msg+"</TD> </TR> </TABLE>";
		else 
		remsg="<span class='r1_2'>"+msg+"</span>";
    return remsg;
}
