
  function isBlank(str)
  {
    for(var i=0; i<str.length; i++)
    {
      var ch = str.charAt(i);
      if( (ch != ' ') && (ch != '\n') && (ch != '') )
        return false;
    }
    return true;
  }

  function isEmailAddr(email)
  {
    var result = false;
    var str = new String(email);
    var index = str.indexOf("@");
    
    if (index > 0)
    {
      var dotIndex = str.indexOf(".",index);
      if((dotIndex > index + 1) && (str.length > dotIndex +1))
        result = true;
    }
    return result;
  }
  
  function isPhoneNumber(pnum)
  {
    var result = true;
    var str = new String(pnum);
  
    for (var i = 0; i < str.length; i++)
    {
      var c = str.charAt (i);
      
      if (c == '-' || c == '.' || c == ' ' || 
         	c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || 
         	c == '5' || c == '6' || c == '7' || c == '8' || c == '9')
      {}
      else
      {
        result = false;
      }
    }
    return result;   
  }
  
  function clearContents(formField,label)
  {
    if(formField.value == label)
    {
      formField.style.color = "black";
      formField.value = "";
    }
  }
  
  function refreshContents(formField,label)
  {
    if (formField.value == "")
    {
      formField.value = label;
    }
  }
  
  function validateField(formField,fieldLabel)
  {
    if (isBlank(formField.value) || formField.value == fieldLabel || formField.value.length < 2)
    {
      return false;
    }
    else
    {
      return true;
    }
  }
  
  function highlightField(formField,fieldLabel)
  {
    formField.style.color = "red";
    formField.value = fieldLabel;
  }
  
  function validateCity()
  {
    if (document.vixen_contact.City.value == "SELECT")
      return false;
    else
      return true;
  }
  
  function validateSeeComments()
  {
    if (document.vixen_contact.City.value == "SEE COMMENTS" )
    {
      if(document.vixen_contact.Comments.value == "Comments" || isBlank(document.vixen_contact.Comments.value) )
      {
        return false;
      }
      else
      {
        return true;
      }
    }
    else
    {
      return true;
    }
  }
  
  function validate()
  {  
    var valid = true;
    var alertMsg = "Please enter valid data in following highlighted field(s)";
    
    if (!validateField(document.vixen_contact.Name,"Full Name"))
    {
      valid = false;
      alertMsg += "\n - Full Name";
      highlightField(document.vixen_contact.Name,"Full Name");
    }
    if (!validateField(document.vixen_contact.Email,"Email Address"))
    {
      valid = false;
      alertMsg += "\n - Email Address";
      highlightField(document.vixen_contact.Email,"Email Address");
    }
    else if (!isEmailAddr(document.vixen_contact.Email.value))
    {
      valid = false;
      alertMsg += "\n - Email Address";
      highlightField(document.vixen_contact.Email,"Email Address");
    }
    if (!validateField(document.vixen_contact.Phone,"Phone Number"))
    {
      valid = false;
      alertMsg += "\n - Phone Number";
      highlightField(document.vixen_contact.Phone,"Phone Number");
    }
    else if(!isPhoneNumber(document.vixen_contact.Phone.value))
    {
      valid = false;
      alertMsg += "\n - Phone Number";
      highlightField(document.vixen_contact.Phone,"Phone Number");
    }
    if (!validateField(document.vixen_contact.Date,"Date"))
    {
      valid = false;
      alertMsg += "\n - Date";
      highlightField(document.vixen_contact.Date,"Date");
    }
    if (!validateCity())
    {
      valid = false;
      alertMsg += "\n\nPlease select a City";
    }  
    else if (!validateSeeComments())
    {
      valid = false;
      alertMsg += "\n\nPlease enter a City in the Comments Field";
      highlightField(document.vixen_contact.Comments,"Comments")
    }
    if (!valid)
      alert(alertMsg);
      
    return valid;
  }
  
  function doSubmit()
  {
    if (validate())
      document.searchFrm.submit();
  }