// JavaScript Document

// workaround function for IE weirdness
function hasClass(obj)
{
	 var result = false;
	 if (obj.getAttributeNode("class") != null)
	 {
			 result = obj.getAttributeNode("class").value;
	 }
	 return result;
}   

// function to display rows of a table with alternating backgrounds (stripes).
// call function with the ID of the table, plus the even/odd colors to use (optional).
function stripeTable(id)
{
	var even = false;

	// if arguments are provided to specify the colors of the even & odd rows, then use the them;
	// otherwise use the following defaults:
	var evenColor = arguments[1] ? arguments[1] : "#000000";
	var oddColor = arguments[2] ? arguments[2] : "#555555";

	// obtain a reference to the desired table if no such table exists, abort
	var table = document.getElementById(id);
	if (!table) { return; }
	
	// by definition, tables can have more than one tbody
	// element, so we'll have to get the list of child tbodys
	var tbodies = table.getElementsByTagName("tbody");

	// and iterate through them...
	for (var h = 0; h < tbodies.length; h++)
	{
		// find all the tr elements... 
		var trs = tbodies[h].getElementsByTagName("tr");
		
		// ... and iterate through them
		for (var i = 0; i < trs.length; i++)
		{
			// avoid rows that have a class attribute or backgroundColor style
			if (! hasClass(trs[i]) && ! trs[i].style.backgroundColor)
			{
				// get all the cells in this row...
				var tds = trs[i].getElementsByTagName("td");
			
				// and iterate through them...
				for (var j = 0; j < tds.length; j++)
				{
					var mytd = tds[j];

					// avoid cells that have a class attribute or backgroundColor style
					if (! hasClass(mytd) && ! mytd.style.backgroundColor)
					{
						mytd.style.backgroundColor = even ? evenColor : oddColor;
					}
				}
			}
			// flip from odd to even, or vice-versa
			even = !even;
    }
  }
}

// similar to stripeTable, but to display list items in a list with alternating text color.
// call function with the ID of the list (ul or ol), plus the even/odd colors to use (optional).

function stripeList(id)
{
	var even = false;

	// if arguments are provided to specify the colors of the even & odd items, then use the them;
	// otherwise use the following defaults:
	var evenColor = arguments[1] ? arguments[1] : "#fff";
	var oddColor = arguments[2] ? arguments[2] : "#eee";

	// obtain a reference to the desired list; if no such list exists, abort
	var list = document.getElementById(id);
	if (!list) { return; }
	
	// get the list of children (li)
	var listitems = list.getElementsByTagName("li");

	// and iterate through them...
	for (var h = 0; h < listitems.length; h++)
	{
		var myitem = listitems[h];
		// avoid items that have a class attribute or assigned style we are setting
		if (! hasClass(myitem) && ! myitem.style.color)
		{
			myitem.style.color = even ? evenColor : oddColor;
		}
		// flip from odd to even, or vice-versa
		even = !even;
	}
}
