function setBackground (field, fragRoot) {}  // Function to change the background image of the google text field when appropriate TT:Google image was killed

/*
//THT: Depretiated: Making more robust search scripts
var searchControl;
var drawOptions;	
// NOTE: this only works if the google search script is included before this script
function OnLoad() {
	// SR: Create a search control
	searchControl = new google.search.SearchControl();

	// SR: site restricted web search with custom label and class suffix
	var siteSearch = new GwebSearch();
	siteSearch.setUserDefinedLabel("Thiess");
	siteSearch.setUserDefinedClassSuffix("siteSearch");
	siteSearch.setSiteRestriction("thiess.com.au");

	// SR: set default to show expanded version and add searcher to search control
	var options = new GsearcherOptions();
	options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
	searchControl.addSearcher(siteSearch, options);

	// SR: set the draw mode for the Google search and set the input field (instead of the default one)
	drawOptions = new GdrawOptions();
	drawOptions.setInput(document.getElementById("googleSearchTextField"));
	
	// SR: parse the search term from the URL
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	
	if(urlHalves[1]){
		//load all the name/value pairs into an array
		var urlVars = urlHalves[1].split('&');
		//loop over the list, and find the specified url variable
		for(i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){
				//load the name/value pair into an array
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0] == 'searchTerm') {
					document.getElementById('googleSearchTextField').value = unescape(urlVarPair[1]);
					googleSearch('button');
				}
			}
		}
	}
}
*/


// =========================================================================================================================
// ===================== WWW_MENU_BAR Class ============================================================================
function WWW_MENU_BAR (strInstanceName, strCgiPath, strAssetsPath, strShowHome) {
	this.m_InstanceName = strInstanceName;
	this.m_CgiPath		= strCgiPath;
	this.m_AssetsPath	= strAssetsPath;
	this.m_ShowHome	    = false;
	if (strShowHome != null && strShowHome == 'true')
		this.m_ShowHome = true;

	this.m_src_Space = strAssetsPath + 'space.gif';
	this.m_HeaderTableId = strInstanceName + '_HeaderTable';
	this.m_HeaderMenuId  = strInstanceName + '_HeaderMenu';
	this.m_selectedElements = new Array(0);
	this.m_ds = new Array();
	this.m_di = 0;

	// primary display
	WWW_MENU_BAR.prototype.Display 	= WWW_MENU_BAR_Display;
	WWW_MENU_BAR.prototype.DisplayNode 	= WWW_MENU_BAR_DisplayNode;
	// content page generation
	WWW_MENU_BAR.prototype.OpeningHtml = WWW_MENU_BAR_OpeningHtml;
	WWW_MENU_BAR.prototype.CoreHtml 	= WWW_MENU_BAR_CoreHtml;
	WWW_MENU_BAR.prototype.ClosingHtml 	= WWW_MENU_BAR_ClosingHtml;
	// runtime support
	WWW_MENU_BAR.prototype.topCollectionItem_mouseover	= WWW_MENU_BAR_topCollectionItem_mouseover;
	WWW_MENU_BAR.prototype.topCollectionItem_mouseout	= WWW_MENU_BAR_topCollectionItem_mouseout;
	WWW_MENU_BAR.prototype.childCollectionItem_mouseover = WWW_MENU_BAR_childCollectionItem_mouseover;
	WWW_MENU_BAR.prototype.childCollectionItem_mouseout   = WWW_MENU_BAR_childCollectionItem_mouseout;
	WWW_MENU_BAR.prototype.highlightItem			= WWW_MENU_BAR_highlightItem;
	WWW_MENU_BAR.prototype.unhighlightItem			= WWW_MENU_BAR_unhighlightItem;
	WWW_MENU_BAR.prototype.linkItem_mouseover		= WWW_MENU_BAR_linkItem_mouseover;
	WWW_MENU_BAR.prototype.linkItem_mouseout		= WWW_MENU_BAR_linkItem_mouseout;
	WWW_MENU_BAR.prototype.topCollectionItem_onclick	= WWW_MENU_BAR_topCollectionItem_onclick;
	WWW_MENU_BAR.prototype.childCollectionItem_onclick	= WWW_MENU_BAR_childCollectionItem_onclick;
	WWW_MENU_BAR.prototype.linkItem_onclick			= WWW_MENU_BAR_linkItem_onclick;
	WWW_MENU_BAR.prototype.closeChildMenusOf		= WWW_MENU_BAR_closeChildMenusOf;
	WWW_MENU_BAR.prototype.closeOpenSiblingsOf		= WWW_MENU_BAR_closeOpenSiblingsOf;
	WWW_MENU_BAR.prototype.setMenuDisplayStatus		= WWW_MENU_BAR_setMenuDisplayStatus;
	WWW_MENU_BAR.prototype.resetMenus				= WWW_MENU_BAR_resetMenus;
}

function WWW_MENU_BAR_Display(node) {
	this.m_ds[this.m_di++] =
		'<table id="' + this.m_HeaderTableId + '" class="www_HeaderMenuTable" border="0" cellspacing="0" cellpadding="0">' +
		'	<tr>' +
		'	<td id="ww_headSpacer">' +
		'	<td id="' + this.m_HeaderMenuId + '" class="www_HeaderMenuCell">' +
		'		<table width=100%  height=100%  border="0" cellpadding="0" cellspacing="0">\n' +
		'			<tr style="text-align: center;">\n';
	this.DisplayNode(node);		// recursive walk...
	this.m_ds[this.m_di++] =
		'			</tr>\n' +
		'		</table>' +
		' 	</td>' +
		'	</tr>' +
		'</table>\n';

	document.write(this.m_ds.join(''));
}

function WWW_MENU_BAR_DisplayNode (parentElement, parentPath) {
	// Create a variable containing all children of the passed-in element.
	var childList = parentElement.m_subNodes;

	// Call the function that generates the opening html code for a collection (the generated code will typically be an opening <div> tag that will act as a container for the collection).
	this.OpeningHtml(parentElement);

	if (parentElement.m_level == 0 && this.m_ShowHome)
		this.CoreHtml(parentElement, parentPath);

	// Loop through the children of the passed-in element. For each child, run the core html function,
	// and if that child has children of its own, recursively call the DisplayNode function.

	for (var i=0; i<childList.length; i++) {
		var childNode = childList[i];
		var nodepath  = "";

		if (parentPath) 	{
			nodePath = parentPath + "." + i;
		} else {
			nodePath = i.toString();
		}
		this.CoreHtml(childNode, nodePath);
		if (childNode.m_subNodes.length > 0) 	{
			this.DisplayNode(childNode, nodePath);
		}
	}
	/* Call the function that generates the closing html code for a collection (the generated	code will typically be a closing </div> tag for the collection container).*/
	this.ClosingHtml(parentElement);
}

// ============== Page Data Generation functions ========================
function WWW_MENU_BAR_OpeningHtml(parentElement) {
	var level = parentElement.m_level;
	if (level == 0)  {    // Home node

	} else  {
		// Child menu items
		var divClass = "www_SubChildCollectionContainer";
		var tableClass = "www_SubChildListTable";

		if (level == 1)  { // Top-level menu items
			divClass = "www_TopChildCollectionContainer";
			tableClass = "www_TopChildListTable";
		}
		this.m_ds[this.m_di++] =
			'<div class="' + divClass+ '" style="display:none">\n' +
			'	<table class="'+ tableClass+'" border="0" cellpadding="0" cellspacing="0">\n' +
			'		<tr>\n' +
			'			<td>\n' +
			'				<img src="' + this.m_src_Space + '" width="1" height="2"></td>\n' +
			'		</tr>\n';
	}
}

function WWW_MENU_BAR_CoreHtml(childElement, nodeLocation) {
	var label = childElement.m_label;
	var id = nodeLocation;
	var level = childElement.m_level;

	if (level == 0 && this.m_ShowHome)
		level = 1;	// fake it...

	if (level == 0) // Home node
	{

	} else	if (level == 1)  {		// Top-level menu items
		var linkTarget = "_self";
		var url = childElement.m_href.replace(/'/g, "\\'");

		if (childElement.m_subNodes.length == 0 || childElement.m_level == 0) 	{	// "item"
			this.m_ds[this.m_di++] =
				'<td id="' + id + '" class="www_TopLinkItem"' +
				' onclick="' + this.m_InstanceName + '.linkItem_onclick(event, this, \'' + url + '\', \'' + linkTarget + '\')"' +
				' onmouseover="' + this.m_InstanceName + '.linkItem_mouseover(this)"' +
				' onmouseout="' + this.m_InstanceName + '.linkItem_mouseout(this)">\n' +
				'	' + label + '\n' +
				'</td>\n';
		} else  {	// "collection"
			this.m_ds[this.m_di++] =
				'<td id="' + id + '"' +
				' onclick="' + this.m_InstanceName + '.linkItem_onclick(event, this, \'' + url + '\', \'' + linkTarget + '\')"' +
				' onmouseover="' + this.m_InstanceName + '.topCollectionItem_mouseover(event, this)"' +
				' onmouseout="' + this.m_InstanceName + '.topCollectionItem_mouseout(event, this)">\n' +
				'	<table class="www_TopCollectionItemTable" border="0" cellpadding="0" cellspacing="0">\n' +
				'		<tr>\n' +
				'		<td class="www_TopCollectionItem">\n' +
				'			' + label + '</td>\n' +
				'		</tr>\n' +
				'	</table>\n';
		}
	} else	{ 			// Child menu items
		var linkTarget = "_self";
		var url = childElement.m_href.replace(/'/g, "\\'");

		if (childElement.m_subNodes.length == 0)  {	// "item"
			this.m_ds[this.m_di++] =
				'<tr>\n' +
				'	<td id="' + id + '" class="www_ChildLinkItem"' +
					' onclick="' + this.m_InstanceName + '.linkItem_onclick(event, this, \'' + url + '\', \'' + linkTarget + '\')"' +
					' onmouseover="' + this.m_InstanceName + '.linkItem_mouseover(this)"' +
					' onmouseout="' + this.m_InstanceName + '.linkItem_mouseout(this)">\n' +
				'	' + label + '\n' +
				'	</td>\n' +
				'</tr>\n';
		} else  {				 // "collection"
			this.m_ds[this.m_di++] =
				'<tr>\n' +
				'	<td  id="' + id + '"' +
						' onclick="' + this.m_InstanceName + '.linkItem_onclick(event, this, \'' + url + '\', \'' + linkTarget + '\')"' +
						' onmouseover="' + this.m_InstanceName + '.childCollectionItem_mouseover(event, this)"' +
						' onmouseout="' + this.m_InstanceName + '.childCollectionItem_mouseout(event, this)">\n' +
				'		<table class="www_ChildCollectionItemTable" style="width:100%" border="0" cellpadding="0" cellspacing="0">\n' +
				'			<tr>\n' +
				'				<td class="www_ChildCollectionItem">\n' +
				'					' + label + '</td>\n' +
				'			</tr>\n' +
				'		</table>\n';
		}
	}
}

function WWW_MENU_BAR_ClosingHtml(parentElement) {
	var level = parentElement.m_level;
	if (level == 0)  { // Home node
	} else  if (level == 1) // Top-level menu items
	{
		this.m_ds[this.m_di++] =
			'			<tr>\n' +
			'				<td>\n' +
			'					<img src="' + this.m_src_Space + '" width="1" height="2"></td>\n' +
			'			</tr>\n' +
			'		</table>\n' +
			'	</div>\n' +
			'</td>\n'; // Closing tag for parent cell
	} else							// Child menu items
	{
		this.m_ds[this.m_di++] =
			'			<tr>\n' +
			'				<td>\n' +
			'					<img src="' + this.m_src_Space + '" width="1" height="2"></td>\n' +
			'			</tr>\n' +
			'		</table>\n' +
			'	</div>\n' +
			'	</td>\n' + // Closing tag for parent cell.
			'</tr>\n'; // Closing tag for parent row.
	}
}

// ============= Runtime Support Functions =============================

function WWW_MENU_BAR_topCollectionItem_mouseover(e, element) {
	this.highlightItem(element);
	var headerTable = document.getElementById(this.m_HeaderTableId);
	var headerHeight = parseInt(headerTable.offsetHeight);
	var headerTop = parseInt(headerTable.offsetTop) - 2;
	var headerLeft = parseInt(headerTable.offsetLeft);
	var trikLeft = 0;
	var trikTop = 0;
	var container = headerTable.offsetParent;
	
	var menuID = element.id;

	while (container)  {
		trikLeft += container.offsetLeft;
		trikTop += container.offsetTop;
		container = container.offsetParent;
	}

	if (navigator.appName == "Netscape") {
		var menuBottomBorder = 1;
		var menuBottomPadding = 1;
	}  else {
		var menuBottomBorder = parseInt(document.getElementById(this.m_HeaderMenuId).currentStyle.borderBottomWidth);
		var menuBottomPadding = parseInt(document.getElementById(this.m_HeaderMenuId).currentStyle.paddingBottom);
		if (isNaN(menuBottomBorder)) { menuBottomBorder = 0 }
		if (isNaN(menuBottomPadding)) { menuBottomPadding = 0 }
	}

	headerHeight = parseInt(headerHeight) - parseInt(menuBottomBorder) - parseInt(menuBottomPadding);

	if (element.getElementsByTagName("div").length > 0) {
		var childMenu = element.getElementsByTagName("div")[0];		
		childMenu.style.top = trikTop + headerTop + headerHeight;
		if (menuID < 4)
			childMenu.style.left = trikLeft + headerLeft + element.offsetLeft;
		else
			childMenu.style.left = trikLeft + headerLeft + element.offsetLeft - 105;
		
		childMenu.style.display = "block";
		this.setMenuDisplayStatus(childMenu, "on");
	}
}

function WWW_MENU_BAR_topCollectionItem_mouseout(e, element) {
	if (!e) { e = window.event; }

	this.unhighlightItem(element);
	if (element.getElementsByTagName("div").length > 0)	{
		var childMenu = element.getElementsByTagName("div")[0];
		childMenu.style.display = "none";
		this.setMenuDisplayStatus(childMenu, "off");
	}
}

//THT: alignment of child menus here
function WWW_MENU_BAR_childCollectionItem_mouseover(e, element) {
	this.highlightItem(element);
		
	//TT:  Put hard codes here
	if (element.getElementsByTagName("div").length > 0)  {
		var childMenu = element.getElementsByTagName("div")[0];
		var menuID = element.id;

		if (navigator.appName == "Netscape") {			
			childMenu.style.top = 22;
		}else {
			childMenu.style.top = element.offsetTop;
		}
		if (menuID >= 4)
			childMenu.style.left = -170;

		childMenu.style.display = "block";
		this.setMenuDisplayStatus(childMenu, "on");
	}
}

function WWW_MENU_BAR_highlightItem(element) {
	var itemDisplayTable = element.getElementsByTagName("table")[0];

	// Set style for item's display table element.
	if (itemDisplayTable.className == "www_TopCollectionItemTable")  {
		itemDisplayTable.className = "www_TopCollectionItemTable_over";
	}
	else if (itemDisplayTable.className == "www_ChildCollectionItemTable")
	{
		itemDisplayTable.className = "www_ChildCollectionItemTable_over";
	}

	var tableCells = itemDisplayTable.getElementsByTagName("td")
	for (var i=0; i<tableCells.length; i++) 	{
		// Set style for item's label cell element.
		if (tableCells[i].className == "www_TopCollectionItem")  {
			tableCells[i].className = "www_TopCollectionItem_over";
		}  else if (tableCells[i].className == "www_ChildCollectionItem")	{
			tableCells[i].className = "www_ChildCollectionItem_over";
		}
	}
}

function WWW_MENU_BAR_childCollectionItem_mouseout(e, element) {
	if (!e) { e = window.event; }

	this.unhighlightItem(element);
	if (element.getElementsByTagName("div").length > 0) {
		var childMenu = element.getElementsByTagName("div")[0];
		childMenu.style.display = "none";
		this.setMenuDisplayStatus(childMenu, "off");
	}

}

function WWW_MENU_BAR_unhighlightItem(element) {
	var itemDisplayTable = element.getElementsByTagName("table")[0];
	// Set style for item's display table element.
	if (itemDisplayTable.className == "www_TopCollectionItemTable_over")  {
		itemDisplayTable.className = "www_TopCollectionItemTable";
	}  else if (itemDisplayTable.className == "www_ChildCollectionItemTable_over") 	{
		itemDisplayTable.className = "www_ChildCollectionItemTable";
	}

	var tableCells = itemDisplayTable.getElementsByTagName("td")
	for (var i=0; i<tableCells.length; i++) 	{
		// Set style for item's label cell element.
		if (tableCells[i].className == "www_TopCollectionItem_over")  {
			tableCells[i].className = "www_TopCollectionItem";
		}  else if (tableCells[i].className == "www_ChildCollectionItem_over") 	{
			tableCells[i].className = "www_ChildCollectionItem";
		}
	}
}

function WWW_MENU_BAR_linkItem_mouseover(element)  {
	if (element.className == "www_TopLinkItem")  {
		element.className = "www_TopLinkItem_over";
	} else if (element.className == "www_ChildLinkItem") 	{
		element.className = "www_ChildLinkItem_over";
	}
}

function WWW_MENU_BAR_linkItem_mouseout(element)  {
	if (element.className == "www_TopLinkItem_over")  {
		element.className = "www_TopLinkItem";
	}  else if (element.className == "www_ChildLinkItem_over") 	{
		element.className = "www_ChildLinkItem";
	}
}

function WWW_MENU_BAR_topCollectionItem_onclick(e, element)  {
	alert("WWW_MENU_BAR_topCollectionItem_onclick 00");
	var headerTable  = document.getElementById(this.m_HeaderTableId);
	//var headerHeight = headerTable.offsetHeight;
	var trikLeft = 0;
	var trikTop = 0;

	var container = headerTable.offsetParent;
	while (container)  {
		trikLeft += container.offsetLeft;
		trikTop += container.offsetTop;
		container = container.offsetParent;
	}

	if (navigator.appName == "Netscape") {
		alert("WWW_MENU_BAR_topCollectionItem_onclick 01");

		if (element.getElementsByTagName("div").length > 0) {
			alert("WWW_MENU_BAR_topCollectionItem_onclick 02");

			var childMenu = element.getElementsByTagName("div")[0];
			alert("WWW_MENU_BAR_topCollectionItem_onclick 03");
			if (childMenu.style.display == "none")  {
				this.resetMenus();
				//childMenu.style.top = headerHeight + trikTop;
				childMenu.style.left = element.offsetLeft + trikLeft;
				childMenu.style.display = "block";
				this.setMenuDisplayStatus(childMenu, "on");
			}
			else if (childMenu.style.display == "block")
			{
				this.resetMenus();
				this.highlightItem(element);
				/* Note: have to rehighlight the element since the mouse is logically still over this element, and the closeChildMenusOf function loop sets parent
					elements of ALL child menus (including the target) back to regular style */
			}
		}
		e.stopPropagation();
	}  else // IE Branch
	{
		e.cancelBubble = true;
	}
}

function WWW_MENU_BAR_childCollectionItem_onclick(e, element)  {
	e.cancelBubble = true;
}

function WWW_MENU_BAR_linkItem_onclick(e, element, url, target) {
// alert (url);
	if (target == "") {
		target = "_self";
	}
	window.open(url, target);
	this.resetMenus();

	e.cancelBubble = true;

}

function WWW_MENU_BAR_closeChildMenusOf(element) {
// Closes an element's associated child menu as well as all decendents of that menu.
	var decendentMenus = element.getElementsByTagName("div");

	for (var i=decendentMenus.length-1; i>=0; i--)  {
		var childMenu = decendentMenus[i];
		this.unhighlightItem(childMenu.parentNode);
		childMenu.style.display = "none";
		this.setMenuDisplayStatus(childMenu, "off");
	}
}

function WWW_MENU_BAR_closeOpenSiblingsOf(element) {
	var hierarchyLevel = element.id.split(".").length;

	if (hierarchyLevel == 1) // Top-level items
	{
		var siblingCellElements = element.parentNode.cells;

		for (var i=0; i<siblingCellElements.length; i++) 	{
			var siblingCellElement = siblingCellElements[i];

			if (siblingCellElement.getElementsByTagName("div").length > 0) 	{
				if (siblingCellElement.getElementsByTagName("div")[0].style.display == "block" && siblingCellElement != element) 	{
					this.closeChildMenusOf(siblingCellElement);
				}
			}
		}
	} else // Sub-level items
	{
		var siblingRowElements = element.parentNode.parentNode.rows; // Note: had to use parentNode twice to get past the TBODY element to the TABLE element.

		for (var i=0; i<siblingRowElements.length; i++) {
			var siblingCellElement = siblingRowElements[i].cells[0];

			if (siblingCellElement.getElementsByTagName("div").length > 0)  {
				if (siblingCellElement.getElementsByTagName("div")[0].style.display == "block" && siblingCellElement != element) 	{
					this.closeChildMenusOf(siblingCellElement);
				}
			}
		}
	}
}

/* This function uses a global array (defined above) to record element references
	to all menu containers that are currently visible. */
function WWW_MENU_BAR_setMenuDisplayStatus(menuElement, status) {
	if (status == "on") {
		/* If setting status to "on", add the element to the selectedElements array. */
		var alreadyOn = false;
		for (var i=0; i<this.m_selectedElements.length; i++)  {
			if (this.m_selectedElements[i] == menuElement)	{
				alreadyOn = true;
				break;
			}
		}
		if (!alreadyOn) 	{
			this.m_selectedElements.concat(new Array(menuElement));
		}
	} else if (status == "off")  {
		/* If setting status to "off", loop through the selectedElements array and
			find the array item that matches the current menu element and remove it
			from the array. */
		for (var i=0; i<this.m_selectedElements.length; i++)
		{
			if (this.m_selectedElements[i] == menuElement)
			{
				this.m_selectedElements.splice(i, 1); //Removes the selected element from the array.
				break;
			}
		}
	}
}

function WWW_MENU_BAR_resetMenus(e) {
	var i = 0;
	var topLevelMenuCell = document.getElementById(i.toString());
	while (topLevelMenuCell != null)
	{
		if (topLevelMenuCell.getElementsByTagName("div").length > 0 && topLevelMenuCell.getElementsByTagName("div")[0].style.display == "block")
		{
			this.closeChildMenusOf(topLevelMenuCell);
		}
		i++;
		topLevelMenuCell = document.getElementById(i.toString());
	}
	this.m_selectedElements.length = 0; // Clear out the array.
}
// ==================== the end ===========================
