/**
 * Add the class alt to every other row, as well as the class "highlight" to
 * rows onMouseOver.
 *
 * The alt class is added to even numbered rows when no parameters are
 * provided, and odd numbered rows when the passed parameter is true
 *
 * Parameters:
 * string tableClass - Add highlight functionality to tables with this class
 *                     Defaults to "addHighlight"
 * boolean altOdd - "alt" class is applied to add numbered rows if true.
 */
function highlightTable(tableClass, altOdd) {
	if (!document.getElementById || !document.createElement)
		return;

	tableClass = tableClass != null ? tableClass : 'addHighlight';
	altOdd = altOdd != null ? altOdd : false;

	for (i = 0; (table = document.getElementsByTagName('table')[i]); i++) {
		if (table.className.indexOf(tableClass) < 0)
			continue;

		highlightRow(table, altOdd);
	}
}

/**
 * Highlights a row on mouseOver
 */
function highlightRow(table, altOdd) {
	for (var i = 0; (row = table.getElementsByTagName('tr')[i]); i++) {
		row.onmouseover = function() { addClass(this, 'highlight'); };
		row.onmouseout = function() { removeClass(this, 'highlight'); };

		if ((!altOdd && i%2 == 0) || (altOdd && i%2 == 1))
			addClass(row, 'alt');

		highlightCell(table);
	}
}

/**
 * Highlights a table cell on mouseOver
 */
function highlightCell(row) {
	for (var i = 0; (cell = row.getElementsByTagName('td')[i]); i++) {
		cell.onmouseover = function() { addClass(this, 'highlight'); };
		cell.onmouseout = function() { removeClass(this, 'highlight'); };
	}
}