//check for the validity of the password
function isPassVaild(currPass, newPass, confirmPass)
{
	var isValid = false;
	//check old password	
	//Changed by Gayatri Yadav on 30-Sept-2010 [ WI01SUN006 ] [ To implement SHA-256 while login ]
	//if ( (currPass == currPwd))
	if ( (currPass == currPwd)  || (currPwd == sha256_digest(currPass)) )
	{
		if (newPass == confirmPass)
		{
			if (newPass.toLowerCase().indexOf("password") == -1)
			{
				//check the length of the new password
				if(newPass.length < minPwdLen )
				{
					//added by Kiran G for Russian SErver
					//alert("Minimum password length is "+minPwdLen+" characters !");
					var minPasswdLen = "Minimum password length is".toLocaleString();
					var characters = "characters !".toLocaleString();
					alert(minPasswdLen+" "+minPwdLen+" "+characters);
					
				}
				else
				{
					if (checkContents(newPass))
					{
						var toBeChecked = (trim(fname.toLowerCase())== "")?true:false;
						//check whether name is used in the password or not
						if (toBeChecked || newPass.toLowerCase().indexOf(trim(fname.toLowerCase())) == -1 )
						{
							toBeChecked = (trim(mname.toLowerCase())== "")?true:false;
							if (toBeChecked || newPass.toLowerCase().indexOf(trim(mname.toLowerCase())) == -1)
							{
								toBeChecked = (trim(lname.toLowerCase())== "")?true:false;
								if (toBeChecked || newPass.toLowerCase().indexOf(trim(lname.toLowerCase())) == -1)
								{
									if(newPass.toLowerCase().indexOf(trim(empCode.toLowerCase())) == -1)
									{
										if (currPass == newPass)
										{
										    //alert("New Password and Old Password are same, choose different password");
											//added by Kiran G for Russian Server
											var passwdSame= "New Password and Old Password are same, choose different password".toLocaleString();
											alert(passwdSame);
										}
										else
										{
											isValid = true;
										}
									}
									else
									{
									    //alert("Employee code cannot be used in the password");
									    //added by Kiran G for Russian Server
										var empCodePasswd = "Employee code cannot be used in the password".toLocaleString();
										alert(empCodePasswd);
									}
								}
								else
								{
									//alert("Last Name cannot be used as password, select another password");
									//added by Kiran G for Russian Server
									var lastNamePasswd="Last Name cannot be used as password, select another password".toLocaleString();
									alert(lastNamePasswd);
								}
							}
							else
							{
								//alert("Middle Name cannot be used as password, select another password");
								//added by Kiran G for Russian Server
								var middleNamePasswd="Middle Name cannot be used as password, select another password".toLocaleString();
								alert(middleNamePasswd);
							}
						}
						else
						{
							//alert("First Name cannot be used as password, select another password");
							//added by Kiran G for Russian Server
							var firstNamePasswd="First Name cannot be used as password, select another password";
							alert(firstNamePasswd.toLocaleString());
						}
					}
					else
					{
						//alert("Password must contains atleast one Uppercase character, Lowercase character and a Digit !");
						//added by Kiran G for Russian Server
						var passwdContains="Password must contains atleast one Uppercase character, Lowercase character and a Digit !".toLocaleString();
						alert(passwdContains);
					}
				}		
			}
			else
			{
				//alert("The word password cannot be used as password, select another password");
				//added by Kiran G for Russian Server
				var passwd="The word password cannot be used as password, select another password".toLocaleString();
				alert(passwd);
				
			}
		}
		else
		{
			//alert("New Password and Confirm Password do not match");
			//added by Kiran G for Russian Server
			var passwdNotMatch="New Password and Confirm Password do not match".toLocaleString();
			alert(passwdNotMatch);
		}
	}
	else
	{
		/*alert("Old password is incorrect !");*/
		//added by Kiran G for Russian Server
		var oldPasswdInCorrect= "OldPasswordisincorrect!";
		alert(oldPasswdInCorrect.toLocaleString());
	}	
	
	return isValid;
}

//password must contain atleast one uppercase character, a lowercase charater and a digit
function checkContents(newPass)
{
	var isUpperCase = false;
	var isLowerCase = false;
	var isDigit = false;
	for(var cnt=0; cnt<newPass.length; cnt++)
	{
		var letter = newPass.charAt(cnt);
		if (!isUpperCase && letter >= 'A' && letter <='Z')
		{
			isUpperCase = true;
		}
		else if (!isLowerCase && letter >= 'a' && letter <= 'z')
		{
			isLowerCase = true;
		}
		else if (!isDigit && letter >= 0 && letter <= 9)
		{
			isDigit = true;
		}
	}
	if (isUpperCase && isLowerCase && isDigit)
		return true;
	else
		return false;
}

function ltrim(s)
{
	return s.replace( /^\s*/, "" );
}

function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}
function trim ( s )
{
	return rtrim(ltrim(s));
}
