var m_strUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var m_strLowerCase = "abcdefghijklmnopqrstuvwxyz";
var m_strNumber = "0123456789";
var m_strCharacters = "!@#$%^&*?_~"

	
function runPassword(strPassword, strFieldID){
	var nScore = checkPassword(strPassword);
 	var ctlBar = document.getElementById(strFieldID + "_bar"); 
 	var ctlText = document.getElementById(strFieldID + "_text");

 	if (!ctlBar || !ctlText)
 		return;
 	
 	ctlBar.style.width = nScore + "%";

	if (nScore >= 90){
		var strText = "Muy Segura";
		var strColor = "#16166B";
	}
	else if (nScore >= 80){
		var strText = "Segura";
		vstrColor = "#5A84AF";
	}
	else if (nScore >= 70){
		var strText = "Muy Fuerte";
		var strColor = "#6EC343";
	}
	else if (nScore >= 60){
		var strText = "Fuerte";
		var strColor = "#5a74e3";
	}
	else if (nScore >= 50){
		var strText = "Aceptable";
		var strColor = "#82D72D";//"#e3cb00";
	}
	else if (nScore >= 25){
		var strText = "D&eacute;bil";
		var strColor = "#EBC016";
	}
	else{
		var strText = "Muy D&eacute;bil";
		var strColor = "#e71a1a";
	}
	ctlBar.style.backgroundColor = strColor;
	//ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + " - " + nScore + "</span>";
	ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + "</span>";
}

function countContain(strPassword, strCheck){ 
	var nCount = 0;
	
	for (i = 0; i < strPassword.length; i++){
		if (strCheck.indexOf(strPassword.charAt(i)) > -1){ 
	        	nCount++;
		} 
	} 

	return nCount; 
} 

function checkPassword(strPassword){
	var nScore = 0;
	
	if (strPassword.length <= 5)	{
		nScore += 1;
	}
	else if (strPassword.length >= 6 && strPassword.length <= 7){
		nScore += 10;
	}
	else if (strPassword.length >= 8){
		nScore += 30;
	}

	var nUpperCount = countContain(strPassword, m_strUpperCase);
	var nLowerCount = countContain(strPassword, m_strLowerCase);
	var nLowerUpperCount = nUpperCount + nLowerCount;

	if (nUpperCount == 0 && nLowerCount != 0){ 
		nScore += 10; 
	}
	else if (nUpperCount != 0 && nLowerCount != 0){ 
		nScore += 20; 
	}
	
	var nNumberCount = countContain(strPassword, m_strNumber);

	if (nNumberCount == 1){
		nScore += 10;
	}

	if (nNumberCount >= 3){
		nScore += 20;
	}
	
	var nCharacterCount = countContain(strPassword, m_strCharacters);

	if (nCharacterCount == 1){
		nScore += 10;
	}	

	if (nCharacterCount > 1){
		nScore += 25;
	}
	
	if (nNumberCount != 0 && nLowerUpperCount != 0)	{
		nScore += 2;
	}

	if (nNumberCount != 0 && nLowerUpperCount != 0 && nCharacterCount != 0)	{
		nScore += 3;
	}

	if (nNumberCount != 0 && nUpperCount != 0 && nLowerCount != 0 && nCharacterCount != 0)	{
		nScore += 5;
	}
	return nScore;
}
