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"), "");
}

function VerifyForm(frm){
  var i;
  var BadForm;
  var BadFields = "";

  var ptrn_name=/^[^\d]{3,}$/;
  var ptrn_email=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;

  var v_version  = trim(frm.Version.value, " ");
  var v_serial  = trim(frm.SerialNumber.value, " ");
  var v_os  = trim(frm.OS.value, " ");
  var v_osversion  = trim(frm.OSVer.value, " ");
  var v_subject  = trim(frm.Subject.value, " ");
  var v_message = trim(frm.Message.value, " ");
  var v_name = trim(frm.Name.value, " ");
  var v_mail = trim(frm.Email.value, " ");
  var v_code = trim(frm.security_problemreport.value, " ");

  //Check Product Version #
  if (v_version == ""){
    frm.Version.style.background = "#FFA07A";
    BadForm = true;
    BadFields = BadFields + "Version number of the product\n"
  }
  else
    frm.Version.style.background = "#FFFFFF";


  //Check OS
  if (v_os == ""){
    frm.OS.style.background = "#FFA07A";
    BadForm = true;
    BadFields = BadFields + "Operating system name on which you are running the product:\n"
  }
  else
    frm.OS.style.background = "#FFFFFF";

  if (v_osversion == ""){
    frm.OSVer.style.background = "#FFA07A";
    BadForm = true;
    BadFields = BadFields + "Operating system version number on which you are running the product:\n"
  }
  else
    frm.OSVer.style.background = "#FFFFFF";

  //Check Inquiry Description
  if (v_subject == ""){
    frm.Subject.style.background = "#FFA07A";
    BadForm = true;
    BadFields = BadFields + "Tell us in general what the inquiry is about:\n"
  }
  else
    frm.Subject.style.background = "#FFFFFF";

  //Check Details
  if (v_message == ""){
    frm.Message.style.background = "#FFA07A";
    BadForm = true;
    BadFields = BadFields + "Give us the details. Be as complete as possible (preferably step-by-step) and include the text of any error messages:\n"
  }
  else
    frm.Message.style.background = "#FFFFFF";

  //Check Name
  if ((v_name == "") || (v_name.match(ptrn_name)==null)){
    frm.Name.style.background = "#FFA07A";
    BadForm = true;
    BadFields = BadFields + "Your full name:\n"
  }
  else
    frm.Name.style.background = "#FFFFFF";


  //Check Email
  if ((v_mail == "") || (v_mail.match(ptrn_email)==null)){
    frm.Email.style.background = "#FFA07A";
    BadForm = true;
    BadFields = BadFields + "Your Email:\n"
  }
  else
    frm.Email.style.background = "#FFFFFF";

  //Check Security Code
  if (v_code== ""){
    frm.security_problemreport.style.background = "#FFA07A";
    BadForm = true;
    BadFields = BadFields + "Your Security Code:\n"
  }
  else
    frm.security_problemreport.style.background = "#FFFFFF";

  //Warn User that the form is bad
  if (BadForm){
    alert("Please provide the following information.\n" +  BadFields);
  }
  else
    frm.action="/cgibin/problem.php";

  return !BadForm;
}
