window.onload=highlightTableRow;
function setRowBackground( row, color) {
	if ( row.highlighted) return;
	var cell;
	var cells = row.getElementsByTagName( "td");
	for( var i=0; i< row.cells.length; i++) {
		cell = cells[i];
		if ( !cell) continue;
		if ( color) {
			if ( !cell.originalColor) {
				cell.originalColor = cell.style.backgroundColor?cell.style.backgroundColor:"undefined";
			}
			cell.style.backgroundColor=color;
		} else {
			cell.style.backgroundColor = cell.originalColor=="undefined"?"":cell.originalColor;
		}
	}
}

function highlightRow( row) {
	var cells = row.getElementsByTagName( "td");
	if ( row.highlighted) {
		for( var i=0; i< row.cells.length; i++) {
			cell = cells[i];
			if ( !cell) continue;
			cell.style.backgroundColor = cell.originalColor=="undefined"?"":cell.originalColor;
		}
		row.highlighted = false;
	} else {
		for( var i=0; i< row.cells.length; i++) {
			cell = cells[i];
			if ( !cell) continue;
			if ( !cell.originalColor) {
				cell.originalColor = cell.style.backgroundColor?cell.style.backgroundColor:"undefined";
			}
			cell.style.backgroundColor = "yellow";
		}
		row.highlighted = true;
	}
}

function highlightTableRow(){
	var i,j,tables,rows;
	tables = document.getElementsByTagName('table');
	for( i=0; i< tables.length; i++) {
		if ( tables[i].className == 'list' || tables[i].className == 'widelist' ) {
			rows = tables[i].rows;
			for( j=1; j< rows.length; j++) { // first row is the header, skip
				if ( rows[j].cells[0].className == 'fieldlabel') continue;
				rows[j].onmouseover = function(){ setRowBackground( this, "lightgreen");};
				rows[j].onmouseout  = function(){ setRowBackground( this, null);};
				rows[j].onclick     = function(){ highlightRow( this);};
			}
		}
	}
}

