// JavaScript Document
function validEmail(email)
{
   invalidChars = " /:,;"

   if (email == "")
      return false

   for (i=0; i<invalidChars.length; i++)
   {
      badChar = invalidChars.charAt(i)

      if (email.indexOf(badChar,0)>-1)
         return false
   }

   atPos = email.indexOf("@",1)

   if (atPos == -1)
      return false

   if (email.indexOf("@",atPos+1) != -1)
      return false

   periodPos = email.indexOf(".",atPos)

   if (periodPos == -1)
      return false

   if (periodPos+3 > email.length)
      return false

   return true
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function submitIt (contactForm)
{
   if (contactForm.name.value == "")
   {
      alert("Please enter your name.")
	  return false
   }

   if (contactForm.tel.value != "" )
   {
      if (isInteger(contactForm.tel.value) == false)
      {
	     alert("Please enter a valid tel number.")
	     contactForm.tel.value=""
	     contactForm.tel.focus()
         return false
      }
   }
   
   if (!validEmail(contactForm.email.value))
   {
      alert("Invalid format. Please enter your email address again.")
      return false
   }
   
   if (contactForm.query.value == "")
   {
      alert ("Please enter a query.")
      return false
   }
     
   return true
}

