// Runs password through check and then updates GUI 
function runPassword(strPassword, strFieldID) 
{
	// Check password
	var nRound = checkPass(strPassword);

	 // Get controls
    	var ctlBar = document.getElementById(strFieldID + "_bar"); 
    	if (!ctlBar)
 			return;
    	// Set new width

	if (nRound > 100)
		nRound = 100;
    	ctlBar.style.width = nRound + "%";

 	// Color and text
 	if (nRound >= 90)
 	{
 		strColor = "#3bce08";
 	}
 	else if (nRound >= 70)
 	{
 		strColor = "orange";
	}
 	else if (nRound >= 50)
 	{
 		strColor = "#ffd801";
 	}
 	else
 	{
		strColor = "red";
 	}
	ctlBar.style.backgroundColor = strColor;
}

function checkPass(password) {
	var score = 0;
	var pwdleng = password.length;
	var check = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var check_leng = check.length;

	if (pwdleng < 8) {
		score = 0;
	} else {
		if (password.match(/[0-9]/)) {
			score += 10;
		}
		if (password.match(/[a-z]/)) {
			score += 15;
		}
		if (password.match(/[A-Z]/)) {
			score += 15;
		}
		if (password.match(/[a-z0-9]/) || password.match(/[A-Z0-9]/) || password.match(/[a-zA-Z]/)) {
			score += 15;
		}
		if (password.match(/[a-zA-Z0-9]/)) {
		    score += 20;
		}
		score += Math.pow(pwdleng, 2) / 3;
	}
	for (var i=0; i<check_leng; i++) {
		var str = check.charAt(i);
		var re =  new RegExp(str+str+str);
		if (password.match(re)) {
			score -= 75;
		}
	}
//document.write(score);
	return score;
}
 

