
var container
var newElement
var newNode
var newText
var theText


if (document.implementation && document.implementation.createDocument)	{	//check for W3C DOM support
xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = insertFeed;

} else {
	if (window.ActiveXObject)	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) insertFeed()
		};
 	} else {
		alert('Your browser can\'t handle this script');
	}
}
xmlDoc.load("xml/waysidefeed.xml");	

window.setTimeout("getTheMenu()", 1000)



function AddLineBreak()	{
	var linebreak=document.createElement('br')
	container.appendChild(linebreak);
}

function AddNodeWithText()	{
	newText=document.createTextNode(theText)
	newNode.appendChild(newText)
	container.appendChild(newNode)
}

function insertFeed()	{

//access the stylesheet
document.getElementsByTagName('link')[0].setAttribute('href','css/waysidespringCSS.css')

container=document.getElementById('rightheader')
container.removeChild(container.childNodes[0])
var x = xmlDoc.getElementsByTagName('coverage')
for (var i=0; i<x.length; i++)	{
	theText=x[i].childNodes[0].nodeValue;
	newNode=document.createElement('span')
	AddNodeWithText()
	AddLineBreak()
	}

container = document.getElementById('rightcol'); 
if(container.childNodes[0].nodeType==1)	{	//inner DIV
	container=container.childNodes[0]	//IE
} else {
	container=container.childNodes[1]	//Mozilla
}

//setTimeout("javascript:void(0)", 1000);
container.removeChild(container.lastChild)	//get rid of ...loading...

theText=' '
newText=document.createTextNode(theText)
newNode=document.createElement('a')
newNode.appendChild(newText)
newNode.setAttribute('id','topofcolumn')
container.insertBefore(newNode,container.childNodes[0])



var sections=xmlDoc.getElementsByTagName('section')

//set up anchor list
for (i=0; i<sections.length; i++){
	var heading=sections[i].getElementsByTagName('h1')
	theText=heading[0].childNodes[0].nodeValue; //1 header per section
	newNode=newNode=document.createElement('a')
	newNode.setAttribute('href','#Section'+i)
	AddNodeWithText()
	AddLineBreak()
}
//

for (i=0; i<sections.length; i++){

//create the section anchors
	theText=' '
	newNode=document.createElement('a')
	newNode.setAttribute('id', 'Section'+i)
	AddNodeWithText()
//

	var heading=sections[i].getElementsByTagName('h1')
	theText=heading[0].childNodes[0].nodeValue; //1 header per section
	newNode=document.createElement('h1')
	AddNodeWithText()

	var items=sections[i].getElementsByTagName('item')
	for (j=0; j<items.length; j++)	{
		var theDate=items[j].getElementsByTagName('date').item(0)
		theText=theDate.childNodes[0].nodeValue
		newNode=document.createElement('span')
		newNode.className='date'
		AddNodeWithText()
		var theHeadline=items[j].getElementsByTagName('headline').item(0)
		theText=theHeadline.childNodes[0].nodeValue
		newNode=document.createElement('span')
		newNode.className='headline'
		AddNodeWithText()
		var theContent=items[j].getElementsByTagName('content').item(0)
		theText=theContent.childNodes[0].nodeValue
		newNode=document.createElement('span')
		AddNodeWithText()
		AddLineBreak()
		theURL=items[j].getElementsByTagName('linkURL').item(0).childNodes[0].nodeValue
		theText=items[j].getElementsByTagName('linktext').item(0).childNodes[0].nodeValue
		newNode=document.createElement('a')
		newNode.className='inline';
		newNode.setAttribute('href', theURL)
		AddNodeWithText()
		newElement=document.createElement('p')
		container.appendChild(newElement)
	}

theText='Return to top of column'
newNode=document.createElement('a')	
AddNodeWithText()
newNode.setAttribute('href','#topofcolumn')
newNode.className="backnav"

}

}	//end of insertFeed



//load menu


function getTheMenu()	{

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