
/**
 * Toggle Table Row by Stanley Sy
 * Changes a TR's class to 'active' when it is clicked
 *
 * Requirements: prototype.lite.js
 * Use: Give the table id="stats-table"
 */
var activeRow;

function changeRowClass(o) {
	// If the clicked row is the existing row, but isn't highlighted
	if (o == activeRow && !Element.hasClassName(o,'active')) {
		Element.addClassName(o,'active');
		activeRow = o;
	} else {
		// If there's an existing current row
		if (activeRow != '') {
			// Remove existing current row
			Element.removeClassName(activeRow,'active');
		}
		// If the clicked row isn't the existing row
		if (o != activeRow) {
			Element.addClassName(o,'active');
			activeRow = o;
		}
	}
}

function toggleTableRow() {
	// grab the table, and each tbody in it.
	var tableObj = $('stats-table');
	var tBody = tableObj.getElementsByTagName('tbody');

	if (tBody) {
		var rows = tBody[0].getElementsByTagName('TR');
	} else {
		var rows = tableObj.getElementsByTagName('TR');
	}
	for(var i=0; i < rows.length; i++) {
		rows[i].onclick = function() { changeRowClass(this); };
	}
}

if(document.getElementById && document.getElementsByTagName) {
	addEvent(window, 'load', toggleTableRow);
}