var validateQuote = function(evt) {
  elemsWithErrors.each(clearErrorArray);
  elemsWithErrors = elemsWithErrors.compact();
  if ($F("customer").blank()) {
    handleError("customer", "Please enter the customer 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("phone").blank()) {
    handleError("phone", "Please enter the contact phone number.", true);
  } else if (!phoneRegex1.test($F("phone")) &&
             !phoneRegex2.test($F("phone")) &&
             !phoneRegex3.test($F("phone")) &&
             !phoneRegex4.test($F("phone"))) {
    handleError("phone", "Please enter the contact phone number in the format (###)###-####.", true);
  } else if (!$F("fax").blank() &&
             !phoneRegex1.test($F("fax")) &&
             !phoneRegex2.test($F("fax")) &&
             !phoneRegex3.test($F("fax")) &&
             !phoneRegex4.test($F("fax"))) {
    handleError("fax", "Please enter the fax number in the format (###)###-####.", true);
  } else if ($F("email").blank()) {
    handleError("email", "Please enter the contact email address.", true);
  } else if (!emailRegex.test($F("email"))) {
    handleError("email", "Please enter a valid contact email address.", true);
  } else if ($F("delivery_address").blank()) {
    handleError("delivery_address", "Please enter the delivery address.", true);
  } else if ($F("city").blank()) {
    handleError("city", "Please enter the delivery city.", true);
  } else if ($F("state").blank()) {
    handleError("state", "Please enter the delivery state.", true);
  } else if ($F("zip").blank()) {
    handleError("zip", "Please enter the delivery postal code.", true);
  } else if (!zipRegex1.test($F("zip")) &&
             !zipRegex2.test($F("zip"))) {
    handleError("zip", "Please enter the delivery postal code in the format ##### or #####-####.", 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("num_units").blank()) {
    handleError("num_units", "Please enter the number of units.", 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 ($F("container_type").blank()) {
    handleError("container_type", "Please enter the container type.", true);
  } else {
    return true;
  }
  evt.stop();
  return false;
}
Event.observe(window, "load", function() {
  $( "submitBtn" ).observe("click", validateQuote.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"
  });
});