/**
 * Swaps a visible div held in a div area with id 'screen' as the first child node with an
 * invisible div held in a div area with id 'holdingdiv' given as an argument.
 * @author danielconn
 * ©2011 Daniel Conn
 * 
 */
 
var xmlHttp;
var response;

function swapdiv(firstDiv)
{
	var screenDiv = document.getElementById('screen');
	var holdingDiv = document.getElementById('holdingdiv');
	var theFirstDiv = document.getElementById(firstDiv);
	var theSecondDiv = screenDiv.firstChild;
	if (!(theFirstDiv == theSecondDiv))
	{
	var theSecondDiv = holdingDiv.appendChild(theSecondDiv);	
	
	screenDiv.insertBefore(theFirstDiv, screenDiv.firstChild);
	
	theFirstDiv.style.display="block";
	theFirstDiv.style.visibility="visible";
	theSecondDiv.style.display="none";
	theSecondDiv.style.visibility="hidden";
	}
	holdingDiv.style.visibility="hidden";
    theFirstDiv="";
	theSecondDiv="";
}

function createXMLRequest()
{
	
	xmlHttp = false;
	// Ensure correct object is created whether IE 5,6,7,8, or 9.
	try
	{
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.6.0");
	}
	catch (e)
	{
		try 
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
		}
		catch (e2)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e3)
			{
				xmlHttp = false;
			}
		}
	}
	try
	{
		// non IE & 7, 8, 9.
		xmlHttp = new XMLHttpRequest();
	
	}
	catch (failed)
	{
		//Browser unsupported
		alert("Sadly your browser does not support this function. Please update your browser for full website functionality.");
		xmlHttp = false;
	}
	
	return xmlHttp;
}

function getXML(aURL)
{

	xmlHttp = createXMLRequest();
	var url = aURL;
	
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState == 4)
		{
			if (xmlHttp.status == 200)
			{
			var myDiv1 = document.getElementById("AJAXDiv");
			myDiv1.appendChild(document.createTextNode(xmlHttp.responseText));
			}
			else if (xmlHttp.status == 404)
			{
         		alert("Request URL does not exist");
			}
      		else
         	{
			 	alert("Error: status code is " + xmlHttp.status); 
			}
		}
	}
	xmlHttp.send();
	return response;
	
}

function getChart(myChart)
{
	
	getXML(myChart);
	
	
}
	

function succeeded()
{
	

}


	

