
    //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('','review','width=540,height=700,left=200,top=10,scrollbars=yes');
      document.contact.submit();
  }

  // email and name validation
  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 validWeb(webIs) {
      webInvalidChars = " /:,;{}"
                     
      // cannot be empty
      if (webIs == "") {
          alert("please enter your website address");
          return false;
      }
      // does it contain any invalid characters?
      for (b=0; b<webInvalidChars.length; b++) {
          badChar = webInvalidChars.charAt(b);
          if (webIs.indexOf(badChar,0) > -1) {
              alert("you have entered illegal characters in your website address.  Please try again.");
              return false;
          }
      }
      
      // there must be one "." 
      periodPos = webIs.indexOf(".",atPos)
      if (periodPos == -1) {
          alert("please make sure your website address contains a '.' character");
          return false;
      }
      // must be at least 2 characters after the "."
      if (periodPos+3 > webIs.length) {
          alert("please make sure you have entered your domain name suffix eg. 'co.uk'");
          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 validTitle(titleIs) {
     titleInvalidChars = "/:,;{}"

     // cannot be empty
     if (titleIs == "") {
     alert("please enter your title");
     return false;
     }
     // does it contain any invalid characters?
     for (d=0; d<titleInvalidChars.length; d++) {
         badChar = titleInvalidChars.charAt(d);
         if (titleIs.indexOf(badChar,0) > -1) {
         alert("you have entered illegal characters in your title.  Please try again.");
             return false;
         }
     }
   return true;
 }

  function validCompany(companyIs) {
     companyInvalidChars = "/:,;{}"

     // cannot be empty
     if (companyIs == "") {
     alert("please enter your company name");
     return false;
     }
     // does it contain any invalid characters?
     for (e=0; e<companyInvalidChars.length; e++) {
         badChar = companyInvalidChars.charAt(e);
         if (companyIs.indexOf(badChar,0) > -1) {
         alert("you have entered illegal characters in your company 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;
 }

  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 company name's valid
      if (!validCompany(document.contact.company.value)) {
          document.contact.company.focus();
          document.contact.company.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 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 URL's valid
      if (!validWeb(document.contact.website.value)) {
          document.contact.website.focus();
          document.contact.website.select();
          return false;
      }
     
      // Everything's valid, so return true
      formMessageWindow();
      return true;
  }
