// Highlight the active row script

function HighlightActiveRow( tableIdName, highlightedClassName, eventList) {

	this.containerId            = tableIdName;
	this.tableElement           = document.getElementById(tableIdName);
	this.highlightedClassName   = highlightedClassName;
	this.selectedRow;
	this.selectedRowOriginalClass;
	
	if( this.tableElement == null ) {
		return false;
	}
		

	var copyOfThis = this;	
	var action 	= 	function( e ) {
						if( e == null ) {
							e = this.tableElement.ownerDocument.parentWindow.event;
						}
						copyOfThis.mouseover(e);
					}

	if (this.tableElement.addEventListener) {
		for( i=0; i< eventList.length; i++ ) {
			this.tableElement.addEventListener(eventList[i], action, false);
		}
	}

	else if (this.tableElement.attachEvent) {
	    for( i=0; i< eventList.length; i++ ) {
			eventName = "on" + eventList[i];
			this.tableElement.attachEvent(eventName, action);
		}
	}
	
	return;
	
}

HighlightActiveRow.prototype.mouseover = function( e ) {
	
	var el;
	if( e.target != null ) {
		el = e.target;
	}
	else {
		el = e.srcElement;
	}
	
	while ( el != null && el.nodeType!=1 && el.parentNode!=this.tableElement ) {
		el = el.parentNode;
	}
	
	if(el == this.tableElement) {
		return false;
	}

	rowEl = this.getCurrentRow(el);
	
	
	if( rowEl == null ) {
		return false;
	}
	
	if( rowEl == this.selectedRow ) {
		return false;
	}
	

	if( this.selectedRow ) {
		this.selectedRow.className = this.selectedRowOriginalClass;
	}
	

	this.selectedRow              = rowEl;
	this.selectedRowOriginalClass = rowEl.className;	

	rowEl.className = this.highlightedClassName;
	return;
	
}

HighlightActiveRow.prototype.getCurrentRow = function(el) {

	while ( el != null && el.parentNode.parentNode.id!=this.containerId && el.parentNode != null) {
		el = el.parentNode;

	}	
	
	return el;
}


