/*

	Initialize
	- Use this function to add calls to all behaviour scripts used

*/

window.onload = function () {
	fn_stripe(); //Alternating table row colors
	fn_toggle(); //Show/hide stuff
	fn_filter();  //Filter
}

/*

	Shared scripts

*/

// Cookies, DOM, AJAX?, etc ..

/*

	Behaviour scripts
	- These are the scripts that do all the real work

*/

function fn_filter() {
	Element.hide("filter");
	$("tfilter").onclick = function() { Element.toggle("filter"); return false; }
}

function fn_toggle() {
	var fieldsets = document.getElementsByTagName("fieldset");
	for(var i=1;i < fieldsets.length;i++)
	{
		if (fieldsets[i].className == "toggle")
		{
			fieldsets[i].onclick = function() { this.className += " show"; return false; }
		}
 	}
}

function fn_stripe()
{
	var even = true;
	var tables = document.getElementsByTagName("table");
	for(var x=0;x!=tables.length;x++)
	{
		var table = tables[x];
		if (! table) return;
		var tbodies = table.getElementsByTagName("tbody");
		for (var h = 0; h < tbodies.length; h++)
		{
			var trs = tbodies[h].getElementsByTagName("tr");
			even = true;
			for (var i = 0; i < trs.length; i++)
			{
				trs[i].onmouseover = function() { this.className += " highlight"; return false; }
				trs[i].onmouseout = function() { this.className = this.className.replace("highlight", ""); return false; }

				if(even) trs[i].className += " stripe";

          		even = !even;
        	}
 		}
 	}
}
