// Generic AJAX Functions
// Eg http://www.ecats.co.uk/pcpro/ajax/innerHTML.html

var xmlHttp;
var divTarget;
var htmlStart = "";
var htmlEnd = "";

// Create the HttpRequest object. Browser-specific
function createXMLHttpRequest() 
{
    if (window.ActiveXObject) 
    {
		// Internet Explorer
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) 
    {
		// Mozilla, Safari, Opera etc
        xmlHttp = new XMLHttpRequest();
    }
}

// Start the request from the server. Store the target div id also
function startRequest(source, target, start, end) 
{
    createXMLHttpRequest();
	divTarget = target;
	htmlStart = start;
	htmlEnd = end;
    xmlHttp.onreadystatechange = handleStateChange;
    xmlHttp.open("GET", source, true);
    xmlHttp.send(null);
}

// State change event handler. If request result returned, set the
// return value as the innerHTML in the target div
function handleStateChange() 
{
    if(xmlHttp.readyState == 4) 
    {
        if((xmlHttp.status == 200) && (divTarget != null))
        {
            document.getElementById(divTarget).innerHTML = htmlStart + xmlHttp.responseText + htmlEnd;
        }
    }
}