// Password strength;
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 = ["weak", "medium", "strong"];
This. divName = "pwd_div _" + Math. ceil (Math. random () * 100000 );
This. minLen = 5;
This. width = "150px ";
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 );
}
}