//
//	Function for highlighting rows.
//
var	currentRow = null;										// currently highlighted row
var	previousClass;											// the class that it was


function reset() {
	if (currentRow)											// is a previous row highlighted?
		currentRow.className = previousClass;				//	yes - restore it's lowlighted class
}

function ChangeCursor (theObject,action) {
   if (action == "over") 
	    theObject.style.cursor = "pointer"
	 else		 
	    theObject.style.cursor = "default"
}

function SetHighlightHand(thisRow) {							// Highlight this row
	if (currentRow)											// is a previous row highlighted?
		currentRow.className = previousClass;				//	yes - restore it's lowlighted class
    previousClass = thisRow.className;						// save the unhighlighted class
    currentRow = thisRow;									// and the row pointer
    thisRow.className = "Hilite";							// now highlight his row		
}

function SetHighlightNormal(thisRow) {							// Highlight this row
	if (currentRow)											// is a previous row highlighted?
		currentRow.className = previousClass;				//	yes - restore it's lowlighted class
    previousClass = thisRow.className;						// save the unhighlighted class
    currentRow = thisRow;									// and the row pointer
    thisRow.className = "HiliteNormal";							// now highlight his row		
}

function SetHighlightBooking(thisRow,CompanyID) {							// Highlight this row
	if (currentRow)											// is a previous row highlighted?
		currentRow.className = previousClass;				//	yes - restore it's lowlighted class
    previousClass = thisRow.className;						// save the unhighlighted class
    currentRow = thisRow;									// and the row pointer
   thisRow.className = "SecondaryColour"+CompanyID;		
}

function KeySetHighlight(hiline,theObject) {
	if (currentRow)											// is a previous row highlighted?
		currentRow.className = previousClass;				//	yes - restore it's lowlighted class	
  previousClass = theObject.rows[hiline].className;						// save the unhighlighted class
  currentRow = theObject.rows[hiline];									// and the row pointer
	currentRow.className = "HiliteLeft"; 						// now highlight his row
}

function SetHighlightLeft(thisRow) {							// Highlight this row
	if (currentRow)											// is a previous row highlighted?
		currentRow.className = previousClass;				//	yes - restore it's lowlighted class
    previousClass = thisRow.className;						// save the unhighlighted class
    currentRow = thisRow;									// and the row pointer
    thisRow.className = "HiliteLeft";							// now highlight his row
}

function showSQL(sqlContainer) {
   if (sqlContainer.style.display == "none") 
       sqlContainer.style.display="";
   else
       sqlContainer.style.display = "none";
}
function findElementNumberByTagName(source, eltype, start) {
//
//	Find the next element matching the spefified tag name
//
	var nochildren=source.childNodes.length;
	var theChildren = source.childNodes;
	for (childNumber = start; childNumber < nochildren; childNumber++) {
		if (theChildren.item(childNumber).nodeType == 1) {
			if (theChildren.item(childNumber).tagName == eltype) {
				return childNumber;						// Found the header
			}
		}
	}
	return null;										// Found nuttin'
}
function findElementByTagName(source, eltype) {
//
//	Find the first element matching the spefified tag name
//
	var foundElement = findElementNumberByTagName(source, eltype, 0);
	if (foundElement != null)
		return source.childNodes.item(foundElement);
	else
		return null;
}
function makeSameWidth(target, source) {
//
//	Make all of the elements in the target tree the same width as those in the source tree.
//	The target is a clone of the source
//
try {
	var	thisChild;
	var sourceChild;
	var targetChild;
	target.style.width = (source.offsetWidth-2)+"px";
	if (target.hasChildNodes()) {
		sourceChild = -1;
		for (thisChild = 0; thisChild < target.childNodes.length; thisChild++) {
			targetChild = target.childNodes.item(thisChild);
			if (targetChild.nodeType == 1 && targetChild.tagName.substring(0,1) == "T") {
				sourceChild = findElementNumberByTagName(source, targetChild.tagName, sourceChild+1);
				if (sourceChild == null)			// No matching child?
					break;							// stop
//				alert(targetChild.tagName+"("+targetChild.offsetWidth+") -> "+source.childNodes.item(sourceChild).offsetWidth);
				makeSameWidth(targetChild, source.childNodes.item(sourceChild));
			}
		}
	}
} catch(err) {
//	alert(err);
}
}
var ttop = 0;												// This is the top of the table
var tbl = null;												// The table
var newtable = null;										// the header table
function resizeTable() {									// called when table is resized
	if (tbl != null && newtable != null)					// Are both items present?
		makeSameWidth(newtable, tbl.obj);					// yes - resize the header to match the table
}						
function fixTableHeader(tableID) {
//
//	Make the nominated table header fixed by cloning the header from the table (THEAD) into
//	a fixed position table superimpoded over the original table header.
//	Note:
//	If the table is not placed at the absolute top of it's window with no margin then the table
//	contents will scroll up past the fixed table header.
//
//  SortableTable.apply( document.getElementById(tableID) );
	tbl = new DOMObject(tableID);
  if (!tbl)													// Does the table exist?
  	return;													// no
	var oldheader = findElementByTagName(tbl.obj, "THEAD");	//	look for the <thead> in the main table
	var oldheaderObj = new DOMObject(oldheader);
	if (!oldheader)											// If there is no table header
		return;												// then we can't position it
	newtable = tbl.obj.cloneNode(false);					// clone the table without children
	var newheader = oldheader.cloneNode(true);				// clone the header and its children
	newtable.appendChild(newheader);						// and append it to the heading table
	newtable.style.left = tbl.getLeft() + "px";				// Move the new table over the old
	newtable.style.top = tbl.getTop() + "px";				//	Note that top shoud be 0 (see above)
	if (document.all)										// IE doesn't handle fixed objects
		newtable.style.position = "absolute";				// so make it absolute and move it with the window
	else
		newtable.style.position = "fixed";					// NS & MZ make it easier
	makeSameWidth(newtable, tbl.obj);						// Make all the copied headings the same width
	tbl.obj.onresize = "resizeTable();";					// allow table to resize on window resize
	newtable.removeAttribute("id");							// ensure there are no duplicate ID's
	newtable.className = "HideReportTitle"
	var oldheaderObj = new DOMObject(oldheader);			// make an object for the old THEAD
	oldheaderObj.removeAllAttributes("id");					// and remove all IDs from the old THEAD
	oldheaderObj.removeAllAttributes("name");				// as well as names
	try {
		document.body.insertBefore(newtable, tbl.obj);		// place the new table before the original
	} catch(err) {
//		alert(err);
	}
	if (document.all) {										// If this is IE then use setExpression
		ttop = tbl.getTop();								// to move the headings (not so hard)
		newtable.style.setExpression("top", "document.body.scrollTop+ttop");
	}
	
}
function sizeToTable() {
	document.getElementById("loading").style.display="none";
	var tbSize = getEltHeight(document.getElementById("BD"));
	var tbTop = getEltPageTop(document.getElementById("BD"));
	var pgSize = document.body.clientTop + tbSize + tbTop + 17;
	window.resizeBy(0, pgSize - getCurrentWinHeight());
	if ((window.parent == window.self) && getCurrentWinHeight() > window.screen.availHeight)
		window.resizeBy(0, window.screen.availHeight - getCurrentWinHeight());
}

function HighlightCell(theObject, option) {
   if (theObject.className != "critical") {
      if (option == 0) 
 		     theObject.className = "DrawTopLine";
	    else 
 			    theObject.className = "CellAttention";
	 }		    
}

function SetMyHighlight (theObject) {
   if (thePrevObject != -1)
	    thePrevObject.className = "DrawTopLine";
	 theObject.className = "critical";		 
   thePrevObject = theObject;

}

/*function DisplayIFrame(AuditID,theObject) {
   oDiv=new lib_obj('JobDiv')
	 oDiv.showIt();
	 oDiv.dragdrop();
	 if (document.all)
  //    oDiv.moveIt(200,event.srcElement.offsetTop)
	    oDiv.moveIt(200,document.body.scrollTop+40)  		// frametop + 100 = center frame 
	 else	
  //		  oDiv.moveIt(200,event.pageY)
	        oDiv.moveIt(200,window.pageYOffset+40)				// frametop + 100 = center frame 
	 theIFrame = "../Jobs/AJob.php?Restrict=true&AuditID="+AuditID+
	             "&RowNumber="+theObject.rowIndex+
							 "&ClassName="+previousClass+
							 "&test=true";
	 window.open(theIFrame, "JobCheckFrame");
}
*/


