/**
 * Password strength checker
 *
 * simple library for checking password's strength
 * 
 * @author Adam Heinrich <a.heinrich@seznam.cz>
 * @copyright (c) 2008 Adam Heinrich
 * @link http://adamh.cz
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License
 */
 
 /**
  * passwordStrength
  *
  * +1 point for each character over 6 in length
  * +1 point for being mixed case, upper and lower
  * +1 point for including both numbers and letters
  * +1 point for including punctuation
  */
 function passwordStrength(password) {
 	var length = password.length;
 	var points = 0;
 	
 	if (length >= 6) {
 		// +1 point for each character over 6 in length
		points = length-6;
		
		// +1 point for being mixed case, upper and lower
		if (password.match(/[a-z]/) && password.match(/[A-Z]/)) {
			points++;
		}
		
		// +1 point for including both numbers and letters
		if (password.match(/[a-zA-Z]/) && password.match(/[0-9]/)) {
			points++;
		}
		
		// +1 point for including punctuation
		if (password.match(/\W/)) {
			points++;
		}
	}
	
	return points;	
 }
 
 /**
  * checkPassword
  *
  * check password and show message
  */
 function checkPassword(password, showItem, messages) {
 	var item = document.getElementById(showItem);
 	var points = passwordStrength(password);
 	var strength = 0;
 	var color = 'red';
 	
 	if (points == 0) {
 		strength = 0;
 	} else if (points > 0 && points < 3) {
 		strength = 1;
 	} else if (points >= 3 && points < 5) {
 		strength = 2;
 		color = 'orange';
 	} else if (points >= 5) {
 		strength = 3;
 		color = 'green';
 	}  
 	
 	item.style.color = color;
 	item.innerHTML = messages[strength];
 }
