// JavaScript Document

var xmlHttp;

function loadBody() {
	
	xmlhttp=null;
	
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (xmlhttp!=null)
	{
		xmlhttp.onreadystatechange=onResponse;
		xmlhttp.open("GET","http://www.genedaniellsound.com/Schedule/shows.xml",true);
		xmlhttp.send(null);
	}
	else
	{
		alert("Your browser is not supported by this page.");
	}
}

function checkReadyState(obj)
{
	if(obj.readyState == 4)
	{
		if (obj.status == 200)
		{
			return true;
		}
		else
		{
			alert("Problem retrieving XML data " + obj.status);
		}
	}
}

function onResponse()
{
	if(checkReadyState(xmlhttp))
	{
		var responseDoc = xmlhttp.responseXML;
		
		var sidebar = document.getElementById("sidebar");
		var sidebarText = "<h3>Show Schedule</h3>";
		
		var months = responseDoc.getElementsByTagName("month");
		
		for ( var index = 0; index < months.length; index++ )
		{
			var MonthName = "";
			
			for ( var attridx = 0; attridx < months[index].attributes.length; attridx++ )
			{
				if ( months[index].attributes[attridx].nodeName.toLowerCase() == "name" )
				{
					MonthName = months[index].attributes[attridx].nodeValue;
				}
			}
			
			sidebarText = sidebarText + "<h5>" + MonthName + "</h5>";
			
			var shows = months[index].getElementsByTagName("show");
			
			for ( var showidx = 0; showidx < shows.length; showidx++ )
			{
				var showName = "";
				var showCity = "";
				var showState = "";
				var showDates = "";
				
				for ( var attridx = 0; attridx < shows[showidx].attributes.length; attridx++ )
				{
					if ( shows[showidx].attributes[attridx].nodeName.toLowerCase() == "name" )
					{
						showName = shows[showidx].attributes[attridx].nodeValue;
					}
					
					if ( shows[showidx].attributes[attridx].nodeName.toLowerCase() == "city" )
					{
						showCity = shows[showidx].attributes[attridx].nodeValue;
					}
					
					if ( shows[showidx].attributes[attridx].nodeName.toLowerCase() == "state" )
					{
						showState = shows[showidx].attributes[attridx].nodeValue;
					}
					
					if ( shows[showidx].attributes[attridx].nodeName.toLowerCase() == "dates" )
					{
						showDates = shows[showidx].attributes[attridx].nodeValue;
					}
				}
				
				sidebarText = sidebarText + "<h6>" + showName;
				
				if ( showCity.toLowerCase() == "" )
				{
					sidebarText += "</h6>";
				}
				else
				{
					sidebarText += "<br>" + showDates + ", " + showCity + ",  " + showState + "</h6>";
				}
			}
		}
		
		sidebar.innerHTML = sidebarText;
	}
}
