function NewLogin_Validator(theForm)
{
	if(!Login_Validator(theForm))
	{
		return false;
	}
	
	cur = trim(theForm.password_confirm.value);
	theForm.password_confirm.value = cur; 
	
	if( cur != theForm.password.value )
	{
		alert("Password confirmation failed.\r\nPlease re-enter your password in 'Confirm Password' field ");
		theForm.password_confirm.value = "";
		theForm.password_confirm.focus();
		return (false);   
	}  
	
	return (true);
}

function Login_Validator(theForm)
{
	if (Login_Name_Validator(theForm) == false)
		return (false);
       
	cur = trim(theForm.password.value);
	theForm.password.value = cur; 
	if ( Password_Validator(cur) == false )
	{
		alert("Password must be an alphanumeric value from 6 to 20 characters.");
		theForm.password.value="";
		theForm.password.focus();
		return (false);
	} 
	
	return (true);
}

function Login_Name_Validator(theForm)
{
	cur = trim(theForm.login.value);
	theForm.login.value = cur; 
	len = cur.length;
	if ( !isAlphaNum_And(cur,"_") || len < 6 || len >20 )
	{
		alert("Login name must be an alphanumeric value from 6 to 20 characters.");
		theForm.login.focus();
		return (false);
	} 
	
	return (true);
}   

function Password_Validator(pw)
{
	len = pw.length;
	if ( !isAlphaNum_Only(pw) || len < 6 || len >20 )
		return (false);
	
	return (true);
}   

function Challenge_Validator(theForm)
{  
	if (theForm.challenge_code.value == "0")
	{
		alert("Select challenge phrase in case you will forget your password.");
		theForm.challenge_code.focus();
		return (false);
	}
	   
	cur = trim(theForm.answer.value);
	if (cur.length == 0)
	{
		alert("Enter answer to a challenge phrase.");
		theForm.answer.focus();
		return (false);
	}   
	
	return (true);
}

function Change_Password_Validator(theForm)
{
	cur = trim(theForm.current_password.value);
	theForm.current_password.value = cur; 
	if ( Password_Validator(cur) == false )
	{
		alert("'Current password' must be an alphanumeric value from 6 to 20 characters.");
		theForm.current_password.value = "";
		theForm.current_password.focus();
		return (false);
	}
	
	if (Confirm_Password_Validator(theForm) == false)
		return (false);
	
	return Challenge_All_Validator(theForm);
}

function Confirm_Password_Validator(theForm)
{
	cur = trim(theForm.password.value);
	theForm.password.value = cur; 
	if ( Password_Validator(cur) == false )
	{
		alert("'New password' must be an alphanumeric value from 6 to 20 characters.");
		theForm.password.value = "";
		theForm.password.focus();
		return (false);
	}
	
	cur = trim(theForm.password_confirm.value);
	theForm.password_confirm.value = cur; 
	if (theForm.password_confirm.value != theForm.password.value )
	{
		alert("Password confirmation failed.\r\nPlease re-enter your password in 'Confirm Password' field.");
		theForm.password_confirm.value = "";
		theForm.password_confirm.focus();
		return (false);
	}
	
	return (true);
}

function Challenge_All_Validator(theForm)
{  
	if (theForm.challenge_code1.value == "0")
	{
		alert("Please select a valid entry for Question 1.");
		theForm.challenge_code1.focus();  
		return (false);
	}
	if (isEmpty(theForm.answer1.value))
	{
		alert("Please enter the answer to Question 1.");
		//theForm.answer1.focus();  // *** removed focus because on hidden fields it causes IE errors
		return (false);
	}
	
	if (theForm.challenge_code2.value == "0")
	{
		alert("Please select a valid entry for Question 2.");
		theForm.challenge_code2.focus();  
		return (false);
	}
	if (isEmpty(theForm.answer2.value))
	{
		alert("Please enter the answer to Question 2.");
		//theForm.answer2.focus();  
		return (false);
	}
	
	if (theForm.challenge_code3.value == "0")
	{
		alert("Please select a valid entry for Question 3.");
		theForm.challenge_code3.focus();  
		return (false);
	}
	if (isEmpty(theForm.answer3.value))
	{
		alert("Please enter the answer to Question 3.");
		//theForm.answer3.focus();  
		return (false);
	}
	
	if (theForm.challenge_code4.value == "0")
	{
		alert("Please select a valid entry for Question 4.");
		theForm.challenge_code4.focus();  
		return (false);
	}
	if (isEmpty(theForm.answer4.value))
	{
		alert("Please enter the answer to Question 4.");
		//theForm.answer4.focus();  
		return (false);
	}
	
	if (theForm.challenge_code5.value == "0")
	{
		alert("Please select a valid entry for Question 5.");
		theForm.challenge_code5.focus();  
		return (false);
	}
	if (isEmpty(theForm.answer5.value))
	{
		alert("Please enter the answer to Question 5.");
		//theForm.answer5.focus();  
		return (false);
	}
	
	if (theForm.challenge_code2.value == theForm.challenge_code1.value)
	{
		alert("Please select a unique entry for Question 2.");
		theForm.challenge_code2.focus();  
		return (false);
	}
	if (theForm.challenge_code3.value == theForm.challenge_code1.value || 
		theForm.challenge_code3.value == theForm.challenge_code2.value)
	{
		alert("Please select a unique entry for Question 3.");
		theForm.challenge_code3.focus();  
		return (false);
	}
	if (theForm.challenge_code4.value == theForm.challenge_code1.value || 
		theForm.challenge_code4.value == theForm.challenge_code2.value ||
		theForm.challenge_code4.value == theForm.challenge_code3.value)
	{
		alert("Please select a unique entry for Question 4.");
		theForm.challenge_code4.focus();  
		return (false);
	}
	if (theForm.challenge_code5.value == theForm.challenge_code1.value || 
		theForm.challenge_code5.value == theForm.challenge_code2.value ||
		theForm.challenge_code5.value == theForm.challenge_code3.value ||
		theForm.challenge_code5.value == theForm.challenge_code4.value)
	{
		alert("Please select a unique entry for Question 5.");
		theForm.challenge_code5.focus();  
		return (false);
	}
	
	if (theForm.answer2.value == theForm.answer1.value)
	{
		alert("Please enter a unique answer for Question 2.");
		//theForm.answer2.focus();  
		return (false);
	}
	if (theForm.answer3.value == theForm.answer1.value ||
		theForm.answer3.value == theForm.answer2.value)
	{
		alert("Please enter a unique answer for Question 3.");
		//theForm.answer3.focus();  
		return (false);
	}
	if (theForm.answer4.value == theForm.answer1.value ||
		theForm.answer4.value == theForm.answer2.value ||
		theForm.answer4.value == theForm.answer3.value)
	{
		alert("Please enter a unique answer for Question 4.");
		//theForm.answer4.focus();  
		return (false);
	}
	if (theForm.answer5.value == theForm.answer1.value ||
		theForm.answer5.value == theForm.answer2.value ||
		theForm.answer5.value == theForm.answer3.value ||
		theForm.answer5.value == theForm.answer4.value)
	{
		alert("Please enter a unique answer for Question 5.");
		//theForm.answer5.focus();  
		return (false);
	}
	 
	return (true);
}

