
var newNode
var newText
var theText


if (document.implementation && document.implementation.createDocument)	{	//check for W3C DOM support
xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = insertMenu;					//Firefox uses this

} else {
	if (window.ActiveXObject)	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) insertMenu()
		};
 	} else {
		alert('Your browser can\'t handle this script');
	}
}
xmlDoc.load("xml/waysidemenu.xml");	



function insertMenu()	{

	container=document.getElementById('menu')
	var indxActive=container.childNodes[0].nodeValue*1; 	//marker for page indicator - convert to number
	container.removeChild(container.childNodes[0])		//remove it after saving the value
	var uList=document.createElement('ul')
	container.appendChild(uList);
	container=container.childNodes[0];				//ul
	var x = xmlDoc.getElementsByTagName('menuItem');
	for (var i=0; i<x.length; i++)	{		
		var theLink=x[i].getElementsByTagName('linkURL').item(0);
		var linkText=theLink.childNodes[0].nodeValue;
		var theItem=x[i].getElementsByTagName('itemName').item(0);
		var itemText=theItem.childNodes[0].nodeValue;
		var theDrop=x[i].getElementsByTagName('dropdown').item(0);
		var dropText=theDrop.childNodes[0].nodeValue;
		var newDrop=document.createElement('span');		
		var newAnchor=document.createElement('a');
		newText=document.createTextNode(itemText);		
		newAnchor.appendChild(newText);
		newAnchor.setAttribute('href', linkText);
		if (i == indxActive)	{
			newAnchor.setAttribute('id', 'active');
			newText=document.createTextNode('You are on this page');
		} else {
			newText=document.createTextNode(dropText);
		}
		newDrop.appendChild(newText);	
		newAnchor.appendChild(newDrop);
		var newListItem=document.createElement('li');
		newListItem.appendChild(newAnchor);
		container.appendChild(newListItem);
//structure is <li><a href={linkText}>itemText<span>dropText</span></a></li>	
	}

} //end of insertMenu