function checkContactUsForm(ThisForm)
{
  if (!validValue(ThisForm.Name.value))
  {
    alert("Enter your name.");
    ThisForm.Name.focus();
    ThisForm.Name.select();
    return false;
  }
  if (!validEmail(ThisForm.emailAddr.value))
  {
    alert("Enter a valid email address.");
    ThisForm.emailAddr.focus();
    ThisForm.emailAddr.select();
    return false;
  }
  if (!validValue(ThisForm.vcomments.value))
  {
    alert("Enter a text message.");
    ThisForm.vcomments.focus();
    ThisForm.vcomments.select();
    return false;
  }
}



function validValue(pass)
{
  if (pass.length == 0 || trim(pass) == "")
  {
    return false;
  }
  return true;
}



function trim(str)
{ 
    if (str != null)
    {
        var i; 
        for (i=0; i<str.length; i++)
        {
            if (str.charAt(i)!=" ")
            {
                str=str.substring(i,str.length); 
                break;
            } 
        } 
    
        for (i=str.length-1; i>=0; i--)
        {
            if (str.charAt(i)!=" ")
            {
                str=str.substring(0,i+1); 
                break;
            } 
        } 
        
        if (str.charAt(0)==" ")
        {
            return ""; 
        } else {
            return str; 
        }
    }
}



function validEmail(email)
{
  invalidChars = "/:,;";  // declare invalid characters
  
  if (email == "")
  {
    return false;
  }
  for (i=0; i<invalidChars.length; i++)  // email contains an invalid character (as specified in invalidChars)
  {
    badChar = invalidChars.charAt(i);
    if (email.indexOf(badChar,0) > -1){
    return false;
    }
  }
  atPos = email.indexOf("@",1);  		// email does not contain @ sign
  if (atPos == -1){
    return false;
  }
  if (email.indexOf("@",atPos+1) != -1){ //  email starts with at sign
    return false;
  }
  periodPos = email.indexOf(".", atPos)
  if (periodPos == -1){					
    return false;
  }
  if (periodPos+3 > email.length){
    return false;
  }
  return true;
}