/*
 * function ValidateForm
 *
 * This function is called by the contact us popup.  The form is passed in by 
 * reference.  The fields to be validated are hard coded in this function with 
 * generic functions being used to perform the validation.
 *
 * Return values: 
 *	True: the form is valid.  Focus is passed back to the page where the form action is executed.   
 *  False: the form is not valid.  A javascript error message is called with focus of the form set
 *		to the error field.  False prevents the form action from being executed.
 */
function ValidateForm(form)
{
   var sName = form.name.value;
   var sPhone = form.phone.value;
   var sEmail = form.email.value;
   var sComments = form.comments.value;
   
      /* The name input box */ 
    if(IsEmpty(sName))
   {
      alert('Please enter a valid name.');
      form.name.focus(); 
      return false; 
   }
    if(IsScriptBlock(sName))
   {
      alert('Please remove all "greater than" and "less than" characters from your name.');
      form.name.focus(); 
      return false; 
   }
   
   /* The phone input box */ 
    if(IsScriptBlock(sPhone))
   {
      alert('Please remove all "greater than" and "less than" characters from your phone.');
      form.phone.focus(); 
      return false; 
   }
   
   /* The email input box */ 
    if(! IsValidEmail(sEmail))
   {
      alert('Please enter a valid email address.');
      form.email.focus(); 
      return false; 
   }
    if(IsScriptBlock(sEmail))
   {
      alert('Please remove all "greater than" and "less than" characters from your email.');
      form.email.focus(); 
      return false; 
   }      
   
   /* The comments text area box */
   if(IsEmpty(sComments)) 
   { 
      alert('Please enter an inquiry or comment.');
      form.comments.focus(); 
      return false; 
   }
    if(IsScriptBlock(sComments))
   {
      alert('Please remove all "greater than" and "less than" characters from your comments.');
      form.comments.focus(); 
      return false; 
   } 
return true;
} 
/*
 * function IsEmpty
 *
 * Generic function used to test for the presence of any text in a string
 *
 * Return values:
 *	True: The string is empty or null.
 *	False: The string has some value.
 *
 */
function IsEmpty(aTextField) {
   if ((aTextField.length==0)||(aTextField==null)) {
		return true;
	}
	else { 
		return false; 
	}
}
/*
 * function IsValidEmail
 *
 * Used to test for a valid email address.  This function tests for the presence
 * of a dot "." in the string as at least the third character or the at symbol "@"
 * as at least the second character.
 *
 * Return values:
 *	True: The string is a valid email.
 *	False: The string is not valid.
 *
 */
function IsValidEmail(str) {
	if ((str.indexOf(".") > 2) && (str.indexOf("@") > 0)){
		return true;
	}
	else {
		return false;
	}
}
/*
 * function IsScriptBlock
 *
 * Used to test for script blocks in open ended input boxes and
 * text area fields.  Script blocks start with a greater than character
 * and end with a less than character.  This function test for the presence
 * of either of these two characters.
 *
 * Return values:
 *	True: A script block was found.
 *	False: A script block was not found.
 *
 */
function IsScriptBlock(str) {
	if ((str.indexOf("<") > -1) || (str.indexOf(">") > -1)){
		return true;
	}
	else {
		return false;
	}
}