// Focus() on the first field in the first form found with a class of 'focus_first'.
document.observe("dom:loaded", function() {
  var firstForm = document.getElementsByClassName('focus_first')[0];
  if (firstForm) {
    Form.focusFirstElement(firstForm);
  }
		
  var delete_forms = document.getElementsByClassName('delete_form')
  if(delete_forms.length > 0) {
    delete_forms.invoke('observe', 'submit', function(e){
      return confirm("Are you sure you want to delete this?");      
    });
  }		
});


// Given an element, checks all the check boxes in it.
function check_all_by_class(klass, action) {
  var checkboxes = document.getElementsByClassName(klass);
  checkboxes.each(function(checkbox) {
    if (action == 'check') { checkbox.checked = true; }
    if (action == 'uncheck') { checkbox.checked = false;}
  });	
}


// Sets all visible Flash messages to display: none.
function hideFlash() {
  document.getElementsByClassName('message').invoke('hide');
}



/*
// Color the background of the active input field:
Event.observe(window, 'load',
	function() {
		// Get all the input fields.
		var fields = $A(document.getElementsByTagName('input'));
		fields = fields.concat($A(document.getElementsByTagName('textarea')));
		fields.each( function(field) {
			Event.observe(field, 'focus', function(){this.style.backgroundColor = 'black';});
		}
		
	);
		
	}

);
*/
