$(document).ready(function() {
  $("form").submit(function() {
//    alert("Please wait.  Validating " + this.id);
    var form = $(this);//$("#" + this.id);
    var valid = true;
    form.find(".form-error").removeClass("form-error");
    var fields = form.find(".input-required");
    fields.each(function(index) {
      if ($("input[name='" + $(this).attr("name") + "']").size() > 1) {
        var onevalid = false;
        $("input[name='" + $(this).attr("name") + "']").each(function(index) {
          if ($(this).filter(":checked").size()) {
            onevalid = true;
            return true;
          }
        });
        if (!onevalid) {
          $(this).parent().addClass("form-error");
        }
      } else {
        if ($(this).attr("regexp")) {
          //alert($(this).attr("regexp"));
          var regexp = new RegExp($(this).attr("regexp"));
          if (!regexp.test($(this).val())) {
            valid = false;
            $(this).parent().addClass("form-error");
          }
        } else {
          if (!$(this).val()) {
            valid = false;
            $(this).parent().addClass("form-error");
          }
        }
      }
    });
    if (!valid) {
      alert("Please make sure all form fields are properly filled out.");
      return false;
    } else {
      return true;
    }
  });
});
