// JavaScript Document
// function to load the xml
function loadXML()
{
var timestamp = new Date();
var uri = "xml/homePrograms.xml";
var uniqueURI = uri + (uri.indexOf("?") > 0 ? "&" : "?")+ "timestamp="+ timestamp.getTime();
	try
	{
		if (window.ActiveXObject)
		{
			var errorHappendHere = "Check Browser and security settings";
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async=false;
			xmlDoc.load(uniqueURI);
			getNav();
		}
		else if(window.XMLHttpRequest)
		{
			var errorHappendHere = "Error handling XMLHttpRequest request";
			var d = new XMLHttpRequest();
			d.open("GET", uniqueURI, false);
			d.send(null);
			xmlDoc=d.responseXML;
			getNav();
		} else {
			var errorHappendHere = "Error.";
			xmlDoc = document.implementation.createDocument("","",null);
			xmlDoc.async=false;
			xmlDoc.load(uniqueURI);
			xmlDoc.onload=getNav();
		}
	}	
	catch(e)
	{
		alert(errorHappendHere);
	}
}

// function to create needed navigation items from the loadXML function.
var getNav = function getImages()
{
	// create an object with all of the image nodes
	var xmlTopNodes=xmlDoc.getElementsByTagName("node")[0].getElementsByTagName("image"); 
	// find out how many top nodes there are
	var numTopNodes=xmlTopNodes.length; 
	// assign the number of images to a higher level variable for use in other functions
	topNodeCounter = numTopNodes; 
	// create a random number
	var randomNumber=Math.floor(Math.random()*topNodeCounter); 
	// get the value of the randomly selected image source
	var newImage = xmlDoc.getElementsByTagName("node")[0].getElementsByTagName("image")[randomNumber].getElementsByTagName("location")[0].childNodes[0].nodeValue;
	// get the value of the randomly selected image alt text
	var newAlt = xmlDoc.getElementsByTagName("node")[0].getElementsByTagName("image")[randomNumber].getElementsByTagName("alt")[0].childNodes[0].nodeValue;
	// get the value of the randomly selected image link path
	var newLinkPath = xmlDoc.getElementsByTagName("node")[0].getElementsByTagName("image")[randomNumber].getElementsByTagName("linkPath")[0].childNodes[0].nodeValue;
	// put everything together and create the image
	document.getElementById('programRotation').innerHTML = '<a href="' + newLinkPath + '" title="' + newAlt + '"><img src="' + newImage + '" border="0" /></a>'
}

// function to clear text from search box if default text exists
function clearSearch(){
	if(document.getElementById('searchBox').value == "SEARCH"){
		document.getElementById('searchBox').value = "";
	}
}

// function to add default text back if text box is blank
function addSearch(){
	if(document.getElementById('searchBox').value == ""){
		document.getElementById('searchBox').value = "SEARCH";
	}
}