function highlightError(id) {
  var element = document.getElementById(id);
  element.style.border = '2px solid #FF0000';
}

function checkEmail(id) {
  var strng = document.getElementById('email').value;
  var error = "";

  if (strng == "") {
     highlightError(id);
     return "You must enter an email address.\n";
  }

  var emailFilter = /^.+@.+\..{2,3}$/;
  if (!(emailFilter.test(strng))) { 
    highlightError(id);
    return "You must enter a valid email address.\n";
  }

  var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
  if (strng.match(illegalChars)) {
    highlightError(id);
    error = "The email address contains illegal characters.\n";
  }

  return error;
}

function checkCaptcha() {
  var error = "";
  var element = document.getElementById('captcha');

  if (element != null) {
    if (element && element.value == "") {
      highlightError('captcha');
      return "You must enter the text from the image.";
    }
  }
  return error;
}

function checkStringByID(id, error_msg) {
  var strng = document.getElementById(id).value;
  var error = "";

  if (strng == "") {
    highlightError(id);
    error = error_msg + "\n";
  }

  return error;
}

function checkContactForm() {
  var errors = '';
  errors += checkEmail('email');
  errors += checkStringByID('name', 'You must include a name.');
  errors += checkStringByID('your_message', 'You must include a message.');
  errors += checkCaptcha();

  if (errors != "") {
    alert(errors)
    return false;
  }
  return true;
}