function clear_password()
{
  document.getElementById('password').setAttribute("autocomplete","off");
  document.getElementById('password').value="";
  document.getElementById('c_password').setAttribute("autocomplete","off");
  document.getElementById('c_password').value="";
}

function testPassword(password)
{
var description = new Array();


description[0] = "<table><tr><td><table cellpadding=0 cellspacing=2><tr><td height=8px width=30px bgcolor=#ff0000></td><td height=8px width=120px bgcolor=#E0E0E0></td></tr></table></td><td>   <b>Weakest</b></td></tr></table>";

description[1] = "<table><tr><td><table cellpadding=0 cellspacing=2><tr><td height=8px width=60 bgcolor=#F69142 ></td><td height=8px width=90 bgcolor=#E0E0E0></td></tr></table></td><td>   <b>Weak</b></td></tr></table>";

description[2] = "<table><tr><td><table cellpadding=0 cellspacing=2><tr><td height=8px width=90 bgcolor=#CD661D ></td><td height=8px width=60 bgcolor=#E0E0E0></td></tr></table></td><td>   <b>Medium</b></td></tr></table>";

description[3] = "<table><tr><td><table cellpadding=0 cellspacing=2><tr><td height=8px width=120 bgcolor=#008000></td><td height=8px width=30 bgcolor=tan></td></tr></table></td><td>   <b>Strong</b></td></tr></table>";

description[4] = "<table><tr><td><table><tr><td height=8px width=150 bgcolor=#008000></td></tr></table></td><td>   <b>Strongest</b></td></tr></table>";

description[5] = "<table><tr><td><table><tr><td height=8px width=150 bgcolor=#E0E0E0></td></tr></table></td><td>   <b>Start Typing</b></td></tr></table>";


special_chars = ">!#$%&'()*+,-./:;<=>?@[\]^_`{|}~";
var lowerCaseCount = 0;
var upperCaseCount = 0;
var numberCount = 0;
var specialCharsCount = 0;
var passwordLength = 0; 

lowerCaseArray = password.match(/[a-z]/g);
lowerCaseCount = (lowerCaseArray) ? lowerCaseArray.length : 0;
upperCaseArray = password.match(/[A-Z]/g);
upperCaseCount = (upperCaseArray) ? upperCaseArray.length : 0;
numberArray   = password.match(/[0-9]/g);
numberCount   = (numberArray) ? numberArray.length : 0;
specialCharsArray = password.match(/[>!"#$%&'()*+,-.:;<=>?@[\]^_`{|}~]/gi);
specialCharsCount = (specialCharsArray) ? specialCharsArray.length : 0;
passwordLength = password.length;

if(passwordLength == 1)
{
strength = description[5];
}
else if((lowerCaseCount > 0) && ((upperCaseCount == 0) && (numberCount == 0)))
{
strength = description[0];
}
else if((upperCaseCount > 0) && ((lowerCaseCount == 0) && (numberCount == 0)))
{
strength = description[0];
}
else if((numberCount > 0) && ((upperCaseCount == 0) && (lowerCaseCount == 0)))
{
strength = description[0];
}

else if ((passwordLength < 8) && (((lowerCaseCount >0) && (upperCaseCount > 0)) && (numberCount == 0) ))
{
strength = description[1];
}
else if ((passwordLength < 8) && (((lowerCaseCount >0) && (numberCount > 0)) && (upperCaseCount == 0) ))
{
strength = description[1];
}
else if ((passwordLength < 8) && (((upperCaseCount  > 0 ) && (numberCount > 0)) && (lowerCaseCount == 0)))
{
strength = description[1];
}

else if (((passwordLength > 8) && ((lowerCaseCount >0) && (upperCaseCount > 0) && (numberCount  == 0) )) ||  ((passwordLength >  8) && ((lowerCaseCount >0) && (numberCount > 0) && (upperCaseCount  == 0))) || ((passwordLength > 8) && ((numberCount > 0) && (upperCaseCount >0) && (lowerCaseCount == 0))))
{
strength = description[2];
}

else if (((passwordLength  > 8) && (lowerCaseCount > 0) && (upperCaseCount > 0) && (numberCount > 0)) && (specialCharsCount == 0))
{
strength = description[3];
}
else if ((passwordLength  > 8)  && (upperCaseCount > 0) && (numberCount > 0) && (specialCharsCount > 0))
{

strength = description[4];
}
document.getElementById('password_meter').innerHTML= (strength);
}
