// JavaScript Document
function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmail(theForm.subscribe);	
  
  if (reason != "") {
    alert("Some fields need correction:<br />" + reason);
    return false;
  }

  return true;
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

    if (fld.value == "") {
        fld.style.background = 'White';
        error = "You must enter an email address.<br />";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'White';
        error = "Please enter a valid email address.<br />";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'White';
        error = "The email address contains illegal characters.<br />";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

