var validateDelivery = function(evt) {
  elemsWithErrors.each(clearErrorArray);
  elemsWithErrors = elemsWithErrors.compact();
  if ($F("customer").blank()) {
    handleError("customer", "Please enter your company name.", true);
  } else if ( $F( "contact" ).blank() ) {
    handleError("contact", "Please enter the contact name.", true);
  } else if ($F("addr").blank()) {
    handleError("addr", "Please enter your address.", true);
  } else if ($F("city").blank()) {
    handleError("city", "Please enter your city.", true);
  } else if ($F("state").blank()) {
    handleError("state", "Please enter your state.", true);
  } else if ($F("zip").blank()) {
    handleError("zip", "Please enter your postal code.", true);
  } else if (!zipRegex1.test($F("zip")) &&
             !zipRegex2.test($F("zip"))) {
    handleError("zip", "Please enter your postal code in the format ##### or #####-####.", true);
  } else if ($F("email").blank()) {
    handleError("email", "Please enter your email address.", true);
  } else if (!emailRegex.test($F("email"))) {
    handleError("email", "Please enter a valid email address.", true);
  } else if ($F("delivery_address").blank()) {
    handleError("delivery_address", "Please enter the delivery address.", true);
  } else if ($F("delivery_city").blank()) {
    handleError("delivery_city", "Please enter the delivery city.", true);
  } else if ($F("delivery_state").blank()) {
    handleError("delivery_state", "Please select the delivery state.", true);
  } else if ($F("delivery_date").blank()) {
    handleError("delivery_date", "Please enter the delivery date.", true);
  } else if (!dateRegex.test($F("delivery_date"))) {
    handleError("delivery_date", "Please enter the delivery date in the format MM/DD/YYYY.", true);
  } else if ($F("lease_term").blank() ||
             $F("lease_term") == '[ Enter Purchase To Buy ]') {
    handleError("lease_term", "Please enter the lease term.", true);
  } else if (!$("dol").checked && !$("dof").checked) {
    handleError("config", "Please select the door configuration (DOL or DOF).", false);
  } else {
    return true;
  }
  evt.stop();
  return false;
}
Event.observe(window, "load", function() {
  $("submitBtn").observe("click", validateDelivery.bindAsEventListener());
  $("lease_term").observe("focus", function() {
    if ($F("lease_term") == "[ Enter Purchase To Buy ]") {
      $("lease_term").clear();
    }
  });
  Calendar.setup({
    dateField      : "delivery_date",
    triggerElement : "delivery-date-cal"
  });
});