function validateFormOnSubmit(theForm) {
	var reason = "";

  reason += validateEmail(theForm.fixedEmail);
  reason += validateEmpty(theForm.first);
  reason += validateEmpty2(theForm.last);
  reason += validateEmpty3(theForm.comment);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

// Validate Empty Fields

function validateEmpty(first) {
    var error = "";
  
    if (first_name.value.length == 0) {
        first.style.background = 'Yellow'; 
        error = "Your first name has not been filled in.\n"
    } else {
        first.style.background = 'White';
    }
    return error;   
}
function validateEmpty2(last) {
    var error = "";
  
    if (last.value.length == 0) {
        last.style.background = 'Yellow'; 
        error = "Your last name has not been filled in.\n"
    } else {
        last.style.background = 'White';
    }
    return error;   
}
function validateEmpty3(comment) {
    var error = "";
  
    if (comment.value.length == 0) {
        comment.style.background = 'Yellow'; 
        error = "Your company has not been filled in.\n"
    } else {
        comment.style.background = 'White';
    }
    return error;   
}
	
// Validate Email

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fixedEmail) {
    var error="";
    var tfld = trim(fixedEmail.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fixedEmail.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (email.value.match(illegalChars)) {
        fixedEmail.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else {
        fixedEmail.style.background = 'White';
    }
    return error;
}

// Validate Phone

function validatePhone(phone) {
    var error = "";
    var stripped = phone.value.replace(/[\(\)\.\-\ ]/g, '');     

   if (phone.value == "") {
        error = "Please enter your 10-digit area code and phone number.\n";
        phone.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "Please enter your 10-digit area code and phone number.\n";
        phone.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "Please enter your 10-digit area code and phone number.\n";
        phone.style.background = 'Yellow';
    } 
    return error;
}
