// JavaScript Document

/* 


*/
var childFound = false;


function openChildren(node){
	 for(var c=0;c<node.childNodes.length;c++){
		if(node.childNodes[c].nodeName=="UL"){
			node.childNodes[c].style.display="block";
		}
	 }
}


function highlightMenu(n) { // n is a Node
 	/*
		var children = n.childNodes; // Now get all children of the ul object (li's)
		var breadCrumb = document.getElementById("breadcrumb");
		
		var breadCrumbLinks = breadCrumb.innerHTML.split("</LI>");
		
		for(b=0; b<breadCrumbLinks.length;b++){
			breadCrumbLinks[b] = breadCrumbLinks[b].substring(breadCrumbLinks[b].indexOf("tabid")+6, breadCrumbLinks[b].indexOf("/Default"));
		}
		alert(children[2].nodeName)
		
		for(var i=0; i < children.length; i++) { // Loop through the children
			if(children[i].nodeName=="LI"){
				if(children[i].firstChild.nodeName == "A"){ // get all the 'A' tags
						var linkId = children[i].firstChild.getAttribute("href").substring(children[i].firstChild.getAttribute("href").indexOf("link=")+5,children[i].firstChild.getAttribute("href").indexOf("&"));
						for(var r=0;r<breadCrumbLinks.length;r++){
							if(breadCrumbLinks[r]==linkId){
								children[i].className="selected";
							}
						}
				}
			}
		}
		 
	*/
	var children = n.childNodes; // Now get all children of n
	var breadCrumb = document.getElementById("breadcrumb");
	var breadCrumbLinks;
	if(document.all){	
		breadCrumbLinks = breadCrumb.innerHTML.split("</LI>");
	}else{
		breadCrumbLinks = breadCrumb.innerHTML.split("</li>");
	}
	for(b=1; b<breadCrumbLinks.length;b++){
		breadCrumbLinks[b] = breadCrumbLinks[b].substring(breadCrumbLinks[b].indexOf("tabid")+6, breadCrumbLinks[b].indexOf("/Default"));
	}
		
		
	for(var i=0; i < children.length; i++) { // Loop through the children
	
		 if(children[i].nodeName == "A"){ // get all the 'A' tags
		 // extract the page number from the href string...

			
			
			var linkId;

			if(document.all){
				linkId = children[i].getAttribute("href").substring(children[i].getAttribute("href").indexOf("link=")+5,children[i].getAttribute("href").indexOf("&"));
			}else{
				linkId = children[i].href.substring(children[i].href.indexOf("link=")+5,children[i].href.indexOf("&"));
			}
			
			for(var r=0;r<breadCrumbLinks.length;r++){
				if(breadCrumbLinks[r]==linkId){
					children[i].parentNode.parentNode.parentNode.parentNode.className="selected";
					children[i].parentNode.parentNode.parentNode.className="selected";
					children[i].parentNode.parentNode.className="selected";
					children[i].parentNode.className="selected";
					children[i].className="selected";
				}
			}
			/*
			if(children[i].getAttribute("href")!=null)
			 if(children[i].getAttribute("href").indexOf('link=')!=-1){
				 var thisChannel = children[i].getAttribute("href").substring(children[i].getAttribute("href").indexOf('link=')+5,children[i].getAttribute("href").indexOf('&'));
				
			 }
			
			 
			 // if the current 'A' tag link to a page matches the current page number
			 if(thisChannel == currentPage){
				
//				children[i].parentNode.parentNode.style.display="block";
				if(children[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName=="UL"){ //third level nav
					children[i].parentNode.parentNode.parentNode.parentNode.style.display="block";
					children[i].parentNode.parentNode.parentNode.parentNode.parentNode.className ="open";
					children[i].parentNode.parentNode.parentNode.className = "selected";	
				}
				else if(children[i].parentNode.parentNode.parentNode.parentNode.nodeName=="UL"){ // second level nav
					children[i].parentNode.parentNode.style.display="block";
					children[i].parentNode.parentNode.parentNode.className ="open";
					children[i].parentNode.className = "selected";	
				}else{ //first level nav
					children[i].parentNode.parentNode.style.display="block";
					children[i].parentNode.parentNode.parentNode.className ="open";
					children[i].parentNode.className = "selected";	
					openChildren(children[i].parentNode); // we need to check if our page has children as they should "open" 
					
				}
				
			 }
			*/
		 }
		 
		 childTag = highlightMenu(children[i]); // Recurse on each one

	 }/**/
}

function highlightTopMenu(n){
		
		var children = n.childNodes; // Now get all children of the ul object (li's)
		var breadCrumb = document.getElementById("breadcrumb");
		
	if(breadCrumb!=null){
		var breadCrumbLinks = breadCrumb.innerHTML.split("</LI>");
		
		for(b=0; b<breadCrumbLinks.length;b++){
			breadCrumbLinks[b] = breadCrumbLinks[b].substring(breadCrumbLinks[b].indexOf("tabid")+6, breadCrumbLinks[b].indexOf("/Default"));
		}
		
		for(var i=0; i < children.length; i++) { // Loop through the children
			if(children[i].nodeName=="LI"){
				if(children[i].firstChild.nodeName == "A"){ // get all the 'A' tags
						var linkId = children[i].firstChild.getAttribute("href").substring(children[i].firstChild.getAttribute("href").indexOf("link=")+5,children[i].firstChild.getAttribute("href").indexOf("&"));
						for(var r=0;r<breadCrumbLinks.length;r++){
							if(breadCrumbLinks[r]==linkId){
								children[i].className="selected";
							}
						}
				}
			}
		}
	}
}


function topNavNewWindow(headerNav){
	var children = headerNav.childNodes; // Now get all children of n
	
	for(var i=0; i < children.length; i++) { // Loop through the children

		 if(children[i].nodeName == "LI"){ // get all the 'A' tags
		 	if(children[i].firstChild.getAttribute("href").indexOf('http://www.business')!=-1){
				children[i].firstChild.target ="_blank";
			}
		 }
	}
	
}
function highlightTab(n){
		
		var children = n.childNodes; // Now get all children of the ul object (li's)
		
		for(var i=0; i < children.length; i++) { // Loop through the children
			if(children[i].nodeName=="LI"){
				if(children[i].firstChild.nodeName == "A"){ // get all the 'A' tags
						var linkId = children[i].firstChild.getAttribute("href").substring(children[i].firstChild.getAttribute("href").indexOf("link=")+5,children[i].firstChild.getAttribute("href").indexOf("&"));
					if(location.href.indexOf(linkId)!=-1){
						//children[i].firstChild.style.color="#F35700";
						children[i].firstChild.className="on";
					}
				}
			}
		}
}
if(document.getElementById("IconBar.ascx_lblMode")==null) {
	if(document.getElementById("tertiary_list_nav") !=null){
		var tabBlock=document.getElementById("tertiary_list_nav");
		highlightTab(tabBlock);
	}

	if(document.getElementById("header_nav") !=null){
		var headerNav = document.getElementById("houseMenuVstatic0");
		topNavNewWindow(headerNav);
	}
}
	if(document.getElementById("dnn_LeftPane") !=null){
		var leftNav = document.getElementById("dnn_LeftPane");
	}
	var topNav = document.getElementById("main_nav");

	var cp_indexOfTabid = window.location.href.indexOf("tabid")+6;
	var cp_indexOfSlashDefault = window.location.href.indexOf("/Default.aspx");
	var currentPage = window.location.href.substring(cp_indexOfTabid, cp_indexOfSlashDefault);

	if(document.getElementById("IconBar.ascx_lblMode")==null) {
		highlightTopMenu(topNav);
		document.write('<style>#lh_nav_container ul li ul{display:none;}#lh_nav_container ul li ul li ul{display:none;}</style>');
		if(document.getElementById("dnn_LeftPane") !=null){
				highlightMenu(leftNav);
		}
		
	}

