function validateInput() {
  var name = document.getElementById("Name");
  var email = document.getElementById("Email");
  var comments = document.getElementById("Comments");

  var isValid = validateField('Name', trim(name.value, ''));
  if (isValid) {
    isValid = validateField('Email', trim(email.value, ''));
  }
  
  if (isValid) {
    isValid = validateField('Comments', trim(comments.value, ''));
  }
  
  return isValid;
}

function validateField(field, value) {
  if (value.length == 0) {
   alert(field + " can not be empty.");
   return false;
  }
  
  var ltFound = (value.indexOf('<') > -1) || (value.indexOf('&lt;') > -1);
  var gtFound = (value.indexOf('>') > -1) || (value.indexOf('&gt;') > -1);
  
  if (ltFound || gtFound) {
   alert(field + " can not contain scripts or HTML.");
   return false;
  }
  
  return true;
}

function resetFields() {
  var name = document.getElementById("Name");
  var email = document.getElementById("Email");
  var comments = document.getElementById("Comments");

  name.value = '';
  email.value = '';
  comments.value = '';
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}