//
//  Sprint.com/business
//
//  Collapse the NavIII Left Side Menu
//   Based on identifiers set in the HTML page
//		
//		v1.0 PD 2006-03-15

var MAXNAVIII_LEVEL = 4;
var nav = new Array();


setNavStyles();
    

function setupLeftMenu(inArray) {
	if (!isBadBrowser()) {	   
		nav = inArray;
		addLoadEvent(doNav);
	}
}

// Show the first level of the nav and then recurse down the tree
function doNav() {
	doNavLevel(0);
}

function setNavStyles() {
	if (!isBadBrowser()) {
		var ssEl = getEl("styleSheetNavIII");
		if (ssEl!=null) {
			ssEl.disabled= false;
		}
	}
}

// Recursively show each branch of the tree, highlighting the correct LI element
//  based on the id params set in the page
//	  Returns true if a element is found to highlight
function doNavLevel(level) {
	debug("level:"+ level);

	if (!exists(nav[level]) ) return false;
	// string version of level numbers
	var thisLevel = ""+ (level+1);
	var nextLevel = ""+ (level+2);

	var parentLI = getEl("IIInav"+ thisLevel+"_"+ nav[level]);
	if (parentLI ==null) {
		return false;
	} else {
		// see if there's a child tree
		var treeUL = getEl("IIInav"+ nextLevel +"Tree_"+ nav[level]);
		if (treeUL == null) {
			// no tree, set parent class
			debug("level:"+ level +" - no tree found: " + "IIInav"+ nextLevel +"Tree_"+ nav[level]);
			addLinkClass(parentLI, "active spot");
			return true;
		} else {
			// tree exists, set parent classes
			parentLI.className += " activeLI";
			addLinkClass(parentLI, "active");
			// show the tree
			treeUL.style.display = "block";

			// set the next level recursively
			var childActive = false;
			if (level < MAXNAVIII_LEVEL-1) {
				childSelected = doNavLevel(level+1);
			}
			// if no level selected,
			//  make the item with the parent's name active by default
			if (!childSelected) {
				debug("level:"+ level +" no child");
				var defaultChildLI = getEl("IIInav"+ nextLevel +"_"+ nav[level]);
				if (defaultChildLI!=null) {
					addLinkClass(defaultChildLI, "active spot");
				}
			}
			return true;
		}
	}
}

	// set the class of the first A element in a block
	function addLinkClass(el, addClassName) {
		var linkEls = el.getElementsByTagName("a");
		if (linkEls.length > 0) {
			linkEls[0].className += " "+addClassName;
		}
	}

	// checks a string for a value
	function exists(str) {
		return (str!=null && str!="");
	}

	// wrapper for getElementById
	function getEl(eyedee) {
		return document.getElementById(eyedee);
	}


	var DEBUGALERT=false;
	function debug(msg) {
		if (DEBUGALERT) window.alert(msg);
	}

	// Checks for Browsers that do not have the level of DOM/CSS support needed for the dyno-menus.
	function isBadBrowser() 
	{
		var agent=navigator.userAgent.toLowerCase();

		var isOldNS = agent.indexOf("mozilla")>-1 && agent.indexOf("compatible")== -1 && (parseInt(navigator.appVersion)<=4);
		var isIEMac = agent.indexOf("msie")> -1 && agent.indexOf("mac")> -1;

		return (isOldNS || isIEMac);
	}


/* Thanks http://simon.incutio.com/archive/2004/05/26/addLoadEvent */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

