// define behavior to highlight field on focus
function IsArray(obj) {
  return obj instanceof Array;
}

var FieldFocus = Behavior.create({
  onfocus:function() {
    this.element.addClassName('field-focus');
  },
  onblur:function() {
    this.element.removeClassName('field-focus');
  }
});

// add behavior to form fields
function AddFieldFocus(input) {
  // init list
  var list = [];
  
  // check input, can be either array of form ids or an element id
  // if neither, default to all forms in document
  if (IsArray(input)) {
    list = input;
  } else if (input != '' && (input = $(input))) {
    list = $A(input.getElementsByTagName('form'));
  } else {
    list = $A(document.getElementsByTagName('form'));
  }
  
  // add behavior
  list.each(function(form) {
    if (form = $(form)) {
      $A(form.getElements()).each(function(e) {
        var types = ['text', 'textarea', 'select-one', 'select-multiple', 'password'];
        if (types.indexOf(e.type) >= 0) {
          FieldFocus.attach(e);
        }
      });
    }
  });
}