function checkPassword(strPassword) {
	var score = 0;
	
	if (strPassword.length == 0)
		return 0;
	
	// Length
	score += strPassword.length / 3;	

	// Capital Letter
	if (strPassword.search(/[A-Z]/) != -1) {
		score++;
	}

	// Lowercase Letter
	if (strPassword.search(/[a-z]/) != -1) {
		score++;
	}

	// Number
	if (strPassword.search(/[0-9]/) != -1) {
		score++;
	}

	// Special character
	if (strPassword.search(/[^A-Za-z0-9]/) != -1) {
		score++;
	}
	
	return (score-1) / 5;
}

// Runs password through check and then updates GUI 
function runPassword(strPassword, strFieldID) 
{
	// Check password
	nPerc = checkPassword(strPassword);
	
	 // Get controls
   	var ctlBar = document.getElementById(strFieldID + "_bar"); 
   	var ctlText = document.getElementById(strFieldID + "_text");
   	if (!ctlBar || !ctlText)
   		return;
    	
   	// Set new width
   	var nRound = Math.round(nPerc * 100);
	if (nRound < (strPassword.length * 5)) 
	{ 
		nRound += strPassword.length * 5; 
	}
	if (nRound > 100) nRound = 100;
	ctlBar.style.width = nRound + "%";
 
 	// Color and text
 	if (nRound >= 80)
 	{
 		strText = "Very Secure";
 		strColor = "#3bce08";
 	}
 	else if (nRound >= 60)
 	{
 		strText = "Secure";
 		strColor = "orange";
	}
 	else if (nRound >= 40)
 	{
 		strText = "Mediocre";
 		strColor = "#ffd801";
 	}
 	else
 	{
 		strColor = "red";
 		strText = "Insecure";
 	}
	ctlBar.style.backgroundColor = strColor;
	ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + "</span>";
}
 
