
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");	

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/waysideLammasCSS.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
}


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
