<!--
// general ajax post and get functions - returning httprequest data
// data (if loaded) passed back to this function:
//function jg_ajax_passback(http_request,callID){
//
//}

//=====================================================================
//GET type
//=====================================================================

function jg_ajax_get(url,callID){ //pass in the url of the script to return data and also what type, "text" or "XML"

	var http_request = false;

	if (window.XMLHttpRequest)
	{ // create xmlhttpreq if not IE
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType)
		{
			http_request.overrideMimeType('text/xml'); // for firefox to overide sent header mime type - may cause errors if file called is not xml - i.e plain text - still seems to work though
		}
	}
	else if (window.ActiveXObject)
	{ // else then create xmlhttpreq for IE
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP"); // try first type on fail try second type
		}
		catch (e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {} // if neither do nothing
		}
	}

	if (!http_request) // check to see if instance created
	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	// or proceed with call
	http_request.onreadystatechange = function() {jg_return_data(http_request,callID);};
	http_request.open('GET', url, true); //get the url - true means continue with lines below
	http_request.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" ); // belt and braces to try and ensure always refreshed
	http_request.send(null); // perform the get - send nothing
}

//=====================================================================
//POST type
//=====================================================================

function jg_ajax_post(url,parameters,callID) { //creates a http req instance and posts form data to script
	var http_request = false;

	if (window.XMLHttpRequest)
	{ // create xmlhttpreq if not IE
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType)
		{
			http_request.overrideMimeType('text/xml'); // for firefox to overide sent header mime type - may cause errors if file called is not xml - i.e plain text - still seems to work though
		}
	}
	else if (window.ActiveXObject)
	{ // else then create xmlhttpreq for IE
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP"); // try first type on fail try second type
		}
		catch (e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {} // if neither do nothing
		}
	}

	if (!http_request) // check to see if instance created
	{
		alert('It Appears Your Browser Cannot Support HttpRequest As Required');
		return false;
	}
	else
	{
		// or proceed with call
		http_request.onreadystatechange = function() { jg_return_data(http_request,callID);};
		http_request.open('POST', url , true); //post data
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		//http_request.setRequestHeader("Content-length", parameters.length);
		//http_request.setRequestHeader("Connection", "close");
		http_request.send(parameters);
	}
}

//=====================================================================
//return data function
//=====================================================================

function jg_return_data(http_request,callID) { // function called on load
	try // put it into a test case - if no access tor server etc then does not crash
	{
		if (http_request.readyState == 4) // if finished loading
		{
			if (http_request.status == 200) // if successful load
			{
				//alert(http_request.responseText); //for dump of data passed
				//passback loaded data
				jg_ajax_passback(http_request,callID);
			}
			else
			{
				alert('There was a problem with the request.'); // data not loaded (404 etc)
			}
		}
	}
	catch( e )
	{
		alert('Caught Exception: ' + e.description); // if test case fails
	}

}
-->