// JavaScript Document
var CllrInfo; // object holds the  recordset of councillor details
var xmlCouncillors;
var nMain;  // to hold main node of councillor

function showotherbutton(whichbutton,visibility){
	document.getElementById(whichbutton).style.visibility=visibility;
}

function errorDisplay(passedError, sField){
			alert( sField + " is Empty " +" error description is: " + passedError.description + "-- error message is: " + passedError.message);
}
	

function GetRecords(){
	/*allow for different browsers*/
	
	 <!-- If the browser has scripting turned on it will hide the warning-->
	document.getElementById("WarningNoneScript").style.visibility = "hidden";

	if (window.ActiveXObject){//Internet Explorer
		xmlCouncillors = new ActiveXObject("MSXML2.DOMDocument");
		xmlCouncillors.async = false; 
	}
	else if (document.implementation && document.implementation.createDocument){//Firefox
		xmlCouncillors = document.implementation.createDocument("","XML",null);
		xmlCouncillors.async = false;
	}
	else
	{
		alert('Your browser can\'t handle this script');
		return;
	}

	if (typeof xmlCouncillors!="undefined"){
		xmlCouncillors.load("councillors.xml");		
		
		CllrInfo = xmlCouncillors.documentElement;//gets object Nodelist  councillors elements in firefox but not ie
		try{
			nMain = CllrInfo.getElementsByTagName("councillor");// returns element of all councillors object
		}
		catch(eGetError){
				errorDisplay(eGetError, "xmldocument");
		}
	}
	else
		alert("Sorry! This Browser is not able to display the details. Please Update your Browser");
		
	GetDetails(0);
		
}

function GetDetails(nCllr){ // nCllr is the array representing the individual councillor eg 0 for Nancy Ashcroft -- 8 for Barbara walsh
	var sTitle = "Should Never Get this message"; //others are self explanatory
	var sAddress1 = "Not Available";
	var sAddress2 = "Not Available";
	var sTown = "St Helens";  //default to St Helens
	var sPostCode = "Not Available";
	var sTelephone = "Not Available";
	var	sPhoto ="Not Available";
	var	sResume ="Not Available";
			// if any XML fields are blank, can result in an error if not caught
	try{
		sTitle  = nMain[nCllr].getElementsByTagName("title")[0].firstChild.nodeValue;
	}
	catch(errorTitle){
		errorDisplay(errorTitle, "Title Field");
	}
	//Address Data
	try{
		sAddress1 = nMain[nCllr].getElementsByTagName("address1")[0].firstChild.nodeValue;
	}
	catch(errorAddress1){
		errorDisplay(errorAddress1, "Address1 Field");
	}
	try{
		sAddress2 = nMain[nCllr].getElementsByTagName("address2")[0].firstChild.nodeValue;
	}
	catch(errorAddress2){
		errorDisplay(errorAddress2, "Address2 Field");
	}
	try{
		sTown = nMain[nCllr].getElementsByTagName("town")[0].firstChild.nodeValue;
	}
	catch(errorTown){
		errorDisplay(errorTown, "Town Field");
	}
	try{
		sPostCode = nMain[nCllr].getElementsByTagName("postcode")[0].firstChild.nodeValue;
	}
	catch(errorPC){
			errorDisplay(errorPC, "PostCode Field");
  	}
	try{
		sTelephone = nMain[nCllr].getElementsByTagName("telephone")[0].firstChild.nodeValue;
	}
	catch(errorTel){
		errorDisplay(errorTel, "Telephone Field");
	}
	//Address Data
	try{
		sPhoto = nMain[nCllr].getElementsByTagName("photo")[0].firstChild.nodeValue;
	}
	catch(errorPhoto){
		errorDisplay(errorPhoto, "Photo Field");
	}
	try{
		sResume =nMain[nCllr].getElementsByTagName("resume")[0].firstChild.nodeValue;
	}
	catch(errorResume){
		errorDisplay(errorResume, "Resume Field");
	}
	//works to here in Firefox and Internet Explorer
	//now add info to main document
	
	if(document.getElementById){ // make sure the browser supports getEelementById
		document.getElementById("TitleHolder").innerHTML =sTitle;
		//Address Info
		document.getElementById("Address1").innerHTML =sAddress1;
		document.getElementById("Address2").innerHTML =sAddress2;
		document.getElementById("Town").innerHTML =sTown;
		document.getElementById("PostCode").innerHTML =sPostCode;
		document.getElementById("Telephone").innerHTML =sTelephone;
		//end Address
		//resume
		document.getElementById("ResumeHolder").innerHTML =sResume;
		//Now place the photo
		document.getElementById("PhotoHere").src = "Pictures/"+sPhoto;
	}
	else{
		alert("Sorry! This Browser is not able to display the details. Please Update your Browser");
	}
	
}
