// Highlights table row
// Paksy David
// Based on: F. Permadi 2005.Copyright (C) F. Permadi
// http://www.permadi.com/tutorial/cssHighlightTableRow/index.html


/////////////////////////////////////////////////////
// Highlight table row.
// myElement is the table row
// highlightColor is the color of the highlight
/////////////////////////////////////////////////////
function highlightTableRowVersionA(myElement, highlightColor) {	

	// If you don't want a particular row to be highlighted, set it's id to "header"
	if (!myElement || (myElement && myElement.id && myElement.id=="header") ) {
		return;
	}
	
	// The following code traverses every <td> within the <tr> and highlights it
	// by changing its style[backgroundColor] property
	if (myElement) {
		//var tableRow = myElement;

		// Since myElement is a <tr>, then find the first <td>.  
		// You'd think that the <td> is  going to be the 
		//   firstChild of the <tr>, but it's not always the case (it 
		//   depends on how the browser defines the DOM).
		var tableCell = findNode(myElement, "TD"); 

		var i=0;
		// Loop through every sibling.  Theoretically, a sibling of a <td> should be 
		//  another <td>, but this is not always the case on certain browsers, 
		//  so we need to check the tagName to be sure and skip to the next 
		//  sibling if the sibling is not a <td>)
		// We then highlight every siblings
		while (tableCell) {
			// Make sure it's actually a cell (a <td>)
			if (tableCell.tagName=="TD") {
				// If no style has been assigned, assign it, otherwise Netscape will behave weird.
				if (!tableCell.style) {
					tableCell.style={};
				}
				// Assign the highlight color
				tableCell.style["backgroundColor"]=highlightColor;

				// Optional: alter cursor
				tableCell.style.cursor='default';
				i++;
			}
			// Go to the next cell in the row
			tableCell=tableCell.nextSibling;
		}
	}
}

/////////////////////////////////////////////////////
// This function is used to find the first descendant with the specified tag name.
/////////////////////////////////////////////////////
function findNode(startingNode, tagName) {
	// on Firefox, the <td> node might not be the firstChild node of the <tr> node
	var myElement=startingNode;
	var i=0;
	while (myElement && (!myElement.tagName || (myElement.tagName && myElement.tagName!=tagName))) {
		myElement=startingNode.childNodes[i++];
	} 
	if (myElement && myElement.tagName && myElement.tagName==tagName) {
		return myElement;
	}
	// On Internet Explorer, the <tr> node might be the firstChild node of the <tr> node 
	else if (startingNode.firstChild) {
		return findNode(startingNode.firstChild, tagName);
	}
	return 0;
}
