// JavaScript Document

<!--beginning of script
	
	function activeInput(obj) {
		obj.style.backgroundColor = '#cccc99';
		obj.style.color = '#414141';
		}
		
	function inactiveInput(obj) {
		obj.style.backgroundColor = '#CCCCCC';
		obj.style.color = '#000000';
		}
// the following function checks the feedback1 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.

// I also used a variety of sources on the web for a few details
// that weren't described in the book. I've listed their URLs at
// the bottom of the page.

function checkForm() {
  var error_mess = "";

  // check the first name field
  if ((document.getElementById("feedback1").Web_Enquiry_Contact_Name.value == "Contact_Name") ||
	 (document.getElementById("feedback1").Web_Enquiry_Contact_Name.value == "")) 
		{
		error_mess += "- You must enter your first name.\n";
		event.returnValue=false;
		document.getElementById("feedback1").Web_Enquiry_Contact_Name.style.backgroundColor='#FFFF00';
		}

  // check the last name field
  //if ((document.getElementById("feedback1").lname.value == "last") ||
	// (document.getElementById("feedback1").lname.value == "")) 
	//	{
	//	error_mess += "- You must enter your last name.\n";
	//	event.returnValue=false;
	//	document.getElementById("feedback1").lname.style.backgroundColor='#FFFF00';
	//	}

  // check the email field
  var atsymbol = document.getElementById("feedback1").Web_Enquiry_Email.value.indexOf("@");
  var lastdot = document.getElementById("feedback1").Web_Enquiry_Email.value.lastIndexOf(".");
  var space = document.getElementById("feedback1").Web_Enquiry_Email.value.indexOf(" ");
  var elength = document.getElementById("feedback1").Web_Enquiry_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;
		 document.getElementById("feedback1").Web_Enquiry_Email.style.backgroundColor='#FFFF00';
		 }

 
  // 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;
	}

  }

//end of script-->
