
// OCEAN_PWSTRENGTH.JS version 1.0
// **************************************
// *  Copyright 2010 - Blue C Software  *
// *  All Rights Reserved               *
// **************************************

	ratingMsgs = new Array(6);
	ratingMsgColors = new Array(6);
	barColors = new Array(6);
	
	ratingMsgs[0] = "Too short";
	ratingMsgs[1] = "Weak";
	ratingMsgs[2] = "Fair";
	ratingMsgs[3] = "Good";
	ratingMsgs[4] = "Strong";
	ratingMsgs[5] = "Not rated"; 
	
	ratingMsgColors[0] = "#666666";
	ratingMsgColors[1] = "#800000";
	ratingMsgColors[2] = "#808000";
	ratingMsgColors[3] = "#008080";
	ratingMsgColors[4] = "#008000";
	ratingMsgColors[5] = "#666666";
	
	barColors[0] = "#666666";
	barColors[1] = "#800000";
	barColors[2] = "#FFCC00";
	barColors[3] = "#008080";
	barColors[4] = "#008000";
	barColors[5] = "#666666";

	var pwStrength=1;

	function checkPWstrength(where) {
		var whichform = eval("document." + where);
		var xpw = whichform.PASSWORD.value;
			var xpwU = xpw.toUpperCase();
		var xun = whichform.USER_LOGIN.value.toUpperCase();

  		var passwdMatch = document.getElementById('passwdMatch');

		var score = 0;
		pwStrength=1;

		if (xpw.length>5) { score += 25; }
		if (xpw.length>8) { score += 25; }

		var hasNum = 0;
		var hasChr = 0;
		var numList = '0123456789';
		var chrList = '~`!@#$%^&*()_-+={}[]:;"\'<>,.';
		for (var i=0; i<xpw.length; i++) {
			temp = "" + xpw.substring(i, i+1);
			if (numList.indexOf(temp) != "-1") { hasNum=25; }
			if (chrList.indexOf(temp) != "-1") { hasChr=25; }
		}
		score += hasNum;
		score += hasChr;

		if (xpwU.indexOf(xun) != "-1") { score -= 500; }

		if (score>25) { pwStrength=2; }
		if (score>50) { pwStrength=3; }
		if (score>75) { pwStrength=4; }

	      	if (xpw.length > 0) {
			updateBar(pwStrength);
			checkPWmatch(where);
	  	} else {
	  		resetBar();
			checkPWmatch(where);
	  	}

	}



	function checkPWmatch(where) {
		var whichform = eval("document." + where);
		var xpw = whichform.PASSWORD.value;
			var xpwU = xpw.toUpperCase();

		var xpw2 = whichform.PASSWORD2.value;

		var xun = whichform.USER_LOGIN.value.toUpperCase();



		var matchRating=0;
		var matchMessage='';

		if (xpwU.indexOf(xun) != "-1") { 
    			matchMessage += "Login Name Detected! - ";
		}



		if (xpw==xpw2) {
			document.getElementById('PW2').style.backgroundColor='#AAFFAA';
			matchRating=4;
			matchMessage +='Matched';
		} else {
			document.getElementById('PW2').style.backgroundColor='#FFAAAA';
			matchRating=1;
			matchMessage +='Not Matched';
		}

		if (xpw.length<1) {
			matchRating=0;
			matchMessage ='';
		}

  		var passwdMatch = document.getElementById('passwdMatch');
    		passwdMatch.innerHTML = "<font color='" + ratingMsgColors[matchRating] + "'>" + matchMessage + "</font>";

	}



	function updateBar(rating) {
		var posbar = document.getElementById('posBar');
		var negbar = document.getElementById('negBar');
  		var passwdRating = document.getElementById('passwdRating');
		var barLength = 100;
		var pWidth = 0;
		var nWidth = 0
		if (rating >= 0 && rating <= 4) {  
			pWidth = barLength / 4 * rating;
			nWidth = barLength / 4 * (4 - rating);
		} else {
			pWidth = 0;
			nWidth = barLength;
			rating = 5; 
		}

		posbar.style.width = pWidth + 'px';
		negbar.style.width = nWidth + 'px';

		posbar.style.background = barColors[rating];
    		passwdRating.innerHTML = "<font color='" + ratingMsgColors[rating] + "'>" + ratingMsgs[rating] + "</font>";

	}

	function resetBar() {
		var posbar = document.getElementById('posBar');
		var negbar = document.getElementById('negBar');
  		var passwdRating = document.getElementById('passwdRating');
		var barLength = 100;
		posbar.style.width = "0px";
		negbar.style.width = barLength + "px";
		passwdRating.innerHTML = "";
	}


