/*--------Function reDisplay--------------
The Following function is called to display the menu
Parameters:
	currentNumber:  
		The current index number of the item selected

	currentIsExpanded:  
		The current state of the selected item
		Values: True (is expanded), False (is not expanded)
----------------------------------------*/

function reDisplay(iMode) {
	
	// Working Storage**
	var strLineBreak = "BrandTool,GlobalTool,GlobalLabel,SectionLabel"; 	//Defines Navigation Types that need line breaks
	var strMenuToggleElements = "SectionHeading"; 	//Defines Navigation Types that toggle and rollup the menu
	var skipLength = -1;				//If a menu item has a URL its children will not be loaded	
	var tmpString = "";				//Used to assemble strings
	var outputToNav = false;			//Flag for checking if an item should be output to the screen
	var itemStart;
	var itemEnd;
	var itemStyle;
	var strOutput;
	var toggleColor = "";				//Controls the BackGround of the Elements
	var isToggleColor = false;
	var toggleColorLength = -1;
	//alert("I am at start");
	//resCont = window.open("", "");
	
	var contArray = getItemInfo("CONT");
	itemStart = contArray[2];
	itemClass = contArray[4];
	
	//Creates the Div Container***********************************
	//document.writeln("<div id=\"container\">");
	// Output Main Menu**
	// Get Category from Query String**
	var queryIdLength = -1; 			//Tracks the length of the category id
	var objArgs = LN_getArgs();			//Gets query string
	var queryId = objArgs['catid'];			//Category Id from Query String	
	
	//alert("I am before queryId");
	//alert("Query Id: " + queryId);
	if (queryId == null) { 
		queryIdLength = -1;
		queryId = -1;
		
	} else {
		//Get the entire category string from toc tab
		var tmpId;
		var tmpArray;
		var gotId = false;
		for (i=0; i < tocTab.length; i++) {
			tmpId = tocTab[i][0];
			tmpArray = tmpId.split(lftnavIdDelimit);
			if (tmpArray[tmpArray.length-1].indexOf("bl") > -1) {
				tmpArrayLength = tmpArray.length - 2;
			} else {
			        tmpArrayLength = tmpArray.length - 1;
			}
			if (tmpArray[tmpArrayLength] == queryId) {
				gotId = true;
				break;
			}
		}

		if (gotId) {
			var queryIdArray = tmpArray;
			//alert("Query Array: " + queryIdArray.toString());
			queryIdLength = queryIdArray.length;

			//Create an array to track each level that should be written
			var parentStack = new Array(20);

			for (i=0; i < parentStack.length; i++) parentStack[i] = -1;
			//alert("Got Here: QueryLength=" + queryIdLength);

			for(i=1; i<queryIdLength; i++) {
				if (i == 1) {
					parentStack[i] = queryIdArray[i];
					tmpString = queryIdArray[i];
					//alert("First Stack: " + parentStack.toString());
				
				} else {
					tmpString = tmpString + lftnavIdDelimit + queryIdArray[i];
					parentStack[i] = tmpString;
					//alert("Parent Stack: " + parentStack.toString());
				}
			} 			//toc Tab Loop
			
		} else {			//gotID
			queryIdLength = -1;
		}				//gotId
	}					//queryId Null
	//alert("End: " + queryIdLength + "Parent Stack: " + parentStack.toString());
	//alert("I am at start writing menu");

//Start Writing Menu*************************************
	var prevLabel = false;
	var prevLabelLen = -1;
	var lineOutput, dotLineOutput;
	var isFirstBrandTool = true;
	var globalToolIsSelected = false;
	var bumpCount = 4;
	var isPageGroupParent = false;
	var pageGroupLength = -1;
	var maxPageGroupLen = -1;
	var clrGifLen;
	var menuTextLen;

	//Controls Indent
	var bmpGifLen = 11;
	var bmpTextLen = 137;
	var cnstGifLen = 11;
	var cnstTextLen = 137;
	var removeLen = 0;
	var styleText = "";
	var lineOutput = "", dotLineOutput = "", clrLineOutput = "", bttmSpacerLine = "";
	var isHighlighted = false, highlightedLength = -1, carrotGif = xbClearGif;
	var onStartBrandPageGroup = false, onStartBrandPageGroupLen = -1;
	var onEndBPGArray = [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1];  //Tracks Spacing for BrandPage Groups
	var onEndBrandPageGroup = false;

	lineOutput = "<table " + xbElementName + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\">";
				lineOutput = lineOutput + "<tr valign=\"top\">";
				lineOutput = lineOutput + "<td><img " + xbElementName + " src=\"" + xbClearGif + "\" width=\"1\" height=\"4\" alt=\"\" border=\"0\"></td>";
				lineOutput = lineOutput + "</tr>";
//				lineOutput = lineOutput + "<tr valign=\"top\">";
//				lineOutput = lineOutput + "<td><img " + xbElementName + " src=\"" + xbSolidLine + "\" width=\"151\" height=\"1\" alt=\"\" border=\"0\"></td>";
//				lineOutput = lineOutput + "</tr>";
//				lineOutput = lineOutput + "<tr valign=\"top\">";
//				lineOutput = lineOutput + "<td><img " + xbElementName + " src=\"" + xbClearGif + "\" width=\"1\" height=\"4\" alt=\"\" border=\"0\"></td>";
//				lineOutput = lineOutput + "</tr>";
				lineOutput = lineOutput + "</table>";		
				
	clrLineOutput = "<table " + xbElementName + " class=\"bgSnav\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\">";
				clrLineOutput = clrLineOutput + "<tr valign=\"top\">";
				clrLineOutput = clrLineOutput + "<td><img " + xbElementName + " src=\"" + xbClearGif + "\" width=\"151\" height=\"3\" alt=\"\" border=\"0\"></td>";
				clrLineOutput = clrLineOutput + "</tr>";
				clrLineOutput = clrLineOutput + "</table>";

		dotLineOutput = clrLineOutput;

	bttmSpacerLine = "<table " + xbElementName + " class=\"bgSnav\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\">";
				bttmSpacerLine = bttmSpacerLine + "<tr valign=\"top\">";
				bttmSpacerLine = bttmSpacerLine + "<td><img " + xbElementName + " src=\"" + xbClearGif + "\" width=\"151\" height=\"20\" alt=\"\" border=\"0\"></td>";
				bttmSpacerLine = bttmSpacerLine + "</tr>";
				bttmSpacerLine = bttmSpacerLine + "</table>";

	strOutput =  itemStart + xbElementName + " id=\"container\">";

	document.writeln(strOutput);
	document.writeln(lineOutput);

	 for (i=0; i<tocTab.length; i++) {

			//Working Storage
			var loopId = tocTab[i][0];
			var loopIdArray = loopId.split(lftnavIdDelimit);
			var loopIdLength = loopIdArray.length;
			var loopText = tocTab[i][1];
			var loopURL = tocTab[i][2];
			var itemArray = getItemInfo(loopIdArray[0]);

			//skips to the next item if this one is not in the parms array
			if (itemArray[0] == -1)	{
				continue;
			}		

			itemStart = itemArray[2]; 
			itemEnd = itemArray[3];
			var loopClassName = itemArray[4];
			outputToNav = false;

			if (loopIdLength <= prevLabelLen) {
				prevLabel = false;
			}

		//bug fix 3
			if ((globalMode == xbNS4) && (loopClassName == "BrandSectionLabel")) {
				loopClassName = "BrandPageGroup";
				if (loopText.indexOf(lftnavTextDelimit) > -1) {
					loopTextArray = loopText.split(lftnavTextDelimit);
					loopText = loopTextArray[0];
				}
				//loopIdLength = loopIdLength - 1
			}

			//bug fix 3			
			//Control Highlighting
			if ((isHighlighted) && (loopIdLength <= highlightedLength)) {
				isHighlighted = false;
				highlightedLength = -1;
			}

			//Bug Fix 3
			//Control the Output of the Carrot Gif
			if ((queryIdLength != -1) && (globalMode == xbNS4)) { 
				if (loopIdArray[loopIdArray.length-1] == tmpArray[tmpArrayLength]) {
					carrotGif = xbCarrot;
				} else {
					carrotGif = xbClearGif;
				}
			}		

			//Url for post
			if (loopURL != "")  {
				if ((loopClassName == "SectionHeading") && (globalMode != xbNS4)) {
					var loopLink = "#";
					var loopLinkDir = "onClick=\"javaScript:LN_init_direct('" + loopId + "'); return false\"";
				} else {
					var loopLink = loopURL;
					var loopLinkDir = "";
				}

			} else if (globalMode == xbNS4) {
				var loopLink = "#";
				var loopLinkDir = "";

			} else {
				var loopLink = "#";
				var loopLinkDir = "onClick=\"javaScript:LN_init_direct('" + loopId + "'); return false\"";
			}

			/* 
			The following set of if statements contain the logic to determine if items will
			be written to the page.  The actual html formatting is triggered by setting
			outputToNav equal to true.
			*/	

			// Section Heading ****************************************************
			if ((loopClassName == "SectionHeading") || (loopClassName == "SectionLabel") || (loopClassName == "GlobalLabel")) {
				outputToNav = true;

			// Global Tool *********************************************************
			} else if (loopClassName == "GlobalTool") {
				outputToNav = true;	
				//Sets flag if global tool is selected
				if (queryIdLength != -1) { 
					if (loopIdArray[loopIdArray.length-1] == parentStack[loopIdArray.length-1]) {
						globalToolIsSelected = true;
						//isHighlighted = true; 
						//highlightedLength = loopIdLength;
					}
				}

				//Sets skip length if the global tool has a URL and is not selected
				if (loopURL != "")  {
						if ((queryIdLength != -1) && (loopIdArray[loopIdArray.length-1] == parentStack[loopIdArray.length-1]))  {
							skipLength = -1;

						} else {
							skipLength = loopIdLength; 
						}

				} else {
					skipLength = -1;
				}			

			// Brand Heading *********************************************************
			} else if (loopClassName == "BrandHeading") {

			// If a cat id was passed in the query string only write the single brand else write them all out
				if (((queryIdLength != -1) && (loopIdArray[loopIdArray.length-1] == parentStack[loopIdArray.length-1])) || (queryIdLength == -1))   {
					//outputToNav = false;
					outputToNav = true;					
					if (loopURL != "")  {
						if ((queryIdLength != -1) && (loopIdArray[loopIdArray.length-1] == parentStack[loopIdArray.length-1]))  {
							skipLength = -1;

						} else {
							skipLength = loopIdLength; 
						}

					} else {
						skipLength = -1;
					}

				} else if (globalToolIsSelected) {
						outputToNav = true;
						skipLength  = loopIdLength;
						//alert("Got Here")

				} else {
					//bug fix 2
					if (globalMode != xbNS4) {
						outputToNav = true;  
					} else {
						outputToNav == false;  	
					}

					//outputToNav = false;
					skipLength = loopIdLength;
				}

			// Everything Else *****************************************
			} else {
				//alert(loopText + " " + loopClassName);
				if ((skipLength < loopIdLength ) && (skipLength != -1)){
					//These items are below a URL and will not be written out
					outputToNav = false;

				} else if (loopIdLength <= queryIdLength) {
					//These items are parents of selected item and will be checked in the parent stack	
					var isParent = true;
					//Create Parent String for Comparison
					tmpString = "";

					for (y=1; y < loopIdLength - 1; y++) {
						if (y == 1) {
						 	tmpString = loopIdArray[y];
						} else {
							tmpString = tmpString + lftnavIdDelimit + loopIdArray[y];
						}						
					}

					if (tmpString != "") {												
						if ((parentStack[loopIdLength - 2] == tmpString) || (loopIdArray[1] == parentStack[1])) { 
							outputToNav = true;
						} else {
							outputToNav = false;
							skipLength = loopIdLength; 
						}
					}

					//If the lengths are equal and loopId is not the item selected
					if (loopIdArray[loopIdArray.length-1] == queryId) {
						skipLength = -1;
						if (loopClassName != "BrandSectionLabel") {
							isHighlighted = true; 
							if ((loopIdLength <= highlightedLength) || (highlightedLength == -1)) {
								highlightedLength = loopIdLength;
							}
						}

					} else if (check_Directly_Under(loopIdLength, loopIdArray, queryIdArray)) { 
						skipLength = -1;
						if (loopClassName != "BrandSectionLabel") {
							isHighlighted = true; 
							if ((loopIdLength <= highlightedLength) || (highlightedLength == -1)) {
								highlightedLength = loopIdLength;
							}
						}

					} else {
						if (loopURL == "") {
							skipLength = -1;	
						} else {
							skipLength = loopIdLength; 
						}
					}

				} else if (loopIdLength > queryIdLength) {
					//These items are children of the selected level and will be written out if they do
					//not fall below a URL
					if ((loopClassName == "BrandPageGroup") && (queryIdArray[0] != "BP") && (queryIdArray[0] != "BH")) { 
						isHighlighted = true; 
						if ((loopIdLength <= highlightedLength) || (highlightedLength == -1)) {
							highlightedLength = loopIdLength;
						}
					}

					if (loopURL != "") {
						skipLength = loopIdLength; 
					} else {
						skipLength = -1;
					}
					outputToNav = true;
				} // skipLength

				//Added to toggle on items under open labels	
				if ((prevLabel) && (loopIdLength == prevLabelLen + 1)) {
					outputToNav = true;
				} else if (loopIdLength <= prevLabelLen) {
					prevLabel = false;
				}
			}  //Section If 

			if (outputToNav) {
					//Resets indent and line output
					if ((loopIdLength <= pageGroupLength) && (isPageGroupParent)) {
						isPageGroupParent = false;
						pageGroupLength = -1;
					}

					if (isPageGroupParent == true) {
						if (loopClassName == "BrandSectionLabel") {
							removeLen = ((loopIdLength - pageGroupLength + 1) * 6);
						} else {
							removeLen = ((loopIdLength - pageGroupLength) * 6);
						}

						bmpGifLen = cnstGifLen + removeLen;
						bmpTextLen  = cnstTextLen - removeLen;

					} else {
						bmpGifLen = cnstGifLen;
						bmpTextLen  = cnstTextLen;
					}

					//Inserts Dotted Line After the Brand Tools	
					if ((prevLoopIdClass == "BrandTool") && (loopClassName != "BrandTool")) {
						if (isPageGroupParent) {
							if (globalMode != xbNS4) {
								strOutput = clrLineOutput;
							} else {
								strOutput = "";
							}
						} else {
							strOutput = dotLineOutput;
						}
						isFirstBrandTool = true;
						strOutput = strOutput + itemEnd;
						docOutput(strOutput);
						
					} else if ((prevLoopIdClass == "BrandTool") && (loopClassName == "BrandTool")) {
						strOutput = itemEnd;
						docOutput(strOutput);
					}

					if ((loopClassName != "BrandSectionLabel") && (loopClassName != "SectionHeading")) {
						//Opens the HTML sections
						strOutput= itemStart + xbElementName + " id=\"" + loopId + "\" class=\"" + loopClassName + "\">";
						//Puts in Dotted Line Breaks
						if ((isFirstBrandTool) && (loopClassName == "BrandTool")) {
							if (isPageGroupParent) {
								if (globalMode != xbNS4) {
									strOutput = strOutput  + clrLineOutput;
								}
							} else {
								strOutput = strOutput  + dotLineOutput;
							}

							isFirstBrandTool = false;
						//Puts Spacer in for BrandPageGroup
						} else if (onStartBrandPageGroup) {
							strOutput = strOutput + clrLineOutput;
						}
					}

					//Bug Fix 6	
					//var prevLoopIdClass = loopClassName;
					if ((loopClassName != "BrandSectionLabel") && (loopClassName != "SectionHeading")) {
						//Bug Fix 3	
						//if ((globalMode == xbNS4) && ((isPageGroupParent) || (isHighlighted))) {
						if ((globalMode == xbNS4) && (isHighlighted)) {
							var tmpClass = "bgSnavHi";
						} else if (globalMode == xbNS4) {						
						  var tmpClass = "bgSnav";
						} else {
						  var tmpClass = "bgSnav";
						}
						//Declares HTML table
						strOutput = strOutput + "<table " + xbElementName + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\" class=\"" + tmpClass + "\">";
					}

					// Brand Section Label *********************************************************
					if (loopClassName == "BrandSectionLabel") {
						if (isPageGroupParent == false) {
							clrGifLen = "4";
							menuTextLen = "139";
							bmpTextLen = 143;
							bmpGifLen = 10;
							//Bug Fix 20
							var tmpArrow = "";
							//var tmpArrow = "<img " + xbElementName + " src=\"" + xbArrowOpen + "\" width=\"10\" height=\"10\" alt=\"\" border=\"0\">";
							styleText = " class=\"bgSnav\" ";
						} else {
							var tmpArrow = "";
							clrGifLen = bmpGifLen;
							menuTextLen = bmpTextLen;
							styleText = " class=\"bgSnavHiOn\" ";
						}

						if (loopText.indexOf(lftnavTextDelimit) > -1) {
							var loopTextArray = loopText.split(lftnavTextDelimit);					
							strOutput = itemStart + xbElementName +  " id=\"" + loopId  + lftnavIdDelimit + "blON\" class=\"" + loopClassName + "\">"
							strOutput = strOutput + "<table " + xbElementName + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\" class=\"bgSnav\">";
							strOutput = strOutput + "<td width=\"8\"><img  " + xbElementName + "src=\"" + xbClearGif +  "\" width=\"8\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td " + styleText +  ">" + loopTextArray[0] + tmpArrow + "</td>";

							if (globalMode != xbNS4) {
								strOutput = strOutput + "</tr></table>" + itemEnd + itemStart + xbElementName +  " id=\"" + loopId  + lftnavIdDelimit + "blOFF\" class=\"" + loopClassName + "\">"
								strOutput = strOutput + "<table " + xbElementName + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\" class=\"bgSnav\">";
								strOutput = strOutput + "<td width=\"8\"><img  " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"8\" height=\"10\" alt=\"\" border=\"0\"></td>";				
								strOutput = strOutput + "<td " + styleText + " width=\"151\"><a  " + xbElementName + " href=\"" + loopLink + "\"" + loopLinkDir + ">" + loopTextArray[1] + "</a></td>";
							}
						 } else {						
							prevLabel = true;
							prevLabelLen = loopIdLength;
							strOutput = itemStart + xbElementName +  " id=\"" + loopId + "\" class=\"" + loopClassName + "\">";
							//strOutput = strOutput + "<table " + xbElementName + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\" class=\"bgSnav\"><tr>";
							strOutput = strOutput + "<table " + xbElementName + styleText + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\" ><tr>";
							strOutput = strOutput + "<td " + styleText + " width=\"4\"><img " + xbElementName + " class=\"carrot\" src=\"" + carrotGif +  "\" width=\"4\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td " + styleText + " width=\"" + clrGifLen + "\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"" + clrGifLen + "\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td " + styleText + " width=\"" + menuTextLen + "\">" + loopText + tmpArrow + "</td>";
						}

					// SectionHeading ****************************************************
					} else if (loopClassName == "SectionHeading") {
//						loopText= loopText.toUpperCase();
						var loopTextArray = loopText.split(lftnavTextDelimit);
						// If nothing is in query string write out Select a brand
						//var secOutput;				

						if ((queryIdLength == -1) || (globalToolIsSelected)) {
							strOutput = itemStart + xbElementName +  " id=\"" + loopId  + lftnavIdDelimit + "blON\" class=\"" + loopClassName + "\">"
							strOutput = strOutput + "<table " + xbElementName + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\" class=\"bgSnav\">";
//							strOutput = strOutput + "<td width=\"8\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"8\" height=\"10\" alt=\"\" border=\"0\"></td>";				
//							strOutput = strOutput + "<td  class=\"bgSnav\" align=\"left\" width=\"131\">" + loopTextArray[0] + "</td>";
						} else if (globalMode == xbNS4) {
							strOutput = itemStart + xbElementName +  " id=\"" + loopId  + lftnavIdDelimit + "blOFF\" class=\"" + loopClassName + "\">"
							strOutput = strOutput + "<table " + xbElementName + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\" class=\"bgSnav\">";
							strOutput = strOutput + "<td width=\"8\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"8\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td align=\"left\" width=\"131\"><a class=\"back\" " + xbElementName + " href=\"" + loopLink + "\"" + loopLinkDir + ">" + loopTextArray[1] + "</a></td>";
						} else {
							strOutput = itemStart + xbElementName +  " id=\"" + loopId  + lftnavIdDelimit + "blON\" class=\"" + loopClassName + "\">"
							strOutput = strOutput + "<table " + xbElementName + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\" class=\"bgSnav\">";
//							strOutput = strOutput + "<td width=\"8\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"8\" height=\"10\" alt=\"\" border=\"0\"></td>";				
//							strOutput = strOutput + "<td class=\"bgSnav\" align=\"left\" width=\"131\">" + loopTextArray[0] + "</td>";
							strOutput = strOutput + "</tr></table>" + itemEnd + itemStart + xbElementName +  " id=\"" + loopId  + lftnavIdDelimit + "blOFF\" class=\"" + loopClassName + "\">"
							strOutput = strOutput + "<table " + xbElementName + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\" class=\"bgSnav\">";
							strOutput = strOutput + "<td width=\"8\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"8\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td align=\"left\" width=\"131\"><div class=\"back\"><a id=\"back\" " + xbElementName + " href=\"" + loopLink + "\"" + loopLinkDir + ">" + loopTextArray[1] + "</a></div></td>";
						}
						//alert(strOutput);
					// SectionLabel ****************************************************
					} else if (loopClassName == "SectionLabel") {
//						loopText= loopText.toUpperCase();
						var loopTextArray = loopText.split(lftnavTextDelimit);
						// If nothing is in query string write out Select a brand
						//var secOutput;				

						if ((queryIdLength == -1) || (globalToolIsSelected)) {
							strOutput = itemStart + xbElementName +  " id=\"" + loopId  + lftnavIdDelimit + "blON\" class=\"" + loopClassName + "\">"
							strOutput = strOutput + "<table " + xbElementName + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\" class=\"bgSnav\">";
							strOutput = strOutput + "<td width=\"8\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"8\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td  align=\"left\" width=\"131\"><div class=\"navHdr\">" + loopTextArray[0] + "</div></td>";
						} else if (globalMode == xbNS4) {
							strOutput = itemStart + xbElementName +  " id=\"" + loopId  + lftnavIdDelimit + "blOFF\" class=\"" + loopClassName + "\">"
							strOutput = strOutput + "<table " + xbElementName + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\" class=\"bgSnav\">";
							strOutput = strOutput + "<td width=\"8\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"8\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td align=\"left\" width=\"131\">" + loopTextArray[1] + "</td>";
						} else {
							strOutput = itemStart + xbElementName +  " id=\"" + loopId  + lftnavIdDelimit + "blON\" class=\"" + loopClassName + "\">"
							strOutput = strOutput + "<table " + xbElementName + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\" class=\"bgSnav\">";
							strOutput = strOutput + "<td width=\"8\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"8\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td align=\"left\" width=\"131\"><div class=\"navHdr\">" + loopTextArray[0] + "</div></td>";
							strOutput = strOutput + "</tr></table>" + itemEnd + itemStart + xbElementName +  " id=\"" + loopId  + lftnavIdDelimit + "blOFF\" class=\"" + loopClassName + "\">"
						strOutput = strOutput + "<table " + xbElementName + " cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"151\" class=\"bgSnav\">";
							strOutput = strOutput + "<td width=\"8\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"8\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td align=\"left\" width=\"131\"><div class=\"navHdr\">" + loopTextArray[1] + "</div></td>";
						}
						//alert(strOutput);
					//Global Tool*******************************************
					} else if (loopClassName == "GlobalTool") {
//							loopText= loopText.toUpperCase();
							strOutput = strOutput + "<tr valign=\"top\">";
							strOutput = strOutput + "<td width=\"4\"><img  " + xbElementName + " class=\"carrot\" src=\"" + carrotGif +  "\" width=\"4\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td width=\"4\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"4\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td width=\"131\"><a " + xbElementName + " href=\"" + loopLink + "\"" + loopLinkDir + "class=\"snavHi\">" + loopText + "</a></td>";				
					//Global Labels*******************************************
					} else if (loopClassName == "GlobalLabel") {
//							loopText= loopText.toUpperCase();
							strOutput = strOutput + "<tr valign=\"top\">";
							strOutput = strOutput + "<td width=\"4\"><img  " + xbElementName + " class=\"carrot\" src=\"" + carrotGif +  "\" width=\"4\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td width=\"4\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"4\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td width=\"131\"><div class=\"navHdr\">" + loopText + "</div></td>";
					//Section Labels*******************************************
//					} else if (loopClassName == "SectionLabel") {
//							loopText= loopText.toUpperCase();
//							strOutput = strOutput + "<tr valign=\"top\">";
//							strOutput = strOutput + "<td width=\"4\"><img  " + xbElementName + " class=\"carrot\" src=\"" + carrotGif +  "\" width=\"4\" height=\"10\" alt=\"\" border=\"0\"></td>";				
//							strOutput = strOutput + "<td width=\"4\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"4\" height=\"10\" alt=\"\" border=\"0\"></td>";				
//							strOutput = strOutput + "<td width=\"131\"><div class=\"navHdr\">" + loopText + "</div></td>";
					// Brand Heading *********************************************************
					} else if (loopClassName == "BrandHeading") {
							strOutput = strOutput + "<tr valign=\"top\">";
							strOutput = strOutput + "<td width=\"4\"><img  " + xbElementName + " class=\"carrot\" src=\"" + carrotGif +  "\" width=\"4\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td width=\"4\"><img  " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"4\" height=\"1\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td width=\"139\"><a " + xbElementName + " href=\"" + loopLink + "\"" + loopLinkDir + " class=\"snavHi\">" + loopText + "</a></td>";				
							strOutput = strOutput + "<td width=\"4\"><img  " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"4\" height=\"1\" alt=\"\" border=\"0\"></td>";
					//Brand Page Group**************************************
					} else if (loopClassName == "BrandPageGroup") {
								strOutput = strOutput + "<tr valign=\"top\">";
								strOutput = strOutput + "<td width=\"4\"><img " + xbElementName + " class=\"carrot\" src=\"" + carrotGif +  "\" width=\"4\" height=\"10\" alt=\"\" border=\"0\"></td>";				
								if (globalMode == xbNS4) {
								  var tmpArrow = xbArrowOpen;
								} else {
							   var tmpArrow = xbArrowClose;
								}
 							if ((loopURL == "") || (prevLoopIdClass == "BrandHeading")) {
									if (globalMode == xbNS4) {
										//strOutput = clrLineOutput + strOutput;
									}
									strOutput = strOutput + "<td width=\"" + bmpGifLen + "\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"" + bmpGifLen + "\" height=\"1\" alt=\"\" border=\"0\"></td>";				
									strOutput = strOutput + "<td width=\"" + bmpTextLen + "\"><a " + xbElementName + " href=\"" + loopLink + "\"" + loopLinkDir + " class=\"snavHi\">" + loopText + "<img " + xbElementName + " class=\"arrow\" src=\"" + tmpArrow + "\" width=\"10\" height=\"10\" alt=\"\" border=\"0\"></a></td>";	
								} else {
									strOutput = strOutput + "<td width=\"" + bmpGifLen + "\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"" + bmpGifLen + "\" height=\"1\" alt=\"\" border=\"0\"></td>";				
									strOutput = strOutput + "<td width=\"" + bmpTextLen + "\"><a " + xbElementName + " href=\"" + loopLink + "\"" + loopLinkDir + " class=\"snavHi\">" + loopText + "</a></td>";				
								}
					//Generic Html for all other classes*********************
					} else {
							strOutput = strOutput + "<tr valign=\"top\">";
							strOutput = strOutput + "<td width=\"4\"><img " + xbElementName + " class=\"carrot\" src=\"" + carrotGif +  "\" width=\"4\" height=\"10\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td width=\"" + bmpGifLen + "\"><img " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"" + bmpGifLen + "\" height=\"1\" alt=\"\" border=\"0\"></td>";				
							strOutput = strOutput + "<td width=\"" + bmpTextLen + "\"><a " + xbElementName + " href=\"" + loopLink + "\"" + loopLinkDir + " class=\"snavHi\">" + loopText + "</a></td>";				
							strOutput = strOutput + "<td width=\"4\"><img  " + xbElementName + " src=\"" + xbClearGif +  "\" width=\"4\" height=\"1\" alt=\"\" border=\"0\"></td>";
					} // End Class Specific HTML
						strOutput=  strOutput + "</tr></table>";
						if (loopClassName != "BrandTool") {
							strOutput =  strOutput + itemEnd;
						}	
						if (loopClassName == "SectionHeading") {
							docOutput(lineOutput);
						}
						docOutput(strOutput);
//						if (loopClassName == "SectionHeading") {
//							docOutput(lineOutput);
//						}

					//} Remove filter on brand section label
					//Controls Indent and line output
					if (loopClassName == "BrandPageGroup") {
						isPageGroupParent = true;
						if (pageGroupLength == -1) {
							pageGroupLength = loopIdLength;
							removeLen = 6;
						} else {
							removeLen = ((loopIdLength - pageGroupLength) * 6)
						}
						bmpGifLen = cnstGifLen + removeLen;
						bmpTextLen  = cnstTextLen - removeLen;
						//alert(loopText + " Going In: " + bmpGifLen + " Text Len " + bmpTextLen + " Page Group Len:" + pageGroupLength + " Diff: " + (loopIdLength - pageGroupLength) + " Loop Len " + loopIdLength); 
					}
				var prevLoopIdClass = loopClassName;
			} //If Output to Nav
			// End Menu Ouput *******************************************
			if (loopClassName == "BrandPageGroup") {
				//onStartBrandPageGroup = true;
				//onEndBPGArray[loopIdLength] = loopId;
				//alert(onEndBPGArray.toString());
			} else {
				onStartBrandPageGroup = false;
				//onEndBPGArray[loopIdLength] = loopId;
			}
		} 	//End tocTab Loop
		//Ends the Div Container***********************************
		itemEnd = contArray[3];
//		document.writeln(lineOutput);
		document.writeln(bttmSpacerLine);
		strOutput =  itemEnd;
		document.writeln(strOutput);

	if ((queryIdLength != -1) && (globalMode != xbNS4)) {
		//alert("Got here");
		var parmId = "A" + lftnavIdDelimit + parentStack[queryIdLength-1];
		LN_init_direct(parmId);
	}
	//alert("I am at end");
}

/*--------Function WM_initialize_toolbar--------------
The following function is called on page load to set the
initial state of the menu		
----------------------------------------*/

function WM_initialize_toolbar(){
	//Called onPage Load
}

function docOutput(iOutput) {
		//alert("I wrote: " + iOutput);
		document.writeln(iOutput);
		//resCont.document.writeln(iOutput);
}

function LN_init_direct(parmId) {
	//Working Storage
	var idArray = parmId.split(lftnavIdDelimit);
	var idArrayLength = idArray.length;
	var compareId = -1;				//Used to compare ids withou special characters
	var isExclusiveMode = false;			//Checks to see we looping undera toggled label
	var exclusiveLength = -1;			//The length of the toggled menu id
	var hiddenLength = -1;				//Hides menu items that are greater than this length
	var toggleColor = "";				//Controls the BackGround of the Elements
	var isToggleColor = false;
	var toggleColorLength = -1;
	var parentStack;
	var isBrandSectionLabel = false;
	var isBrandGroupSelected = false;

	//Create an id stripped of special characters
	for (y=0; y<idArrayLength; y++) {
		if (y==0) {
			//skip special character
		} else if (y==1) {
			compareId = idArray[y];
		} else {
			compareId = compareId + lftnavIdDelimit + idArray[y];
		}
	}
	//alert("I am New: "  + parmId + ":" + globalMode);

	if (globalMode == xbNS6) {
		var docArray = new Array();
		//alert(document.getElementById('container').id);
		//var elements = document.getElementsByName('container');
		var docArray = document.getElementsByName('AGLeftNav');
		//alert("Got Here: " + globalMode + " Length: " + docArray.length);
	} else if (globalMode == xbIE) {
		var docArray = document.all('container').all;
	}

	//Loop at the Document Model ***************************************************
	for(i = 0; i < docArray.length; i++){	
		isBrandSectionLabel = false;
		//Only Adjust Div Elements
		if (docArray[i].tagName == "DIV") {	
			//Working Storage for loop
			var isToggleLabel = false;				//Is the menu a toggled label
			//var loopId = document.all('container').all[i].id;
			var loopId = docArray[i].id;
			var compareLoopId = -1;
			var loopIdArray = loopId.split(lftnavIdDelimit);
			var loopIdLength = -1;
			//var loopClassName = document.all('container').all[i].className;
			var loopClassName = docArray[i].className;
			var hideItem = false;
			var isDirectlyUnder = true;
			//alert("In First " + docArray[i].innerText + " : " + loopClassName + " : " + docArray[i].innerHTML);

			if (loopIdArray[loopIdArray.length-1].indexOf("bl") > -1) {
				loopIdLength = loopIdArray.length - 1;
				isToggleLabel = true;
			} else {
				loopIdLength = loopIdArray.length;
				isToggleLabel = false;
			}

			//Create an id stripped of special characters
			for (y=0; y<loopIdLength; y++) {
				if (y==0) {
					//skip special character
				} else if (y==1) {
					compareLoopId = loopIdArray[y];
				} else {
					compareLoopId = compareLoopId + lftnavIdDelimit + loopIdArray[y];
				}
			}

			//Adjust Exclusive Mode
			if (isExclusiveMode) {
				if (loopIdLength == exclusiveLength) {
					isExclusiveMode = false;
					exclusiveLength = -1;
					hiddenLength = -1;					
				}
			}

			//Adjust ToggleColor Mode
			if ((isToggleColor) && (loopIdLength <= toggleColorLength)) {
				isToggleColor = false;
				 toggleColorLength = -1;
				//alert("Adjust: " + document.all('container').all[i].innerText);
			}

			// Main filter if section *******************************************
			if ((loopClassName == "GlobalTool") || (loopClassName == "GlobalLabel")) {
				//Always display these types
				hideItem = false;
				//Toggles Color for Global Tools Sub Items
				if (compareLoopId == compareId) {
					//isToggleColor = true;
					//toggleColorLength = loopIdLength;
					isBrandGroupSelected = true;
				} else if (check_Directly_Under(loopIdLength, loopIdArray, idArray)) { 
					isToggleColor = true;
					toggleColorLength = loopIdLength;
					isBrandGroupSelected = true;
				} else {
					//isBrandGroupSelected = false;
					isToggleColor = false;
					toggleColorLength = -1;
				}

			//Bug Fix 2
			} else if (loopClassName == "BrandHeading") {
				//Always display these types
				//alert("Got Here: " + isBrandGroupSelected)
				if ((compareLoopId == compareId) || (isBrandGroupSelected)) {
					hideItem = false;
				} else if (check_Directly_Under(loopIdLength, loopIdArray, idArray)) { 
					hideItem = false;
				} else {
					hideItem = true;
				}
			} else if ((loopClassName == "SectionHeading") || (loopClassName == "SectionLabel")) {
				//alert("Got Here SH: " + compareLoopId + " : " + compareId + " : " + loopId); 
				if (isBrandGroupSelected) {
					if (loopId.indexOf("blON") > -1) {
					   hideItem = false;
					} else {
					   hideItem = true;
					}
				} else if (compareLoopId == compareId) {
					hiddenLength = loopIdLength;
					if (loopId.indexOf("blON") > -1) {
					   hideItem = false;
					} else {
					   hideItem = true;
					   isBrandGroupSelected = true;
					}
				} else {
					if (loopId.indexOf("blON") > -1) {
					   hideItem = true;
					} else {
					   hideItem = false;
					}
				}
				//Always display these types
				//hideItem = false;
			} else if ((loopIdLength > hiddenLength) && (hiddenLength != -1)) {
				//Always hide these item to be toggled on the screen
				hideItem = true;
				//alert("I am Hiding");
			} else if ((isExclusiveMode) && (loopIdLength == exclusiveLength + 1)) {
				if ((compareLoopId == compareId) || (check_Directly_Under(loopIdLength, loopIdArray, idArray))) {
					hideItem = false;
					hiddenLength = -1;
					//Toggle Color
					if (compareLoopId == compareId) {
						isToggleColor = true;
						toggleColorLength = loopIdLength;
					} else if (check_Directly_Under(loopIdLength, loopIdArray, idArray)) { 
						isToggleColor = true;
						toggleColorLength = loopIdLength;
					} else {
						isToggleColor = false;
						toggleColorLength = -1;
					}
				} else {
					hideItem = true;
					hiddenLength = loopIdLength + 1;
				} 
			} else if (loopClassName == "BrandSectionLabel") {
				isBrandSectionLabel = true;
				if (loopIdArray[loopIdArray.length-1].indexOf("bl") > -1) {
					if ((idArrayLength < loopIdLength) || (compareLoopId == compareId)) {
						if (loopIdArray[loopIdArray.length-1].indexOf("blON") > -1) {
							hideItem = false;
						} else if (loopIdArray[loopIdArray.length-1].indexOf("blOFF") > -1) {
							hideItem = true;
						}
					} else if (check_Directly_Under(loopIdLength, loopIdArray, idArray)) {
						if (loopIdArray[loopIdArray.length-1].indexOf("blON") > -1) {
							hideItem = true;
						} else if (loopIdArray[loopIdArray.length-1].indexOf("blOFF") > -1) {
							hideItem = false;
							isExclusiveMode = true;
							exclusiveLength = loopIdLength;
							hiddenLength = loopIdLength + 1;
						}
					} else {
						if (loopIdArray[loopIdArray.length-1].indexOf("blON") > -1) {
							//hideItem = true;
							hideItem = false;
						} else if (loopIdArray[loopIdArray.length-1].indexOf("blOFF") > -1) {
							//hideItem = false;
							hideItem = true;
							isExclusiveMode = true;
							exclusiveLength = loopIdLength + 1;
							hiddenLength = loopIdLength + 1; // + 1
						}
					}
				} else {
					hideItem = false;
				}
			} else if (loopClassName == "BrandPageGroup") {
				hideItem = false;
				//if (idArrayLength < loopIdLength) {
				if (((idArrayLength < loopIdLength) || (compareLoopId != compareId)) && !(check_Directly_Under(loopIdLength, loopIdArray, idArray)))
				{
					hiddenLength = loopIdLength;
				}
				if (check_Directly_Under(loopIdLength, loopIdArray, idArray)) {
					hiddenLength = -1;
				}
				if ((docArray[i].innerHTML.indexOf("ico_arrow_open") > -1) && (compareLoopId == compareId)) {
					hiddenLength = loopIdLength;
				}

				//Toggles Color
				if ((compareLoopId == compareId) && (toggleColorLength == -1))   {
					if (docArray[i].innerHTML.indexOf("ico_arrow_close") > -1) {
						isToggleColor = true;
						toggleColorLength = loopIdLength;
					} else {
						isToggleColor = false;
						toggleColorLength = -1;
					}
				} else if (((check_Directly_Under(loopIdLength, loopIdArray, idArray)) && (compareLoopId != compareId)) && (toggleColorLength == -1)) { 
					isToggleColor = true;
					toggleColorLength = loopIdLength;
				} else if ((isToggleColor) && (loopIdLength > toggleColorLength )) {
					isToggleColor = true;
				} else {
					isToggleColor = false;
					toggleColorLength = -1;
				}
				
			} else {  
			//End Main Filter Section
				hideItem = false;	
			}	
			//Logic for physically hiding the item on the screen
			if (hideItem) {
				if (globalMode == xbNS6) {
					docArray[i].style.display = 'none';
					//alert("Got Here");
				} else {
					docArray[i].style.display = 'none';
				}
			} else {
				if (globalMode == xbNS6) {
					docArray[i].style.display = 'block';
				} else {
					docArray[i].style.display = '';
				}
			}
		} else if (docArray[i].tagName == "TD") {
			if ((isToggleColor) && (loopClassName == "BrandSectionLabel")) {
				docArray[i].className = "bgSnavHiOn";
			}
		} else if (docArray[i].tagName == "TABLE") {
			if (isToggleColor) {
					if (isBrandSectionLabel) {
						docArray[i].className = "bgSnavHiOn";
					} else {
						docArray[i].className = "bgSnavHi";
					}
				} else {
					docArray[i].className = "bgSnav";
			}
		} else if (docArray[i].tagName == "A") {	
			if (compareLoopId == compareId) {
				docArray[i].className = "snavHiOn";
			} else {
				docArray[i].className = "snavHi";
			}
		} else if (docArray[i].tagName == "IMG") {
			if (docArray[i].className == "carrot") {
				if (compareLoopId == compareId) {
					docArray[i].src = xbCarrot;
				} else {
					docArray[i].src = xbClearGif;
				}
			} else if (docArray[i].className == "arrow") {
				if (hiddenLength == -1) {
					if (isToggleColor) {
						docArray[i].src = xbArrowOpenHi
					} else {
						docArray[i].src = xbArrowOpen;
					}
				} else {
					if (isToggleColor) {
						docArray[i].src = xbArrowCloseHi
					} else {
						docArray[i].src = xbArrowClose;
					}
				}
			}
		} //End Div Check
	} //End Document Loop
	//alert("I am End");
}

function check_Directly_Under(iLength, iLoopArray, iIdArray) {
		isDirectlyUnder = true;

		for (y=1; y<iLength; y++) {
			if (iLoopArray[y] != iIdArray[y]) {
				isDirectlyUnder = false;
				break;
			}
		}
		return isDirectlyUnder;
}
