<!-- 

// the following function checks the contact form for errors
// that may have been entered by the user. Errors in the form
// could prevent the web author from building an accurate
// database of potential customers.

// To write this form, I relied primarily on an example in a good
// book called The Book of JavaScript, by Thau!. Thau! is also the
// author of the JavaScript tutorials on www.webmonkey.com.


function checkForm() {
  var error_mess = "";

  // check the fname field
  if ((document.getElementById("contact").fname.value == "fname") ||
	 (document.getElementById("contact").fname.value == "")) 
		{
		error_mess += "- You must enter your First Name.\n";
		event.returnValue=false;
		}

  // check the lname field
  if ((document.getElementById("contact").lname.value == "lname") ||
	 (document.getElementById("contact").lname.value == "")) 
		{
		error_mess += "- You must enter your Last Name.\n";
		event.returnValue=false;
		}
		
		  // check the stopspam
  var num2 = document.getElementById("contact").stopspam.value.indexOf("2");
  var num7 = document.getElementById("contact").stopspam.value.lastIndexOf("7");
  var space = document.getElementById("contact").stopspam.value.indexOf(" ");
  var elength = document.getElementById("contact").stopspam.value.length;
  if ((num2 == -1) ||     // '2' is missing from stop spam number
	  (num2 == 0) ||        // '2' is first character in stop spam number
	  (num7 == -1) ||            // '7' is missing from stop spam number
	  (num7 - 2 == num2 ) ||  // '2' and '7' next to stop spam number
	  (num7 < num2) ||       // '7' before 2' symbol
	  (num7 == elength -1 ) ||   // '7' is last character in stop spam number
	  (space >= 1))             // stop spam number contains a space
		{
		error_mess += "- You must enter the stop spam number.\n";
		event.returnValue=false;
		}

  // check the email field
  var atsymbol = document.getElementById("contact").email.value.indexOf("@");
  var lastdot = document.getElementById("contact").email.value.lastIndexOf(".");
  var space = document.getElementById("contact").email.value.indexOf(" ");
  var elength = document.getElementById("contact").email.value.length;
  if ((atsymbol == -1) ||     // '@' is missing from e-mail address
	  (atsymbol == 0) ||        // '@' is first character in email address
	  (lastdot == -1) ||            // '.' is missing from email address
	  (lastdot - 1 == atsymbol) ||  // '@' and '.' next to each other
	  (lastdot < atsymbol) ||       // '.' before '@' symbol
	  (lastdot == elength -1 ) ||   // '.' is last character in e-mail address
	  (space >= 1))             // email address contains a space
		{
		 error_mess += "- You must enter a valid e-mail address.\n";
		 event.returnValue=false;
		 }
		 

  // displays itemized error message
  // if the error message is blank, then the user didn't make any mistakes and the
  // form can be submitted to the cgi script for processing. If an error message
  // does display, the form returns false to prevent the errors from getting submitted.
  if (error_mess == "") {
	return true;
	} else {
	error_mess = "We found the following errors in your form: \n" + error_mess;
	alert(error_mess);
	return false;
	}
  }

// -->
