
//Profile xml format
//<members>        
//     <member>   
//          <postname></postname>   <profile></profile>   <link></link>   <region></region>
//     </member>        
//</members>

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 loadprofileXML(xmlFile) {  
//Anne's note - this reads in the xml file named in the 'function call' line in html, then creates an object called xmlDoc to store the xml data
	// code for Mozilla, Firefox, Opera, etc.
	if (document.implementation && document.implementation.createDocument)
	{
		if (debug) alert('Loading '+xmlFile);
		xmlprofDoc = document.implementation.createDocument("", "", null);
		if (debug) alert('xmlDocument created: '+xmlprofDoc);
		xmlprofDoc.onload = function() {
			if (debug) alert('Loaded '+xmlFile);
			updateProfile(xmlprofDoc);   
		}
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		if (debug) alert('Loading '+xmlFile+' for IE');
		xmlprofDoc = new ActiveXObject("Microsoft.XMLDOM");
		if (debug) alert('xmlDocument created: '+xmlprofDoc);
		xmlprofDoc.async=false;
		xmlprofDoc.onreadystatechange = function () {
			if (xmlprofDoc.readyState == 4) {
				if (debug) alert('Loaded '+xmlFile);
				updateProfile(xmlprofDoc);   
// Anne's note:  calling function "updateQuote" - and telling it to use object called xmlprofDoc
			}
		};             
// Anne's note:  now it's an object called xmlprofDoc and it can have properties and be manipulated by the js
	}
	else
	{
		return;
	}
	xmlprofDoc.load(xmlFile);
}

function updateProfile(xmlprofDoc) {      
// Anne's note - this is the bit that actions the entry into the html page
	if (debug) alert('Updating the page');
	var profileNo= Math.round(Math.random() * (xmlprofDoc.getElementsByTagName("member").length-1));  
// Anne note - creates rand num based on num of elements called Member it finds, then converts e.g. 1 to 0 (first array number) and length here translates to object number
//	profileNo = 0;
	if (debug) alert('Using Member No '+profileNo);
	document.getElementById("profile").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>Member Profile:    &nbsp; &nbsp ' + xmlprofDoc.getElementsByTagName("postname")[profileNo].childNodes[0].nodeValue + '</b></h1>\n' +
	'<p>' + xmlprofDoc.getElementsByTagName("profile")[profileNo].childNodes[0].nodeValue + '</p>\n' +
	'<p><a href="http://www.secondlightlive.co.uk' + xmlprofDoc.getElementsByTagName("link")[profileNo].childNodes[0].nodeValue + '" style="float:right">link to poet page</a></p>\n' + 
	'<div style="clear:both"></div>\n';
				
}