function _PwStrengthResult(val, text, color)
{
	var res = new Array(3);
	res[0] = val;
	res[1] = text;
	res[2] = color;
	return res;
}

var pwMinLength = 5;
var pwMaxLength = 15;
var pwLengthWeight = 10;	// [0 - ...]
var pwNumericWeight = 10;	// [0 - 3]
var pwSymbolsWeight = 15;	// [0 - 3]
var pwUpperWeight = 10;		// [0 - 3]

function getPasswordStrength(pw)
{
    // Here is how we weigh the quality of the password
    // number of characters
    // numbers
    // non-alpha-numeric chars
    // upper and lower case characters

    // length of the password
    var pwlength = (pw.length);
    if(pwlength < pwMinLength)
        return _PwStrengthResult(0, "short", "#BB0000");
    if(pwlength > pwMaxLength)
        return _PwStrengthResult(0, "long", "#BB0000");
        
	var lenweight = pwLengthWeight * (pwlength - pwMinLength + 2);

    // use of numbers in the password
    var pw_numeric = pw.replace (/[0-9]/g, "");
    var numeric = pwNumericWeight * Math.min(pw.length - pw_numeric.length, 3);

    // use of symbols in the password
    var pw_symbols = pw.replace (/\W/g, "");
    var symbols = pwSymbolsWeight * Math.min(pw.length - pw_symbols.length, 3);

    // use of uppercase in the password
    var pw_upper = pw.replace (/[A-Z]/g, "");
    var upper = pwUpperWeight * Math.min(pw.length - pw_upper.length, 3);

    var pwstrength = lenweight + numeric + symbols + upper;

    // make sure we give a value between 0 and 100
	pwstrength = Math.min(100, Math.max(pwstrength, 0));
	
	if(pwstrength < 40)
		return _PwStrengthResult(pwstrength, "weak", "#BB0000");
	if(pwstrength < 75)
		return _PwStrengthResult(pwstrength, "fair", "#A8A800");
	if(pwstrength < 100)
		return _PwStrengthResult(pwstrength, "good", "#0000BB");

	return _PwStrengthResult(pwstrength, "strong", "#0000BB");
}
