function validateEmpty(fld) { // function that validates an empty field, turns background yellow if empty
    var error = "";
	if (fld.value.length == 0) {
        fld.style.background = '#FFFFCC'; 
		TheLabel = fld.id;
        error = TheLabel + "\n" 
	} else {
        fld.style.background = 'White';
    }
    return error;   
}

function validateFormOnSubmit(theForm) { // function that validates the form for empty fields
var reason = "";
  reason += validateEmpty(f.xEmail);
  reason += validateEmpty(f.xSubject);
  reason += validateEmpty(f.xBody);     
  if (reason != "") {
    alert("Please input the following:\n" + reason);
    return false;
  }
  return true;
} 
function validateEmail(fld) { // validates a form field for correct e-mail address - use with onBlur="validateEmail(this)"
var tfld = trim(fld.value); // value of field with whitespace trimmed off
if (tfld.length!=0) 
	{
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;  
	if ((!emailFilter.test(tfld)) || (fld.value.match(illegalChars)))
			{
			alert("Please enter a valid email address.");
			fld.focus();
			fld.select();	
			return false;
			 } 
		else
			return true;
	}
}
function trim(s) /// trims whitespac from a field entry
{
  return s.replace(/^\s+|\s+$/, '');
} 
