// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
Event.observe(window, 'load', windowInit);

function windowInit() {
  addFormHighlighters();
}

// Highlights form elements when they receive focus
// Removes highlight when they're blurred
function addFormHighlighters() {
  $$('form').each( function(form) {
    form.getElements().each( function(e) {
      e.onfocus = function() {
        if (!isButton(this)) {
          this.addClassName('focused_form_element');
        }
      }
      e.onblur = function() {
        if (!isButton(this)) {
          this.removeClassName('focused_form_element');
        }
      }
    });
  });
}

function contactFormError(error_html) {
  $('contact_form_errors').update(error_html);
  $('contact_form_spinner').hide();
}

function isButton(element) {
  return (typeof(element.type) != undefined) && (element.type == 'button' || element.type == 'submit');
}