﻿getPasswordStrength = function(passwd) {
	intScore = 0;
	if (passwd.match(/[a-z]/)) // [verified] at least one lower case letter
			{
			intScore = (intScore+1)
			} if (passwd.match(/[A-Z]/)) // [verified] at least one upper case letter
			{
			intScore = (intScore+5)
			} // NUMBERS
			if (passwd.match(/\d+/)) // [verified] at least one number
			{
			intScore = (intScore+5)
			} if (passwd.match(/(\d.*\d.*\d)/)) // [verified] at least three numbers
			{
			intScore = (intScore+5)
			} // SPECIAL CHAR
			if (passwd.match(/[!,@#$%^&*?_~]/)) // [verified] at least one special character
			{
			intScore = (intScore+5)
			} if (passwd.match(/([!,@#$%^&*?_~].*[!,@#$%^&*?_~])/)) // [verified] at least two special characters
			{
			intScore = (intScore+5)
			} // COMBOS
			if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/)) // [verified] both upper and lower case
			{
			intScore = (intScore+2)
			} if (passwd.match(/\d/) && passwd.match(/\D/)) // [verified] both letters and numbers
			{
			intScore = (intScore+2)
			} // [Verified] Upper Letters, Lower Letters, numbers and special characters
			if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/) && passwd.match(/\d/) && passwd.match(/[!,@#$%^&*?_~]/))
			{
			intScore = (intScore+2)
			}
			return intScore;
}

toggleSecurityQuestion = function(cmb) {
    if (cmb.value == 1) {
        $('trSecurityQuestion').setStyle({'display': ''});
    } else {
        $('trSecurityQuestion').setStyle({'display': 'none'});
    }
}

checkPassword = function(pwd, board) {
    var password = pwd.value;
    var pwdStrength = getPasswordStrength(password);
    
    if (pwdStrength < 10) {
        board.update('ضعيف').setStyle({color: 'red'});
    } else if (pwdStrength < 14) {
        board.update('متوسط').setStyle({color: 'orange'});
    } else {
        board.update('قوي').setStyle({color: 'green'});
    }
}

checkConPassword = function(pwd, conPwd, board) {
    var conPassword = conPwd.value;
    var password = pwd.value;
    
    if (conPassword != password) {
        board.update('تكرار كلمه عبور نادرست است!').setStyle({color: 'red'});
    } else {
        board.update('');
    }
}
