
function updateQualityMeter(pw,di){
	var quality = getPasswordStrength(pw);
	setProgressBarValue(quality,di);
}

function setProgressBarValue(quality,di){

	document.getElementById(di).width = (quality*209/100);

}

function getPasswordStrength(pw){

	//length of the password
	var pwlength=(pw.length);
	if (pwlength>5)
		pwlength=5;

	//use of numbers in the password
	var numnumeric = pw.replace (/[0-9]/g, "");
	var numeric=(pw.length - numnumeric.length);
	if (numeric>3)
		numeric=3;

	//use of symbols in the password
	var symbols = pw.replace (/\W/g, "");
	var numsymbols=(pw.length - symbols.length);
	if (numsymbols>3)
		numsymbols=3;

	//use of uppercase in the password
	var numupper = pw.replace (/[A-Z]/g, "");
	var upper=(pw.length - numupper.length);
	if (upper>3)
		upper=3;

	var pwstrength=((pwlength*10)-20) + (numeric*10) + (numsymbols*15) + (upper*10);

	// make sure we're give a value between 0 and 100
	if ( pwstrength < 0 ) {
		pwstrength = 0;
	}

	if ( pwstrength > 100 ) {
		pwstrength = 100;
	}

	return pwstrength;
}
