//Tips xml format
//<tips>        <tip>   <date></date>   <quote></quote>   </tip>        </tips>


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!

function loadtipsXML(xmlFile) {  
//Anne's note - this reads in the xml file named in the 'function call' line in html, then creates an object called xmltipDoc to store the xml data
	// code for Mozilla, Firefox, Opera, etc.
	if (document.implementation && document.implementation.createDocument)
	{
		if (debug) alert('Loading '+xmlFile);
		xmltipDoc = document.implementation.createDocument("", "", null);
		if (debug) alert('xmlDocument created: '+xmltipDoc);
		xmltipDoc.onload = function() {
			if (debug) alert('Loaded '+xmlFile);
			updateTip(xmltipDoc);   
		}
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		if (debug) alert('Loading '+xmlFile+' for IE');
		xmltipDoc = new ActiveXObject("Microsoft.XMLDOM");
		if (debug) alert('xmlDocument created: '+xmltipDoc);
		xmltipDoc.async=false;
		xmltipDoc.onreadystatechange = function () {
			if (xmltipDoc.readyState == 4) {
				if (debug) alert('Loaded '+xmlFile);
				updateTip(xmltipDoc);   
// Anne's note:  calling function "updateTip" - and telling it to use object called xmltipDoc
			}
		};             
// Anne's note:  now it's an object called xmltipDoc and it can have properties and be manipulated by the js
	}
	else
	{
		return;
	}
	xmltipDoc.load(xmlFile);
}

function updateTip(xmltipDoc) {
	var today = checkTime();
	if (debug) alert('Updating the page');
	for (i=0; i<=xmltipDoc.getElementsByTagName("tip").length-1; i++) {
		if (xmltipDoc.getElementsByTagName("date")[i].childNodes[0].nodeValue == today) {
			if (debug) alert('Using Tip No '+i);
			document.getElementById("tip").innerHTML = 	'<p>tip of the day:<br>' + xmltipDoc.getElementsByTagName("quote")[i].childNodes[0].nodeValue + '</p>';
		}
	}
}

function checkTime()
{

var d=new Date();

var month=new Array(12);
month[0]="Jan";
month[1]="Feb";
month[2]="Mar";
month[3]="Apr";
month[4]="May";
month[5]="Jun";
month[6]="Jul";
month[7]="Aug";
month[8]="Sep";
month[9]="Oct";
month[10]="Nov";
month[11]="Dec";


return (d.getDate()+' '+month[d.getMonth()]+' 10');

}
