// JavaScript Document

/****************************************************************
  Code below is used to validate the form 
*****************************************************************/
// submit the form
function submitForm(name) {
  var myForm = document.forms[name];

  if (validate(myForm)) {
    myForm.submit();
  }
  //alert(myForm);
}

// validate the form
function validate(myForm) {
  return (checkField(myForm.elements["firstname"], 'your first name') &&
          checkField(myForm.elements["lastname"], 'your last name') &&
		  checkEmail(myForm.elements["email"]));
}


// check text fields
function checkField(field, name) {
  var error
  var cont = true;
  
  if (field.value == '' || field.value == 'Year') {
    error = 'Please enter ' + name + '. This is a required field.';
    alert(error);
	cont = false;
  }  
  return cont;
}

// check if email address is valid
function checkEmail(field) {
  var error;
  var emailFilter = /^.+@.+\..{2,4}$/;
  var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]\s]/;
  var cont = true;
  
  if (!emailFilter.test(field.value)) {
    error = 'Please enter a valid email address.';
	alert(error);
	cont = false;
  }
  else if (field.value.match(illegalChars)) {
    error = 'Email address contains one or more illegal characters.';
	alert(error);
	cont = false;
  }
  return cont;
}

/******************************************************************/