
//VALIDATION FUNCTIONS
var validated = false // this will be true only when all fields are positively validated
var errorMsg = ""
var errorCount = 0 // the munber of errors must be 0 before the form can be submitted

/*******************************************************************************
** validate   -  validates the form fields. Removes (trim) any white lines at the
**		 start and end of the form entries before carryong out the rele-
**		vant validations.
** Arguments: 	none
** Called by:   onSubmit
** Returns:     nothing
*******************************************************************************/
function validateForm()
{
  theForm = document.mainform;
  
  errorMsg = ""; // reset

  //remove white lines: DO WE STILL NEED THESE????
  theForm.email.value = trim(theForm.email.value);
  theForm.subject.value = trim(theForm.subject.value);
  theForm.message.value = trim(theForm.message.value);
  //END remove white lines


  if (theForm.message.value == "" || theForm.message.value.length < 1)
      errorMsg += "ERROR: You have not entered any message \n"

  checkEmail();

  if (errorMsg.length > 0)
    alert(errorMsg + "\n PLEASE CORRECT AND RE-SUBMIT THE FORM");
  else
    {
       theForm.action = "mailto:Kurt@tridentsite.org,vernon@tridentsite.org";
       theForm.submit();
    }
}


/*******************************************************************************
** checkEmail   -  Validates the e-mail field. Ensures that it is a valid e-mail
**		   address.
** Arguments: 	The caller (ie form field or actual form)
** Called by:   onChange; validateForm.
** Returns:   nothing  
*******************************************************************************/
function checkEmail()
{
  theForm = document.mainform;
  
  var mailValue = theForm.email.value
  var mailLength = mailValue.length
  
  if (mailValue.indexOf("@")<2 || mailValue.indexOf(".")<0)
      errorMsg += "ERROR: Enter a valid e-mail address.\n"
}




/*******************************************************************************
** trim   -  removes whitespace from both ends of a given string.
** Arguments: string to be trimmed
** Called by: Most of the form fields.
** Returns:   the trimmed string.
*******************************************************************************/
function trim(theString)
{
   srngLen = theString.length;
   
   for (i=0; i<srngLen; i++)
    {
      if (theString.charAt(0)== " ")
       theString = theString.substring(1, theString.length)
      else
       break;
    }

   srngLen = theString.length;
   for (j=srngLen; j>0; j--)
    {
      if (theString.charAt(theString.length-1) == " ")
       theString = theString.substring(0, theString.length-1)
      else
       break;
    }
   return theString
}


