function ajax_object() {
 var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
 return request;
}

function ajax_load_js(url,post_callback) {
	var request = ajax_object();
	request.open("GET", url, true);
 
	request.onreadystatechange = function() {
		if (request.readyState == 4 && request.status == 200)
			if (request.responseText) {
				eval(request.responseText);
				post_callback();
			}
		};
	request.send(null);
	
}

function ajax_get(url, callbackFunction){
 
	var request = ajax_object();
	request.open("GET", url, true);
 
	request.onreadystatechange = function() {
		if (request.readyState == 4 && request.status == 200) if (request.responseText) callbackFunction(request.responseText);
		};
	request.send(null);
}



function ajax(url, vars, callbackFunction){
 
        var request = ajax_object();
 
        request.open("POST", url, true);
        request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
 
        request.onreadystatechange = function(){
                if (request.readyState == 4 && request.status == 200) {
                        if (request.responseText) callbackFunction(request.responseText);
                }
        };
        request.send(vars);
}


function ajax_get_file(url,handle_function) {
// Simplest possible interaction - just get the file on the server. (later a server script could be written to automatically request from other trusted domains...)
	var cx = getXmlHttpRequestObject();
	receiveRequest = cx;
	if (cx.readyState == 4 || cx.readyState == 0) {
		//Setup the connection as a GET call to SayHello.html.
		//True explicity sets the request to asyncronous (default).
		cx.open("GET", url, true);
		//Set the function that will be called when the XmlHttpRequest objects state changes.
		cx.onreadystatechange = handle_function; 
		//Make the actual request.
		cx.send(null);
	}	

}


/*
Documentation: Ajax information.

XmlHttpRequest Properties:
========

onreadystatechange

This property sets the method to be called on every state change.  This is usually your event handler for the asynchronous callback.

readyState

This property defines the state of the XmlHttpRequest.  Possible values include:

0      Uninitated
1      Loading
2      Loaded
3      Interactive
4      Complete

When sending the XmlHttpRequest, you will check to see if the readyState is 0 or 4, and in your asynchronous callback handler, you will check to see if the readyState is 4.

responseText

This returns the response from the server as a string.  If you are only returning one value this is the way to go because it is much easier that trying to walk the XML DOM.

responseXML

This returns the response from the server as an XML document.  This is the way to go if you need to return multiple values from your AJAX request.  It does require some knowledge of the XML DOM to use, but is quite powerful.

status

This returns the HTTP status code from the server such as 200 for OK or 404 for not found.

statusText

This returns a string representation of the HTTP status code such as OK for 200 and Not Found for 404


XmlHttpRequest Methods
==============

abort()

This cancels the current request as expected.

getAllResponseHeaders()

Returns all the response headers as a key / value pair.

getResponseHeader(header)

This returns the value of the specified header.

open(method, url)

This prepares the XmlHttpRequest object for a call to the server.  Method can either be POST, GET, or PUT.  Url can be relative or absolute, but it should be known that you can't make cross domain calls for security reasons.  If you need to make cross domain calls, you will have to do some work on the server side to make it happen correctly.  If you are passing parameters with via GET, you can append them to the URL here.

send(body)

This method actually sends the request to the server.  The body parameter can be used to pass any POST parameters that you would like.  You can format your POST parameters just like a GET querystring.

setRequestHeader(header, value)

The final method allows you to set the specified header with the given value.  You will most often use this function for setting the content type of the request.

*/

