// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function updateRowShading(selector) {
	rows = $$(selector);
	x = 0;

	rows.each(function(row){

		if(x % 2 == 0) {
			row.removeClassName('odd');
			row.addClassName('even');
		}
		else {
			row.removeClassName('even');
			row.addClassName('odd');
		}

		x += 1;
	});
}


/* Simple class for setting up and tearing down inline editing widgets */

var GhettoInlineEditor = {
	create: function(id) {
		$(id+'_edit').hide();
		Event.observe(id,'mouseover',function(){$(id).addClassName('inlineedit')},false);
		Event.observe(id,'mouseout',function(){$(id).removeClassName('inlineedit')},false);
		Event.observe(id,'click',function(){GhettoInlineEditor.activate(id)},false);
	},
	activate: function(id){
		$(id).hide();
		$(id+'_edit').show();
		$(id+'_field').focus();
	},
	cancel: function(id){
		$(id).show();
		$(id+'_edit').hide();
	},
	cancelAndClear: function(id){
		this.cancel(id);
		$(id+'_field').value = '';
	}
}


/* These are deprecated functions for doing the exact same thing as the GhettoInlineEditor class below */

function makeGhettoInlineEditor(id){
	//alert('id');
	$(id+'_edit').hide();
	Event.observe(id,'mouseover',function(){$(id).addClassName('inlineedit')},false);
	Event.observe(id,'mouseout',function(){$(id).removeClassName('inlineedit')},false);
	Event.observe(id,'click',function(){activateInlineEdit(id)},false);
}

function activateInlineEdit(id) {
	$(id).hide();
	$(id+'_edit').show();
	$(id+'_field').focus();
}

function cancelInlineEdit(id) {
	$(id).show();
	$(id+'_edit').hide();
}

function cancelInlineEditAndClear(id) {
	$(id).show();
	$(id+'_edit').hide();
	$(id+'_field').value = '';
}