

//CLG highlighting
var BC_CATALOGS_ON = 1;
var DEFAULT_HIGHLIGHT = 0;

function checkActive(modeParam) {
	var und;
	// li array
	var a = document.getElementsByTagName("li");

	var loc = window.location.href;

	//if modeParam undefined make it default
	if(!modeParam)
		modeParam = DEFAULT_HIGHLIGHT;
	


	if(modeParam == BC_CATALOGS_ON){
		//if page is not a BC product page
		if(!(loc.split("/_product_").length > 1) )
			defaultHighlight();
		//if page is a BC product page
		else
			BCProductpageHighlight();
	}
	else{
		defaultHighlight();
	}

}



//default tab menu highlighting
function defaultHighlight(){

	var und;
	// li array
	var a = document.getElementsByTagName("li");
	
	var firstlis = document.getElementById("firstContainer").getElementsByTagName("li");
	var secondlis = document.getElementById("secondContainer").getElementsByTagName("li");
	
	var loc = window.location.href;




	//if first layer link clicked

	for(var i=0; i < firstlis.length; i++){
		
		if(firstlis[i].getElementsByTagName("a")[0] && firstlis[i].getElementsByTagName("a")[0].href == loc){		
			firstlis[i].getElementsByTagName("a")[0].className="activated";		
		
			if(document.getElementById("sub_" + i)){
				document.getElementById("sub_" + i).style.display = "block";
				
			}
	
		}
	}
	
	


	//traverse all lis with <a> child defined
	for(var i=0; i < a.length; i++) {
		// <li> <a> </a>	</li>
		// if <a> child is defined
		if(a[i].getElementsByTagName("a")[0] != und){
			// <li> <a href=VALUE></a></li>
			//if href matches document.location.href
			if (a[i].getElementsByTagName("a")[0].href == loc) {
				a[i].getElementsByTagName("a")[0].className="activated";
		
		
				//alert("href: " + a[i].getElementsByTagName("a")[0].href +"\n loc: " + loc);
				//<li id="VALUE"><a></a></li>
				//if li id is empty or undef
				//if(a[i].id.length == 0){
				//alert("a[i] id: " + a[i].id);
				if(a[i].getAttribute("id") == null || a[i].getAttribute("id").length == 0){
					//if <ul parent> id contains "sib_"
					if((document.getElementById(a[i].parentNode.id.split("sib_")[1]) != null))
						document.getElementById(a[i].parentNode.id.split("sib_")[1]).getElementsByTagName("a")[0].className = "activated";
					
					// warren bug-fix 06/02 
					// add firstContainer parentnode check condition, in case submenu label has the same name with ul id. Bug occurred on CLG
					//if element with id: "sub_[a innerhtml]" exists and it's a child of firstContainer

					if(document.getElementById("sub_"+a[i].getElementsByTagName("a")[0].innerHTML) && 
					    a[i].parentNode.parentNode.getAttribute("id") == "firstContainer"){
					

						document.getElementById("sub_"+a[i].getElementsByTagName("a")[0].innerHTML).style.display="block";
					}

					
				}
									//alert("line 80:" + a[i].parentNode.id.split("sub_"));
			    //<ul style="display: block;" id="sub_BABY"><li><a></a></li></ul>
				if(a[i].parentNode.id.split("sub_").length > 1){

					//alert("in a[i].parentNode.id.split(sub_).length > 1 condition");
					//highlight when 2nd layer is clicked
					if(document.getElementById(a[i].parentNode.id.split("sub_")[1]) != null){
						document.getElementById(a[i].parentNode.id.split("sub_")[1]).className = "activated";
					}


					a[i].parentNode.style.display = "block";
					
					var subindex = 	a[i].parentNode.id.split("sub_")[1];	
	
					//add first layer highlight
					if(document.getElementById("firstContainer").getElementsByTagName("li")[subindex]){
						document.getElementById("firstContainer").getElementsByTagName("li")[subindex].getElementsByTagName("a")[0].className = "activated";
					}
					
				}
				
	
			}
		}
	}

	
}


//BC_CATALOGS_ON highlighting if page is a product page
function BCProductpageHighlight(){

	var und;
	// li array
	var a = document.getElementsByTagName("li");
	var loc = window.location.href;
	var found;
		
	//capture xxxx value from /_product_xxxx/ on window.location value
	var fid = delineate(loc);
		
	//alert("fid: "+ fid);
	for(var i=0; i < a.length; i++) {

		// if current link has occurrence of xxxx (fid) 
		if(a[i].getElementsByTagName("a")[0] && a[i].getElementsByTagName("a")[0].href.split(fid).length > 1){

			found = a[i];
			a[i].getElementsByTagName("a")[0].className = "activated";
			//if id of parent node of li contains 'sub_'
			//firstContainer struct: <ul> <li><a id=[parent menu label]></li></ul>
			// secondContainer struct: <ul id="sub_[parent menu label]> <li class=subLists_[submenu label] /> <li /> 
			if(a[i].parentNode.id.split("sub_").length > 1){
				
				if(document.getElementById(a[i].parentNode.id.split("sub_")[1]) != null){
					//make parent menu active
					document.getElementById(a[i].parentNode.id.split("sub_")[1]).className = "activated";
				}

				//make 2nd layer visible
				a[i].parentNode.style.display = "block";
			}
			
		}
	}
}

//Utility functions
//obtain xxxx from url: /_protuct_xxxx/pagename...
function delineate(str)
{
theleft = str.indexOf("_product_") + 9;
theright = str.lastIndexOf("/");
return(str.substring(theleft, theright));
}
