//banner xml format
//<banners>        
//     <banner>   
//          <quote></quote>   <link></link>   
//     </banner>        
//</banners>

var debug = 0;  
// Anne's note:  zero for de-bugger off;   1 for de-bugger on.    
//With on, the alerts will then be visible and don't use any returns because that ends the comment! 
//If de-bug is set to 1 but you don't get the de-bug alerts, make sure the onload call in html 
//is asking for the full onload e.g. loadbannerXML not just loadXML

function loadbannerXML(xmlFile) {  
//Anne's note - this reads in the xml file named in the 'function call' line in html, then creates an object called xmlbannerDoc to store the xml data
	// code for Mozilla, Firefox, Opera, etc.
	if (document.implementation && document.implementation.createDocument)
	{
		if (debug) alert('Loading '+xmlFile);
		xmlbannerDoc = document.implementation.createDocument("", "", null);
		if (debug) alert('xmlDocument created: '+xmlbannerDoc);
		xmlbannerDoc.onload = function() {
			if (debug) alert('Loaded '+xmlFile);
			updateBanner(xmlbannerDoc);   
		}
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		if (debug) alert('Loading '+xmlFile+' for IE');
		xmlbannerDoc = new ActiveXObject("Microsoft.XMLDOM");
		if (debug) alert('xmlDocument created: '+xmlbannerDoc);
		xmlbannerDoc.async=false;
		xmlbannerDoc.onreadystatechange = function () {
			if (xmlbannerDoc.readyState == 4) {
				if (debug) alert('Loaded '+xmlFile);
				updateBanner(xmlbannerDoc);   
// Anne's note:  calling function "updateBanner" - and telling it to use object called xmlbannerDoc
			}
		};             
// Anne's note:  now it's an object called xmlbannerDoc and it can have properties and be manipulated by the js
	}
	else
	{
		return;
	}
	xmlbannerDoc.load(xmlFile);
}

function updateBanner(xmlbannerDoc) {      
// Anne's note - this is the bit that actions the entry into the html page
	if (debug) alert('Updating the page');
	var bannerNo= Math.round(Math.random() * (xmlbannerDoc.getElementsByTagName("banner").length-1));  
// Anne note - creates rand num based on num of elements called Banner it finds, then converts e.g. 1 to 0 (first array number) and length here translates to object number
//	bannerNo = 0;
	if (debug) alert('Using Banner No '+bannerNo);
	document.getElementById("banner").innerHTML = 
// Anne note innerHTML tells it to put it between the tags e.g. p or div and below is what it writes in to the html 
// + = concatenate
// single quote in these lines says don't interpret, just give me what I say (here, to enable html coding)
//without the quotes, it interprets as though a variable

	'<h1>Anne Stewart snippet:</h1>\n' +
	'<p>' + xmlbannerDoc.getElementsByTagName("quote")[bannerNo].childNodes[0].nodeValue + 
	'</p>\n' +
	'<h1><a href="http://' + xmlbannerDoc.getElementsByTagName("link")[bannerNo].childNodes[0].nodeValue + 
	'">link</a></h1>\n' + 
	'<div style="clear:both"></div>\n';
				
}
