// Global variables
var today=new Date();
var display=(today.getMonth()+1) + "/" + today.getDate() + "/" + today.getYear();
var RequiredDate="";
var emailaddr="";

function CurDate(){
  document.Contact.EmailDate.value=display;
}
//Test to see the searched text is in the string
function testinput(re, str){
 if (str.search(re) != -1) //if str does not contain the searched string
 { 
  return (true)
 } 
 else       
 { 
  return (false)
 }
}

//Extract only numeric characters (ex. "123") out of the string sent
function ExtractNumber(str) {
 var newstr = ""
 for (var i=0; i<str.length; i++) {
   if (str.substr(i,1) != " " && isNaN(str.substr(i,1)) == false) {
    newstr = newstr + str.substr(i,1)
  }

 }   
 return newstr
}



function Validator()
{

  if (document.Contact.Name.value =="")
  {
    alert("Please enter your name.");
    document.Contact.Name.focus();
    return (false);
  }

  if (document.Contact.Zip1.value !="")  //Check to see if user enters just 5-digit zipcode in the first box of zipcode
  {
    Zip = document.Contact.Zip1.value
    NewValue=ExtractNumber(Zip);
    if (NewValue.length !=5) // The first 5 characters of the zipcode must be digit characters
    if (Zip.length !=5 && NewValue.length !=5)
    {
      alert("Please enter 5-digit zipcode in the first box of zipcode.")
      document.Contact.Zip1.focus();
      return (false);
    }
  }

 
  if (document.Contact.Email.value =="")
  {
      alert("Please enter your email address.");
      document.Contact.Email.focus();
      return (false);
  }      
  else
  {
    var input = document.Contact.Email.value;
    if (testinput("@", input) == (false)) //email address does not have "@"
    {
      alert("Please enter correct email address. Ex: name@ISP.com");
    document.Contact.Email.focus();
    return (false);
    }
    if (testinput(".", input) == (false)) //email address does not have "."
    {
      alert("Please enter correct email address. Ex: name@ISP.com");
    document.Contact.Email.focus();
    return (false);
    }
  }
if (document.Contact.Subject.value =="")
  {
    alert("Please enter a subject.");
    document.Contact.Subject.focus();
    return (false);
  }  
  
if (document.Contact.Comment.value == "")
  {
      alert("Please type in your comments or suggestions.");
      document.Contact.Comment.focus();
      return (false);
  }      

return true;
}

function doMail()
{
if(Validator())
{
     result="mailto:" + emailaddr + "?subject=" + Subject;
     document.contact.action=result;
//     document.contact.method="POST"
     document.contact.submit();
}

}
