
    //validation variables
  var b=0;
  var c=0;
  var d=0;
  var e=0;
  var f=0;
  
  // form message window
  function formMessageWindow() {
			messageWin = window.open('','pop','width=620,height=400,left=200,top=100,scrollbars=yes,resizable=yes');
      document.contact.submit();
  }

  // validation
  // mandatory fields
  function validEmail(email) {
      emailInvalidChars = " /:,;{}"
                     
      // cannot be empty
      if (email == "") {
          alert("please enter your email address");
          return false;
      }
      // does it contain any invalid characters?
      for (b=0; b<emailInvalidChars.length; b++) {
          badChar = emailInvalidChars.charAt(b);
          if (email.indexOf(badChar,0) > -1) {
              alert("you have entered illegal characters in your email address.  Please try again.");
              return false;
          }
      }
      // there must be one "@" symbol
      atPos = email.indexOf("@",1)            
      if (atPos == -1) {
          alert("please make sure your email address contains the character '@'");
          return false;
      }
      // and only one "@" symbol
      if (email.indexOf("@",atPos+1) != -1) {
          alert("please make sure your email address contains only one character '@'");
          return false;
      }
      // and at least one "." after the "@"
      periodPos = email.indexOf(".",atPos)
      if (periodPos == -1) {
          alert("please make sure your email address contains a '.' character");
          return false;
      }
      // must be at least 2 characters after the "."
      if (periodPos+3 > email.length) {
          alert("please make sure you have entered your domain name suffix");
          return false;
      }
      return true;
  }


  function validName(nameIs) {
      nameInvalidChars = "/:,;{}"

      // cannot be empty
      if (nameIs == "") {
	    alert("please enter your name");
      return false;
      }
      // does it contain any invalid characters?
      for (c=0; c<nameInvalidChars.length; c++) {
          badChar = nameInvalidChars.charAt(c);
          if (nameIs.indexOf(badChar,0) > -1) {
    		  alert("you have entered illegal characters in your name.  Please try again.");
              return false;
          }
      }
	  return true;
  }

  function validTel(telIs) {
     telInvalidChars = "/:,;{}abcdefghijklmnopqrstuvwxyz"

     // cannot be empty
     if (telIs == "") {
     alert("please enter your telephone no.");
     return false;
     }
     // does it contain any invalid characters?
     for (f=0; f<telInvalidChars.length; f++) {
         badChar = telInvalidChars.charAt(f);
         if (telIs.indexOf(badChar,0) > -1) {
         alert("you have entered illegal characters in your telephone number.  Please try again.");
             return false;
         }
     }
   return true;
 }

  // other fields - no illegal chars as security threat
  function validTitle(myTitleIs) {
     myTitleInvalidChars = "/:,;{}"

     // does it contain any invalid characters?
     for (f=0; f<myTitleInvalidChars.length; f++) {
         badChar = myTitleInvalidChars.charAt(f);
         if (myTitleIs.indexOf(badChar,0) > -1) {
         alert("you have entered invalid characters in your title.  Please try again.");
             return false;
         }
     }
   return true;
 }


  function validAddress(addressIs) {
     addressInvalidChars = "/:,;{}"

     // does it contain any invalid characters?
     for (f=0; f<addressInvalidChars.length; f++) {
         badChar = addressInvalidChars.charAt(f);
         if (addressIs.indexOf(badChar,0) > -1) {
         alert("you have entered invalid characters in your address.  Please try again.");
             return false;
         }
     }
   return true;
 }

  function validAbout(aboutIs) {
     aboutInvalidChars = "/:,;{}"

     // does it contain any invalid characters?
     for (f=0; f<aboutInvalidChars.length; f++) {
         badChar = aboutInvalidChars.charAt(f);
         if (aboutIs.indexOf(badChar,0) > -1) {
         alert("you have entered invalid characters in your enquiry details.  Please try again.");
             return false;
         }
     }
   return true;
 }

  function validCompany(companyIs) {
     companyInvalidChars = "/:,;{}"

     // does it contain any invalid characters?
     for (f=0; f<companyInvalidChars.length; f++) {
         badChar = companyInvalidChars.charAt(f);
         if (companyIs.indexOf(badChar,0) > -1) {
         alert("you have entered invalid characters in your company name.  Please try again.");
             return false;
         }
     }
   return true;
 }


  function validJob(jobIs) {
     jobInvalidChars = "/:,;{}"

     // does it contain any invalid characters?
     for (f=0; f<jobInvalidChars.length; f++) {
         badChar = jobInvalidChars.charAt(f);
         if (jobIs.indexOf(badChar,0) > -1) {
         alert("you have entered invalid characters in your job title.  Please try again.");
             return false;
         }
     }
   return true;
 }


  function validOtherInfo(otherInfoIs) {
     otherInfoInvalidChars = "/:,;{}"

     // does it contain any invalid characters?
     for (f=0; f<otherInfoInvalidChars.length; f++) {
         badChar = otherInfoInvalidChars.charAt(f);
         if (otherInfoIs.indexOf(badChar,0) > -1) {
         alert("you have entered invalid characters in your request for additional information.  Please try again.");
             return false;
         }
     }
   return true;
 }



  function submitIt() {

    
      // check to see if the name's OK
      if (!validName(document.contact.realname.value)) {
          document.contact.realname.focus();
          document.contact.realname.select();
          return false;
      }

      // check to see if the titles's OK
      if (!validTitle(document.contact.myTitle.value)) {
          document.contact.myTitle.focus();
          document.contact.myTitle.select();
          return false;
      }

      // check to see if the email's valid
      if (!validEmail(document.contact.email.value)) {
          document.contact.email.focus();
          document.contact.email.select();
          return false;
      }
     
      // check to see if the address is OK
      if (!validAddress(document.contact.address.value)) {
          document.contact.address.focus();
          document.contact.address.select();
          return false;
      }
     
      // check to see if the tel no's valid
      if (!validTel(document.contact.tel.value)) {
          document.contact.tel.focus();
          document.contact.tel.select();
          return false;
      } 

      // check to see if other fields OK
      if (!validAbout(document.contact.contact_me_about.value)) {
          document.contact.contact_me_about.focus();
          document.contact.contact_me_about.select();
          return false;
      } 

      if (!validCompany(document.contact.company.value)) {
          document.contact.company.focus();
          document.contact.company.select();
          return false;
      } 

      if (!validJob(document.contact.job.value)) {
          document.contact.job.focus();
          document.contact.job.select();
          return false;
      }

      if (!validOtherInfo(document.contact.otherInfo.value)) {
          document.contact.otherInfo.focus();
          document.contact.otherInfo.select();
          return false;
      } 


      // Everything's valid, so return true
      formMessageWindow();
      return true;
  }
