var savedStates=new Array();
var savedStateCount=0;

function table_saveBackground(myElement)
{
	saved=new Object();
	saved.element=myElement;
	saved.className=myElement.className;
	saved.backgroundColor=myElement.style["backgroundColor"];
	return saved;   
}

function table_restoreBackground(savedState)
{
	savedState.element.style["backgroundColor"]=savedState.backgroundColor;
	if (savedState.className)
	{
		savedState.element.className=savedState.className;    
	}
}

function table_findNode(startingNode, tagName)
{
	// on Firefox, the TD node might not be the firstChild node of the TR node
	myElement=startingNode;
	var i=0;
	while (myElement && (!myElement.tagName || (myElement.tagName && myElement.tagName!=tagName)))
	{
		myElement=startingNode.childNodes[i];
		i++;
	}  
	if (myElement && myElement.tagName && myElement.tagName==tagName)
	{
		return myElement;
	}
	// on IE, the TD node might be the firstChild node of the TR node  
	else if (startingNode.firstChild)
		return table_findNode(startingNode.firstChild, tagName);
	return 0;
}


function table_track(mEvent, highlightColor)
{
	if (!mEvent)
		mEvent=window.event;
	
	// Internet Explorer
	if (mEvent.srcElement)
	{
		table_highlightRow( mEvent.srcElement, highlightColor);
	}
	// Netscape and Firefox
	else if (mEvent.target)
	{
		table_highlightRow( mEvent.target, highlightColor);		
	}
}

function table_highlightRow(myElement, highlightColor)
{
	var i=0;
	// Restore color of the previously highlighted row
	for (i; i<savedStateCount; i++)
	{
		table_restoreBackground(savedStates[i]); 
	}
	savedStateCount=0;
	
	// To get the node to the row (ie: the <TR> element), 
	// we need to traverse the parent nodes until we get a row element (TR)
	// Netscape has a weird node (if the mouse is over a text object, then there's no tagName
	while (myElement && ((myElement.tagName && myElement.tagName!="TR") || !myElement.tagName))
	{
		myElement=myElement.parentNode;
	}
	if (!myElement || (myElement && myElement.id && myElement.id=="header") )
		return;
	
	if (myElement)
	{
		var tableRow=myElement;
	
		if (tableRow)
		{
			savedStates[savedStateCount]=table_saveBackground(tableRow);
			savedStateCount++;
		}
	
		var tableCell=table_findNode(myElement, "TD"); 
		
		var i=0;
		while (tableCell)
		{
			if (tableCell.tagName=="TD")
			{
				if (!tableCell.style)
				{
					tableCell.style={};
				}
				else
				{
					savedStates[savedStateCount]=table_saveBackground(tableCell); 
					savedStateCount++;
				}
				tableCell.style["backgroundColor"]=highlightColor;
				i++;
			}
			tableCell=tableCell.nextSibling;
		}
	}
}
