function gotoURL(url) {
	location.href=url;
}
function check_location(page_path){
	var temp=page_path;
	return temp.indexOf("/nexus/preview/");
}
function replace_(node_name){
	var temp = node_name;
	while (temp.indexOf("_")>-1){
		temp=temp.replace("_"," ");
	}
	return temp;
}
function getUL(){
	var ULnum = document.getElementsByTagName("UL");
	return ULnum.length;
}

function rewrite_URL(){
	var LI_obj= document.getElementsByTagName("LI");
	for(j=0;j<LI_obj.length;j++){
		var href_obj=LI_obj[j].getElementsByTagName("a")[0].getAttribute("href",2);
		LI_obj[j].getElementsByTagName("a")[0].setAttribute("href","/"+href_obj);

	}
}
function add_slash_to_folders(){
	var LI_obj= document.getElementsByTagName("LI");
	for(j=0;j<LI_obj.length;j++){
		var href_obj=LI_obj[j].getElementsByTagName("a")[0].getAttribute("href",2);
		if(href_obj.indexOf(".html")==-1 && href_obj.indexOf(".xml")==-1){href_obj=href_obj+"/";
			LI_obj[j].getElementsByTagName("a")[0].setAttribute("href",href_obj);
		}

	}
}


function rearrange(){
	var ULArray = getUL(); // Get the number UL elements on the menu.
	if(navigator.appName.indexOf("Microsoft")!=-1){// For browser compatibility.
		class_name="className";
	}
	if (ULArray>1){ // If UL element is more than one (sub menu)
		var ulIdArray = document.getElementsByTagName("UL");// Get the UL elements as an array.
		for (var i=(ULArray-1) ; i>0 ; i--){ // Loop thru the UL elements
			// Get the Id of the UL element
			var ulId = ulIdArray[i].getAttribute('id');
			// See if there's an UL id on an LI element inside another UL.
			var liId = document.getElementById(ulId+"_li");
			if(liId!=null){// If liId is not null means there is an LI equivalent
				// Put class on for the LI element where the UL's id matched.
				//liId.getElementsByTagName("a")[0].setAttribute(class_name,"on");
				// Append UL element to the LI equivalent.
				if(document.getElementById(ulId).hasChildNodes()){
					document.getElementById(ulId+"_li").appendChild(document.getElementById(ulId));
					document.getElementById(ulId+"_li").getElementsByTagName("a")[0].setAttribute('className',"off");
					document.getElementById(ulId+"_li").getElementsByTagName("a")[0].setAttribute('class',"off");
				} else {
					document.getElementById(ulId).removeNode(true);
				}

			}// End if liId!=null
			else {// If there is no LI equivalent, then UL element(s) must be hidden or from another site.
				if(ulId=="Website"){// If ulId is website, then this is another site.
					// Get the div object/node where the menu items are located.
					var main_menu_div =document.getElementById("nav");
				 	for(var j=i; j>0;j--){// Loop to the rest of the UL elements which are not part of the site.
						// Remove the UL elements.
						main_menu_div.removeChild(document.getElementById(ulIdArray[j-1].getAttribute('id')));
					}// End of For loop
					i=0;// To exit the main For loop.
				}// End of If ulId is Website
				else { // If ulId is not Website (this folder and anything inside are hidden)
					// Remove the UL elements.
					document.getElementById("nav").removeChild(document.getElementById(ulId));
				}// End of Else   
			}//End of Else
			
		}// End of For loop
	}// End of if there are more than one UL elements
	//alert(page_name);
	//alert("Attribute: "+ document.getElementById(page_name+"_li").getAttribute('class'));
	// Check if the page is visible. If it is, then put the class on attribute.
	if (document.getElementById(page_name+"_li")!=null){
			//alert("Page: "+page_name+"_li  Attribute: "+ document.getElementById(page_name+"_li").getAttribute('class'));
			//document.getElementById(page_name+"_li").setAttribute('class',"navon");
			document.getElementById(page_name+"_li").getElementsByTagName("a")[0].setAttribute('className',"on");
			document.getElementById(page_name+"_li").getElementsByTagName("a")[0].setAttribute('class',"on");
	}// End if page_name_li is not null
	if	((node_name=="pagenotfound" | node_name=="pagemoved") && check_location(preview)==-1){ // If page is filenotfound and not on preview
		rewrite_URL(); // Rewrite URL.
	}
	add_slash_to_folders(); // Add slash '/' at the end if the link is a folder. 301 fix for folders link.
}
