
function passwordStrength(score)
{
    var shortPass = 'Too Short<br />&nbsp;';
    var weakPass = 'Weak<br />Tip: Use both letters & numbers';
    var goodPass = 'Medium<br />Tip: Use special characters';
    var strongPass = 'Strong<br />&nbsp;';
    var veryStrongPass = 'Very Strong<br />&nbsp;';

    if (score == 0 )  return shortPass;
    
    if (score < 25 )  return weakPass;
    if (score < 75 )  return goodPass;
    if (score < 95 )  return strongPass;
    return veryStrongPass;
}



function passwordStrengthPercent(password)
{
    var score = 0;

    if (password.length < 6 ) { return 0; }

    //password length
    score += password.length * 5;

    //password has 3 numbers
    if (password.match(/(.*[0-9].*[0-9].*[0-9])/))  score += 5;

    //password has 2 sybols
    if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5;

    //password has Upper and Lower chars
    if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  score += 10;

    //password has number and chars
    if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  score += 15;
    //
    //password has number and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/))  score += 15;

    //password has char and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/))  score += 15;

    //password is just a nubers or chars
    if (password.match(/^\w+$/) || password.match(/^\d+$/) )  score -= 10;
    if (score > 100) return 100;
    return (score);

}

function registerPSEvents(inputID)
{
    $('#' + inputID).keyup(function(){
		score = passwordStrengthPercent($('#' + inputID).val());
        $('#psResult').html(passwordStrength(score));
        if (score < 25) {$('#psResult').css('color','red');}
        else if (score < 75) {$('#psResult').css('color','#FF6020');}
        else if (score > 75) {$('#psResult').css('color','green');}
        $('#psColorbar').css("width", parseInt((score / 100) * 180));
        $('#psColorbar').css("background-position", "0px -" + score + "px");
    	$('#psPercent').html(" " + score  + "% ");
		});
}