
function validate_email(theControl)
{
	
	if ( theControl.value == "" || theControl.value.length <= 0 )
	{

   alert("I'm sorry. This email address must be filled in correct to send the form to our server. Please"
   +" check the prefix and '@' sign.");
   theControl.focus()
		return false;
	}
	
	var reEmail = /^.+\@.+\..+$/
	var holderValue;
	var thisValue = theControl.value;
	
	// Check for e-mail addresses from ISPs and other sources that have been consistently
	// entered incorrectly.  If detected, correct the situation.
	if
		(
			(thisValue.substring(thisValue.length - 4, thisValue.length).toLowerCase()) == '@aol' ||
			(thisValue.substring(thisValue.length - 4, thisValue.length).toLowerCase()) == '@msn' ||
			(thisValue.substring(thisValue.length - 6, thisValue.length).toLowerCase()) == '@yahoo' ||
			(thisValue.substring(thisValue.length - 6, thisValue.length).toLowerCase()) == '@lycos' ||
			(thisValue.substring(thisValue.length - 7, thisValue.length).toLowerCase()) == '@excite' ||
			(thisValue.substring(thisValue.length - 10, thisValue.length).toLowerCase()) == '@altavista' ||
			(thisValue.substring(thisValue.length - 11, thisValue.length).toLowerCase()) == '@compuserve' ||
			(thisValue.substring(thisValue.length - 8, thisValue.length).toLowerCase()) == '@prodigy' ||
			(thisValue.substring(thisValue.length - 8, thisValue.length).toLowerCase()) == '@hotmail' ||
			(thisValue.substring(thisValue.length - 9, thisValue.length).toLowerCase()) == '@netscape'
		)
		{
			holderValue = thisValue.concat('.com');
			thisValue = holderValue;
			theControl.value = thisValue;
		}
	if
		(
			(thisValue.substring(thisValue.length - 5, thisValue.length).toLowerCase()) == '@home'
		)
		{
			holderValue = thisValue.concat('.net');
			thisValue = holderValue;
			theControl.value = thisValue;
		}
		
	// Now check the actual value of the e-mail address for validity.
	var flagFirstCheck = (theControl.value.length < 6) ||
		(thisValue.indexOf('@') == -1) || 
		(thisValue.indexOf('.') == -1) || 
		(thisValue.indexOf('@',(thisValue.indexOf('@')+1)) != -1) ||
		((thisValue.indexOf('.')+1) == thisValue.length) || 
		((thisValue.indexOf('@')+1) == thisValue.length)
	var flagSecondCheck = reEmail.test(thisValue)
	if ( flagFirstCheck || !flagSecondCheck)
	{

   alert("I'm sorry. This email address seems to be incorrect. Please"
   +" check the prefix and '@' sign.");
   theControl.focus()

		return false;
	} 
	else {

		return true;
	}
}

function validatePhone(fld) {
 var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');
	if (fld.value == "") {
	 alert("You didn't enter a phone number.");
	 fld.style.background = '#ffff99';
	 fld.focus()
	return false;
	} else if (isNaN(parseInt(stripped))) {
	 alert("The phone number contains illegal characters.");
	 fld.style.background = '#ffff99';
	 fld.focus()
	 return false;
	} else if (!(stripped.length == 10)) {
	 alert( "Please enter a valid phone number (xxx xxx-xxxx)" );
	 fld.style.background = '#ffff99';
	 fld.focus()
	 return false;
	}
  return true;
}

function FValidateControl(control, prompt) {
  if (control.value=="") {
    alert("The " + prompt +" field is a required field, and it must be filled in before your form can be sent to our server.")
    control.focus()
    return false }
  return true }

function FSubmitValidation(form) {

if (!validate_email(form.email)) return false
if (!FValidateControl(form.name,'Name')) return false
if (!FValidateControl(form.address,'Address')) return false
if (!FValidateControl(form.city,'City')) return false
if (!FValidateControl(form.state,'State')) return false
if (!FValidateControl(form.zip,'Zip')) return false
if (!validatePhone(form.phone)) return false

  if (form.comments.value.length>0) {

        if ( form.comments.value.match("<html") ||
             form.comments.value.match("<body") ||
             form.comments.value.match("<form") ||   
             form.comments.value.match("<href") ||
             form.comments.value.match("http:") ||
             form.comments.value.match("<a") ||
             form.comments.value.match("<img") ||
             form.comments.value.match("<javascript") ||
             form.comments.value.match("<vbscript") || 
             form.comments.value.match("<script") ||    
             form.comments.value.match("<object") ||    
             form.comments.value.match("document.write") ||  
             form.comments.value.match("<\?php") ||      
             form.comments.value.match("<\?xml") ) {
                alert("Sorry .. you are entering text that is unacceptable.")   
                form.comments.focus() 
                return false }
     }

  // only allow 400 chars
  if (form.comments.value.length>400) {
                alert("Sorry .. you entered more text than allowed.")
                form.comments.focus()
                return false }

 return true }

function validatefield(thisfield,imgname){
  if (thisfield.value == "") {
  imgname.src="images/stop.gif";
  }
  else
  {
  imgname.src="images/blank.gif";
  } 
}
