// Telstra v6.02 ; released 130801
// 070801, TEL_onLoad() added

// HM_Loader.js v4.0.5 010312 (c) 2001 Peter Belesis. All Rights Reserved
HM_DOM = (document.getElementById) ? true : false;
HM_NS4 = (document.layers) ? true : false;
HM_IE = (document.all) ? true : false;
HM_IE4 = HM_IE && !HM_DOM;
HM_Mac = (navigator.appVersion.indexOf("Mac") != -1);
HM_IE4M = HM_IE4 && HM_Mac;
HM_IsMenu = (HM_DOM || HM_NS4 || (HM_IE4 && !HM_IE4M));
HM_NS6 = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));
HM_PG_NSFontOver = true;
HM_BrowserString = HM_NS4 ? "NS4" : HM_DOM ? "DOM" : "IE4";

if(window.event + "" == "undefined") event = null;
function HM_f_PopUp(){return false};
function HM_f_PopDown(){return false};
popUp = HM_f_PopUp;
popDown = HM_f_PopDown;

//TELSTRA additions given 'TEL_' prefix to distinguish from hierMenus functions

// function to find matching detials between the page url and a hierMenus divs - allowing us
// to use the hierMenus info for bread crumb names and highlighting
function TEL_retrieveHmPageDetails(mode) {
	
	if (hmVisi != 0) { parentHmArray = eval("HM_Array" + sectionId);}	
	var url = unescape(window.location.href);
	
	var parentHighlight = "0_0";
	var childHighlight = "0_0";
	var parentBreadcrumb = "";
	var childBreadcrumb = "";
	
	if (hmVisi != 0) {	
	// Loop through parent. Starts at 2 and finishes at length -1 , as we know these are for decoration and config
	for (i=2; i<(parentHmArray.length -1); i++) {  
		
		// finds a match in a url in the parent hiermenu 
		if (url.indexOf(parentHmArray[i][1]) != -1) {
		
			var parentHighlight = sectionId + "_" + i;
			var parentBreadcrumb = parentHmArray[i][0];
			break; 
		}
		
		//  no url match found in parent ; if the parent item has children, search them
		else { 
			
			var parentCurrent = sectionId + "_" + i; // the parent div that the child belongs to
			
			if (parentHmArray[i][4] == 1) {  // parentCurrent has child
			
				childHmArray = eval("HM_Array" + sectionId + "_" + i);
		
				for (j=0; j<childHmArray.length; j++) {  // loop through child
				
					if (url.indexOf(childHmArray[j][1]) != -1) { // if url match is found
					
						var parentHighlight = parentCurrent;
						var childHighlight = parentCurrent + "_" + j;
						var childBreadcrumb = childHmArray[j][0];
						var parentBreadcrumb = parentHmArray[i][0];
						break;	 
					}
				
				} 
			
			} 
		
		} 
		
	}
	
	} // end hmVisi catch
			
	// return 
	if (mode == 'parentHighlight') { return parentHighlight;}
	if (mode == 'parentBreadcrumb') { return parentBreadcrumb;}
	if (mode == 'childHighlight') { return childHighlight;}
	if (mode == 'childBreadcrumb') { return childBreadcrumb;}
}

var parentHighlight = "" ; parentHighlight = TEL_retrieveHmPageDetails('parentHighlight');
var childHighlight = "" ; childHighlight = TEL_retrieveHmPageDetails('childHighlight');
var parentBreadcrumb = "" ; parentBreadcrumb = TEL_retrieveHmPageDetails('parentBreadcrumb');
var childBreadcrumb = "" ; childBreadcrumb = TEL_retrieveHmPageDetails('childBreadcrumb');

// write breadcrumb
var tsIndexLink = "";
var siteNameLink = ""
if (tsIndex[0] != "") { tsIndexLink = '<a href="'+tsIndex[1]+'" class="bcrumb">'+tsIndex[0]+'</a>' }; 
if (siteName[0] != "") { siteNameLink = '<a href="'+siteName[1]+'" class="bcrumb">'+siteName[0]+'</a>' }; 
if (siteName[0] != "" && tsIndexLink != "") { siteNameLink = (' &gt;&gt; <a href="'+siteName[1]+'" class="bcrumb">'+siteName[0]+'</a>') };
var gap = '  &gt;&gt;';
if (tsIndexLink == "" && siteName == "") { gap = ""};

if (childBreadcrumb == "") {
	var breadCrumbSection = tsIndexLink + siteNameLink+ gap + ' <a href="'+siteAreasArray[1][sectionId -1]+'" class="bcrumb">'+TEL_removeLineBreak(siteAreasArray[0][sectionId -1])+'</a>';
	var currentBreadCrumb = ' <font class="bcrumb">&gt;&gt;</font> ' + parentBreadcrumb;
}

if (childBreadcrumb != "") {
	var breadCrumbSection = tsIndexLink + siteNameLink + gap + ' <a href="'+siteAreasArray[1][sectionId -1]+'" class="bcrumb">'+TEL_removeLineBreak(siteAreasArray[0][sectionId -1])+'</a>'+' &gt;&gt; '+parentBreadcrumb;
	var currentBreadCrumb = ' <font class="bcrumb">&gt;&gt;</font> ' + childBreadcrumb;
}

if (childBreadcrumb == "" && parentBreadcrumb == "") {
	breadCrumbSection = tsIndexLink + siteNameLink+ gap +' '+TEL_removeLineBreak(siteAreasArray[0][sectionId -1]);  
	currentBreadCrumb='' 
}

function TEL_writeBreadCrumbSection() {
	document.write(breadCrumbSection);
}
function TEL_writeBreadCrumbCurrent() {	
	document.write(currentBreadCrumb);
}


// write horizontal nav tabs
function TEL_writeHorizontalTabs(theme) {
    var s= "";
    for ( var i = 0; i < 52; i++ ) {  
	s = "";
	if (siteAreasArray[0][i] && siteAreasArray[0][i].length>0) { 
		 // If array element is a space, then create a new cell and right align it with a space.
		 // This will right align all tabs that appear after the space.
		 if (siteAreasArray[0][i].substring(0,1) == " ") {
			s +="<td width=\"100%\" align=\"right\">&nbsp;</td>";
		 }
	 	 else {
			if (parseInt(sectionId - 1) == i) {
				if ( i != 0) {
					s = "<td><img src='../../../global/res/images/sin.gif' width='3' height='1'></td>";
					s +="<td class='siteactivetabnav' valign='top'><img src='../../../global/res/themes/wholesale/images/tab_left_inactive.gif ' width='8' height='20' alt=''></td>";
				 }
				 else {
					s +="<td class='siteactivetabnav' valign='top'><img src='../../../global/res/images/sin.gif ' width='5' height='20' alt=''></td>";
			 	 }
				 s +="<td class='siteactivetabnav' valign='middle' align='center' nowrap><img src='../../../global/res/themes/wholesale/images/tick.gif'  width='8' height='9' alt=''>&nbsp;<a class='siteactivetabnav'>" + siteAreasArray[0][i] + "</a></td>";
				 s +="<td align='right' class='siteactivetabnav' valign='top'><img src='../../../global/res/themes/wholesale/images/tab_right_inactive.gif' width='8' height='20' alt=''></td>";
			} else {
				s ="<td><img src='../../../global/res/images/sin.gif' width='3' height='1'></td>";
				s +="<td class='sitetabnav' valign='top'><img src='../../../global/res/themes/wholesale/images/tab_left_inactive.gif' width='8' height='20' alt=''></td>";
				s +="<td class='sitetabnav' valign='middle' align='center' nowrap><a class='sitetabnav' href='"+ siteAreasArray[1][i] +"'  title='"+siteAreasArray[2][i]+"'>"+ siteAreasArray[0][i]  +"</a></td>";
				s +="<td align='right' class='sitetabnav' valign='top'><img src='../../../global/res/themes/wholesale/images/tab_right_inactive.gif' width='8' height='20' alt=''></td>";
			} 
		 }
		 document.write(s);
	}
    }
}


function TEL_writeHorizontalTabsHelp(theme) {
    var s= "";
    for ( var i = 0; i < 52; i++ ) {  
	s = "";
	if (siteAreasArray[0][i] && siteAreasArray[0][i].length>0) { 
		 // If array element is a space, then create a new cell and right align it with a space.
		 // This will right align all tabs that appear after the space.
		 if (siteAreasArray[0][i].substring(0,1) == " ") {
			s +="<td width=\"100%\" align=\"right\">&nbsp;</td>";
		 }
	 	 else {
			if (parseInt(sectionId - 1) == i) {
				if ( i != 0) {
					s = "<td><img src='../../../../global/res/images/sin.gif' width='3' height='1'></td>";
					s +="<td class='siteactivetabnav' valign='top'><img src='../../../../global/res/themes/wholesale/images/tab_left_inactive.gif ' width='8' height='20' alt=''></td>";
				 }
				 else {
					s +="<td class='siteactivetabnav' valign='top'><img src='../../../../global/res/images/sin.gif ' width='5' height='20' alt=''></td>";
			 	 }
				 s +="<td class='siteactivetabnav' valign='middle' align='center' nowrap><img src='../../../../global/res/themes/wholesale/images/tick.gif'  width='8' height='9' alt=''>&nbsp;<a class='siteactivetabnav'>" + siteAreasArray[0][i] + "</a></td>";
				 s +="<td align='right' class='siteactivetabnav' valign='top'><img src='../../../../global/res/themes/wholesale/images/tab_right_inactive.gif' width='8' height='20' alt=''></td>";
			} else {
				s ="<td><img src='../../../global/res/images/sin.gif' width='3' height='1'></td>";
				s +="<td class='sitetabnav' valign='top'><img src='../../../../global/res/themes/wholesale/images/tab_left_inactive.gif' width='8' height='20' alt=''></td>";
				s +="<td class='sitetabnav' valign='middle' align='center' nowrap><a class='sitetabnav' href='"+ siteAreasArray[1][i] +"'  title='"+siteAreasArray[2][i]+"'>"+ siteAreasArray[0][i]  +"</a></td>";
				s +="<td align='right' class='sitetabnav' valign='top'><img src='../../../../global/res/themes/wholesale/images/tab_right_inactive.gif' width='8' height='20' alt=''></td>";
			} 
		 }
		 document.write(s);
	}
    }
}


function TEL_removeLineBreak(str) { //  requirement for <br> line break in horizontal tab names, need to remove the br for the section footer
	 	
	if(str.indexOf("<br>") != -1 ) {
		str1 = str.substring(0, ( str.indexOf("<br>") ) );
		str2 = str.substring( ( str.indexOf("<br>") + 4 ), (str.length) );
		str = (str1 + " " + str2);
	}
	return str;
}


// determine whether inlineDIV or inlineLAYER exists on parent document ; whether vertical menus should be shown at all
function TEL_shouldShow() {
	if (HM_IE && document.all.inlineDIV) { return true }
	else if (HM_NS4 && document.layers.inlineLAYER) {return true }
	else if (HM_NS6 && document.getElementById('inlineDIV') ) { return true }
	else { return false }
}


// display vertical menu correctly positioned in relation to documents 'inlineDIV'
function TEL_displayVerticalMenu() {
	
	shouldShow = TEL_shouldShow();
	if (!shouldShow) { return null;}

	menu = "HM_Menu" + sectionId;
	nsNativeMenu ="";
			
	if (HM_NS4) {	

	// hierMenus v4.05 changed its way of creating layers for netscape . 
	// new Layer() method names the hierMenu layers '_js_randomnumber' 
	// This loop checks how many layers there are native to the page, deducing where hierMenus begin
		for ( i=0 ; i<document.layers.length; i++ ) {
		
			if (document.layers[i].name.indexOf("_js_") != -1 ) {
			
				nsNativeMenu = i;
				break;
			}
		}		
		
		yPos = document.layers["inlineLAYER"].pageY;
		document.layers[nsNativeMenu].moveTo(0,yPos);
	}

		
	if(HM_IE) {
	
		if (!document.all[menu]) menu = "HM_Menu1"; // establish default
		
		document.all[menu].style.top = TEL_distanceFromTop(document.all.inlineDIV) + "px";
		document.all[menu].style.visibility = "visible";
		
		setTimeout("TEL_displayVerticalMenu('" + menu +"')", 1000);
	}	

	if (HM_NS6){
			
		if (!document.getElementById(menu)) menu = "HM_Menu1"; // establish default
		
		document.getElementById(menu).style.top = TEL_distanceFromTop(document.getElementById("inlineDIV")) + "px";
		document.getElementById(menu).style.visibility = "visible";
		setTimeout("TEL_displayVerticalMenu('" + menu +"')", 1000);
	}
		
	TEL_positionAdvert(menu,nsNativeMenu); // call function to position advertising 
return null // Netscape4.03 fix
}


// position advertising beneath the vert menu, taking into account the height of the vert menu
function TEL_positionAdvert(menu,nsNativeMenu) {
		
	var top = ""; 
	var adTop = ""; 
	var bot = "";
	var dist = 6; // distance between navigation div and top of advertising content
					
	if (HM_IE) { 								
			
		top = document.all[menu].style.top;
		bot = document.all[menu].style.height; 
		
		if(bot != "") {

			adTop = parseInt(top) + parseInt(bot) + dist;	
			document.all.advertDiv.style.top = (adTop + "px");	
		}	
		else { 
			return null;
		}	
	}
				
	if (HM_NS4) { 
		
		top = document.layers["inlineLAYER"].pageY;
		bot = document.layers[nsNativeMenu].clip.bottom;
		adTop = parseInt(top) + parseInt(bot) + dist;
		document.layers.advertDiv.top = adTop;
	}
	
	if (HM_NS6) { 

		top = document.getElementById(menu).style.top; 
		bot = document.getElementById(menu).style.height; 
		adTop = parseInt(top) + parseInt(bot) + dist;
		document.getElementById('advertDiv').style.top = adTop;

	}			
return null // Netscape4.03 fix
}


// establish a divs distance from top
function TEL_distanceFromTop(oElement)
{
	var nTop = oElement.offsetTop;
	while(oElement.offsetParent != null)
	{
		nTop += oElement.offsetParent.offsetTop;
		oElement = oElement.offsetParent;
	}
	return nTop;
}


// customise content for each hierMenu div - highlights tabs specified in siteAreasArray
// note HM_ScriptIE.js is using its own version of this, pending fixes
function TEL_customiseDivContent(tree, text) {

	// add wrappers to headers 
	treeIndexOne = tree.charAt(0);
	treeIndexTwo = tree.charAt(1);
	treeIndexThree = tree.charAt(4);
	treeIndexFour = tree.charAt(5);

	if ( (treeIndexOne == "9" && treeIndexTwo != "_") && (treeIndexThree == "_")){ 
		return (hdrNorm + text + hdrEnd);
	}

	if ( ( treeIndexOne == "9" && treeIndexTwo != "_") && treeIndexFour == "_" ){
		return (hdrNorm + text + hdrEnd);
	}	
	
	if ((treeIndexOne == "9") && (treeIndexTwo != "_")){
		
			undScore = tree.indexOf("_");
			actualTree = tree.substring(0,undScore);
			divNumber = tree.substring(undScore + 1,tree.length);
			
			actualTree = eval("HM_Array" + actualTree)
			if ( document.location.href.indexOf(actualTree[divNumber][1])  != -1 ) {
				return (hdrHglht + text + hdrEnd);
			}
			else {
				return (hdrNorm + text + hdrEnd);		
			}
			
	}
	// End Header Wrapping.
	

	
	// find out how many underscores are in the tree, store in undCount variable - here, top level trees have 1 (ie '1_1')
		var undCount = 0;
		var undTree = tree;
		var ret = text;
	
		for ( i=0; i<undTree.length ; i++){  
		
			undScore = undTree.indexOf("_");
			if (undScore != -1) {
			
				undCount = undCount + 1;
				undTree = undTree.substring( (undScore + 1), (undTree.length) )
			}
			else { break }
		}
	
		// once we have the undCount, work out which wrapper to return
		for (i=0; i<1; i++) {
	
			// last div of a top level tree
			if (undCount == 1) {
	
				undScore = tree.indexOf("_");
				whichTree = tree.substring(0,undScore);
				whichArray = eval("HM_Array" + whichTree)
				whichArray = (whichArray.length - 1)
				lastDiv = (whichTree + "_" + whichArray )
		
				if ( tree == lastDiv ) {
					ret = estr;
					break				
				}
			}
					

			// highlighted menus, as specified in siteAreasArray	
			if (tree == parentHighlight) {
				
				// arrow tab where item has flyouts
				actualHm = "HM_Array" + tree.substring(0,(tree.indexOf('_')));
				actualDiv = tree.substring((tree.indexOf('_') +1),(tree.length));
				actualHm = eval(actualHm)
				if (actualHm[actualDiv][4] == 1) {
					if (HM_NS4==true) {
						ret = (selstrWithChild+text+msstrDarkBlue);
					}
					else {
						ret = (selstrWithChild+text+esstr);
					}
				}
				else {
					ret = (selstr+text+esstr);
				}				
				break
			}
			if (tree == childHighlight) {
				ret = (selstrSub + text + esstr);
			}
			if (ret == (selstr + text + esstr) || ret ==  (selstrSub + text + esstr) ) {
				break
			}
							
			// top div of a top level tree needs the curve graphic
			if (undCount == 1 && tree.length == 3 && (tree.substring(1,3)) == "_1" ) {
				ret = topstr;
				break
			}
				
			// top level tree, text does not equal the page description = arrow tab
		/*	if (undCount ==1 && tree != parentHighlight) {	
				ret = (astr + text + esstr);
				break
			}*/
			
			if (undCount ==1 && tree != parentHighlight) {	
			
					
				// arrow tab where item has flyouts
				actualHm = "HM_Array" + tree.substring(0,(tree.indexOf('_')));
				actualDiv = tree.substring((tree.indexOf('_') +1),(tree.length));
				actualHm = eval(actualHm)
				if (actualHm[actualDiv][4] == 1) {
					ret = (mstr + text + msstr);
				}
				else {
					ret = (astr + text + esstr);
				}				
				break
			}
			
	
			// standard tab for secondary menus
			if (undCount >1 ) { 
				ret = (sstr + text + esstr); 
				break
			}		
		}

		return ret;
}

// hide problem forms on menu show
function TEL_hideDiv(div,mode) {
	
	//netscape6 - no problem
	if (HM_NS6) { return null }
	
	// hide divs for IE4/5 & NS4
	view = "hidden";  
	dom = document.all;
	if (HM_NS4) {dom = document.layers; view = "hide" }

	// div array - one default div gets hidden + the div specified
	divs = new Array ("formDiv");
	divs[1] = div;

	for (i=0; i < divs.length; i++) {
		if ( dom[divs[i]] ) {
	 		if (HM_IE) { dom[divs[i]].style.visibility = view }
	 		else { dom[divs[i]].visibility = view }
	 	}
	}
	// suppress Netscape4.03 'function must return value' quirk
	if ( dom.quirky) { return null }
}
// show problem forms on menu hide
function TEL_showDiv(div) {
	
	if (HM_NS6) { return null }
	
	view = "visible";  
	dom = document.all;
	if (HM_NS4) {dom = document.layers; view = "show" }

	divs = new Array ("formDiv");
	divs[1] = div;

	for (i=0; i < divs.length; i++) {
		if ( dom[divs[i]] ) {
	 		if (HM_IE) { dom[divs[i]].style.visibility = view }
	 		else { dom[divs[i]].visibility = view }
	 	}
	}

	if ( dom.quirky) { return null }
}


// decide which functions need to be called onLoad
function TEL_onLoad() {
	
	HM_f_StartIt(); 
	// if hmVisi is not zero, call advert positioning code
	if (hmVisi == 1) {
		 setTimeout('TEL_displayVerticalMenu()',1000)
	}
}

if(HM_IsMenu) {
	document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='../../../../global/res/javascript/HM_Script"+ HM_BrowserString +".js' TYPE='text/javascript'><\/SCR" + "IPT>");
}

// write Section Footer
function TEL_writeSectionFooter(){
var sectionFooter = '';
	for ( i=0; i<siteAreasArray[0,1].length; i++ ) { // Netscape4.03 fix
		if (siteAreasArray[0][i] == ' ') {
			siteAreasArray[0][i] = '';}
		if ( i == (sectionId - 1)) { 
			sectionFooter+= '<span class="contentfooter">' + TEL_removeLineBreak(siteAreasArray[0][sectionId -1]) + '</span> | ';}
		else {			
			if (siteAreasArray[0][i] != '') {
				sectionFooter+= '<a href="' + siteAreasArray[1][i] + '" class="contentfooter">' + TEL_removeLineBreak(siteAreasArray[0][i]) + '</a> | ';}}}	
	sectionFooter = sectionFooter.substring(0,(sectionFooter.length - 2));
	document.write(sectionFooter);
}
