<!-- Begin

/*******************************************************************************
 *	From 'DHTML Utopia: Modern Web Design' by Stuart Langridge
 *	Chapter 3, page 68
 ******************************************************************************/
 
//	Climb up the tree to the supplied tag.
function ascendDOM( el, target ) {
	try 
	{
		while (	el.nodeName.toLowerCase() != target &&
				el.nodeName.toLowerCase() != 'html')
			el = el.parentNode;
	
		return (el.nodeName.toLowerCase() == 'html') ? null : el;
	}
	catch (error) 
	{
		//  Error: Probably el = null
		alert( 'This shouldn\'t happen: ascendDOM: Looking for "' + target + '" current el is "' + el + '".  Error was: ' + error);
		return null;
	}
}

//	Turn ON highlighting
function hi_cellByEvent(e) {
	var el;
	if (window.event && window.event.srcElement)
		el = window.event.srcElement;
	if (e && e.target)
		el = e.target;
	if (!el) return 'el was undefined';
	
	hi_cellByElement( el );
}

//	Turn ON highlighting for row + column
function hi_cellByElement(el) {
	el = ascendDOM( el, 'td' );
	if (el == null) return 'el was null';
	
	var parent_row = ascendDOM( el, 'tr' );
	if (parent_row == null) return 'parent row was null';
	
	var parent_table = ascendDOM( parent_row, 'table');
	if (parent_table == null) return 'parent table was null';
	
	
	//	row styling
	parent_row.className += ' hi';
	
	//	column styling
	var ci = -1;
	for (var i = 0; i < parent_row.cells.length; i++ ) {
		if (el === parent_row.cells[i]) {
			ci = i;
		}
	}
	if (ci == -1) return 'ci was -1'; // this should never happen
	
	for (var i = 0; i < parent_table.rows.length; i++ ) {
		var cell = parent_table.rows[i].cells[ci];
		cell.className += ' hi';
	}
	return 'success';
}

//	Turn ON highlighting for column
//	el is an element in a TD tag
function hi_colByElementTD(el) {
	el = ascendDOM( el, 'td' );
	if (el == null) return 'el was null';
	hi_colByCellElement( el );
}

//	Turn ON highlighting for column
//	el is an element in a TH tag
function hi_colByElementTH(el) {
	el = ascendDOM( el, 'th' );
	if (el == null) return 'el was null';
	hi_colByCellElement( el );
}

//	Turn ON highlighting for column
//	el is a TD or TH element
function hi_colByCellElement(el) {
	el.className += ' hi';

	var parent_row = ascendDOM( el, 'tr' );
	if (parent_row == null) return 'parent row was null';
	
	var parent_table = ascendDOM( parent_row, 'table');
	if (parent_table == null) return 'parent table was null';
	
	//	column styling
	var ci = -1;
	for (var i = 0; i < parent_row.cells.length; i++ ) {
		if (el === parent_row.cells[i]) {
			ci = i;
		}
	}
	if (ci == -1) return 'ci was -1'; // this should never happen
	
	for (var i = 0; i < parent_table.rows.length; i++ ) {
		var cell = parent_table.rows[i].cells[ci];
		cell.className += ' hi';
	}
	return 'success';
}



//	LO BY CELL
//	Turn OFF highlighting by Event
function lo_cellByEvent(e) {
	var el;
	if (window.event && window.event.srcElement)
		el = window.event.srcElement;
	if (e && e.target)
		el = e.target;
	if (!el) return;
	
	lo_cellByElement( el )
}

//	Turn OFF highlighting by Element
//	el is a TD or TH element
function lo_cellByElement(el) {
	el = ascendDOM( el, 'td' );
	if (el == null) return;
	
	var parent_row = ascendDOM( el, 'tr');
	if (parent_row == null) return;
	
	var parent_table = ascendDOM( parent_row, 'table');
	if (parent_table == null) return;
	
	//	row de-styling
	parent_row.className = parent_row.className.replace(/\b ?hi\b/, '');
	
	//	column de-styling
	var ci = el.cellIndex;
	for (var i = 0; i < parent_table.rows.length; i++ ) {
		var cell = parent_table.rows[i].cells[ci];
		cell.className = cell.className.replace(/\b ?hi\b/, '');
	}
}
//	Turn OFF highlighting by Element
//	el is a TD or TH element
function lo_cellOnlyByElement(el) {
	el = ascendDOM( el, 'td' );
	if (el == null) return;
	el.className = el.className.replace(/\b ?hi\b/, '');
	//alert( 'el.className = ' + el.className );
}

//	LO BY COLUMN
//	Turn OFF highlighting by TD
function lo_colByElementTD(el) {
	el = ascendDOM( el, 'td' );
	if (el == null) return;
	lo_colByElement(el);
}
//	Turn OFF highlighting by TH
function lo_colByElementTH(el) {
	el = ascendDOM( el, 'th' );
	if (el == null) return;
	lo_colByElement(el);
}
//	Turn OFF highlighting by Element
//	el is a TD or TH element
function lo_colByElement(el) {
	var parent_row = ascendDOM( el, 'tr');
	if (parent_row == null) return;
	
	var parent_table = ascendDOM( parent_row, 'table');
	if (parent_table == null) return;
		
	//	column de-styling
	var ci = el.cellIndex;
	for (var i = 0; i < parent_table.rows.length; i++ ) {
		var cell = parent_table.rows[i].cells[ci];
		cell.className = cell.className.replace(/\b ?hi\b/, '');
		//alert( cell.className );
	}
}



// End -->
