var newsBox1Wait = 8000;

xmlDoc = loadXML("xml/news.xml");

var x = xmlDoc.documentElement;
var y = xmlDoc.getElementsByTagName('item');
//var y = xmlDoc.documentElement.childNodes;
var numMessages = y.length;

function loadXML(dname)
	{
	var xmlDoc;
	if (window.ActiveXObject)
		{
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument)
		{
		xmlDoc=document.implementation.createDocument("","",null);
		}
	else
		{
		alert('Your browser cannot handle this script');
		}
	xmlDoc.async=false;
	xmlDoc.load(dname);
	return(xmlDoc);
	}

function NewsBox1Update()
	{
	//document.write(y.item(4).childNodes[5].attributes[0].value);
	getText();
	}
	
function getText()
	{
	Index = Math.floor(Math.random()*numMessages);
	
	while (y.item(Index).nodeType==3)
		{
		Index++;
		if (Index>=numMessages)
			{
			Index = 0;
			}
		}
	var text = "";
	for (z=0;z<y.item(Index).childNodes.length;z++)
		{
		if (y.item(Index).childNodes[z].nodeType!=3)
			{
			if (y.item(Index).childNodes[z].nodeName=="title")
				{
				text = text + "<h3>" + y.item(Index).childNodes[z].childNodes[0].nodeValue + "</h3><hr>";
				}
			else if (y.item(Index).childNodes[z].nodeName=="description")
				{
				text = text + y.item(Index).childNodes[z].childNodes[0].nodeValue + "<br />";
				}
			else if (y.item(Index).childNodes[z].nodeName=="link")
				{
				var linkURL = y.item(Index).childNodes[z].childNodes[0].nodeValue;
				var extSite = y.item(Index).childNodes[z].attributes[0].value;
				if (extSite=="No")
					{
					text = text + "<a href='" + linkURL + "'>See here for more details</a>";
					}
				else
					{
					text = text + "<a href='" + linkURL + "' onclick='return disp_confirm();'>See here for more details</a>";
					}
				}
			else if (y.item(Index).childNodes[z].nodeName=="email")
				{
				var emailText = y.item(Index).childNodes[z].childNodes[0].nodeValue;
				var address = y.item(Index).childNodes[z].attributes[0].value;
				
				text = text + "<br /><a href='mailto:" + address + "'>" + emailText + "</a>";
				}
			}
		}
	document.getElementById('NewsBox1').innerHTML = text;
	newsTimer = setTimeout("getText()",newsBox1Wait);	
	}

function ResetNewsTimer()
	{
	newsTimer = setTimeout("getText()",newsBox1Wait);
	}
