/**
* strongPass.js
*
* This script provides a rudimentary check of the
* strength of a password. It is not able to check
* the password against a dictionary to prevent users
* from using common words or phrases, but it does
* check that the password contains upper- and lower-
* case letters, numerals, and symbols. For an 
* example, check out:
*    http://projects.jamessocol.com/scripts/javascript/strongPass.js.htm
*
* LICENSE: This product is freeware. Please feel 
* free to use, modify and distribute, and to learn
* from it. If you use it on your site, please leave
* me some credit, like "By..." if you use it as-is
* or "Based on..." if you modify it. Thanks!
*
* USAGE: To implement this script, simply create some
* <DIV> with a fixed width (in pixels) or a table cell
* and give it the following ID attribute:
*    id="passStrength"
* for example:
*    <td id="passStrength">
* Make sure no other elements of the page use this ID.
* Then add the following attribute to your password field:
*    onKeyUp="strongPass(this);"
* for example:
*    <input type="password" onKeyUp="strongPass(this)">
* Finally, add the following to the <HEAD> section of 
* your page:
*    <script language="javascript" src="strongPass.js"
*      type="text/javascript"></script>
* Then you're done!
* 
* @package	turnThePage
* @author	James Socol <me@jamessocol.com>
* @version	1.0
* @date		20 July 2006
*/

function strongPass (input)
{
	var text   = new Array('<div style="width:', '%; background:#00c; color:#fff; font-weight:bold; font-size:100%; font-family:Tahoma">', '</div>');
	var weak   = new Array('100', 'Password Inseguro!');
	var ok     = new Array('100', 'Password Perfecto');
	var strong = new Array('100', 'Password Fuerte Perfecto');
	var very   = new Array('100', 'Password Muy Fuerte Perfecto');
	var error  = '<div style="width:100%; background:#c00; color:#fff; font-weight:bold; font-size:65%; font-family:Tahoma">Error</div>';
	var password = input.value;
	var strength = 0;

	if (password.match(/[a-z]/)) { strength = strength + 10; }
	if (password.match(/[A-Z]/)) { strength = strength + 10; }
	if (password.match(/[0-9]/)) { strength = strength + 10; }
	if (password.match(/[^a-zA-Z0-9]/)) { strength = strength + 10; }
	if (password.length >= 7) { strength = strength + 5; }
	if (password.length >= 8) { strength = strength + 5; }
	if (password.length >= 14) { strength = strength + 10; }
	if (strength <= 30) {
		text = text[0] + weak[0] + text[1] + weak[1] + text[2];
	} else if (strength <= 40) {
		text = text[0] + ok[0] + text[1] + ok[1] + text[2];
	} else if (strength <= 50) {
		text = text[0] + strong[0] + text[1] + strong[1] + text[2];
	} else if (strength <= 60) {
		text = text[0] + very[0] + text[1] + very[1] + text[2];
	} else {
		text = error;
	}
	if (document.getElementById) {
		id = document.getElementById('passStrength');
		id.innerHTML = '';
		id.innerHTML = text;
	} else if (document.all) {
		id = document.all('passStrength');
		id.innerHTML = text;
	}
}
