var ContactUs = {
  init : function() {
    ContactUs.initForm("contactus_form").focusFirstElement();
    ContactUs.initPhoneField("contact_phone1", "contact_phone2");
    ContactUs.initPhoneField("contact_phone2", "contact_phone3");
    ContactUs.initPhoneField("contact_phone3", "contact_email");
    if(window.location.href.include("#thankyou")) {
      $("thankyou_feedback").show();
    }
  },
  initForm : function(form) {
    form = $(form);
    Event.observe(form, "submit", ContactUs.formSubmit);
    return form;
  },
  initPhoneField : function(field, next) {
    field = $(field);
    new Form.Element.Observer(field, 0.1, function(el, value) {
      if(value.length >= el.getAttribute("maxlength")) {
        $(next).focus();
      }
    });
    return field;
  },
  formSubmit : function(e) {
    var error = false;
    if(!$F("contact_email")) {
      $("contact_email").addClassName("form-error");
      $("form_error_for_contact_email").update("Please enter your email address.").show();
      error = true;
    }
    if(!$F("contact_comments")) {
      $("contact_comments").addClassName("form-error");
      $("form_error_for_contact_comments").update("Please enter your comments here.").show();
      error = true;
    }
    if(error) Event.stop(e);
  }
};
