
function validateForm() 
{
var result = true;
var error_color = '#B1D3EC';
var good_color = '#FFFFFF';

// check if no drop down has been selected
if (document.contact.subject.selectedIndex < 0)
{
alert("Please select one of the \"subject\" options.");
document.contact.subject.style.background = error_color;
return (false);
}

// check if the first drop down is selected, if so, invalid selection
 if (document.contact.subject.selectedIndex == 0)
 {
   alert("The first \"subject\" option is not a valid selection."); 
   document.contact.subject.style.background = error_color;
   return (false);
 }

 else if (document.contact.subject.selectedIndex > 0) 
  {
  document.contact.subject.style.background = good_color;
  }

// check to see if the field is blank

 if (document.contact.name.value == "")
 {
   alert("You must enter your name.");
   document.contact.name.style.backgroundColor = error_color;
   document.contact.name.focus();
   return (false);
 }
 else if (document.contact.name.value > "") {
   document.contact.name.style.backgroundColor = good_color;
  }


// require at least 3 characters be entered
if (document.contact.name.value.length < 3)
 {
  alert("Please enter at least 3 characters in the \"name\" field.");
  document.contact.name.style.backgroundColor = error_color;
  document.contact.name.focus();
  return (false);
 }

 else if (document.contact.name.value.length > 3) {
 document.contact.name.style.backgroundColor = good_color;
 }

// allow ONLY alphanumeric keys, no symbols or punctuation
// this can be altered for any "checkOK" string you desire
var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
var checkStr = document.contact.name.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
 {
 alert("Please enter only letter and numeric characters in the \"name\" field.");
 document.contact.name.style.backgroundColor = error_color;
 document.contact.name.focus();
 return (false);
 }

 else if (document.contact.name.value.length > 3) {
 document.contact.name.style.backgroundColor = good_color;
 }

// check if email field is blank
if (document.contact.email.value == "")
 {
 alert("Please enter a value for the \"email\" field.");
 document.contact.email.style.backgroundColor = error_color;
 document.contact.email.focus();
 return (false);
 }

 else if (document.contact.email.value.length > "") {
 document.contact.email.style.backgroundColor = good_color;
 }

// test if valid email address, must have @ and .
var checkEmail = "@.";
var checkStr = document.contact.email.value;
var EmailValid = false;
var EmailAt = false;
var EmailPeriod = false;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkEmail.length;  j++)
{
if (ch == checkEmail.charAt(j) && ch == "@")
EmailAt = true;
if (ch == checkEmail.charAt(j) && ch == ".")
EmailPeriod = true;
	  if (EmailAt && EmailPeriod)
		break;
	  if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string
if (EmailAt && EmailPeriod)
{
		EmailValid = true
		break;
	}
}
if (!EmailValid)
 {
 alert("The \"email\" field must contain an \"@\" and a \".\".");
 document.contact.email.style.backgroundColor = error_color;
 document.contact.email.focus();
 return (false);
}
// allow only 150 characters maximum in the comment field

if (contact.message.value.length <= 5)
 {
 alert("You must enter your message.");
 document.contact.message.style.backgroundColor = error_color;
 document.contact.message.focus();
 return (false);
 }
 else if (document.contact.message.value.length >= 5) {
 document.contact.message.style.backgroundColor = good_color;
 }

function validateForm() {
if (!validateForm()) return false;
return true;
}
}
