/**********************************************
*	Scott Ladyman 2006
*
***********************************************/

/* needs dom.js library */
var ajax = {
	
	delay 			: 0,
	loadingTarget	: false,	/* simple ajax class self loading - passed obj */
	existingContent	: "",		/* used to store the replaced content of the target */		
	
	init : function() {
		
		var xmlhttp = false; //Clear our fetching variable
			try {
				xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object.
			} catch (e) {
				try {
					xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
				} catch (E) {
					xmlhttp = false;
				}
			}
			if( !xmlhttp && typeof XMLHttpRequest != 'undefined') {
				xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
			}
		
		
		return xmlhttp;	
	},
		
	request : function( url, callback, customLoading ) {
		
		// create the handle for the XMLHttpRequest
		ajaxRequest = this.init();
		
		// open the request, based on the form method type
		ajaxRequest.open("GET" , url, true); 
		
		/* when the server request is completed */
		ajaxRequest.onreadystatechange = function() {
			
			/* four main states/state codes, Loading-1, Loaded-2, Interactive-3, and Complete-4. */
			if( ajaxRequest.readyState == 1 ){
				// loading
			}
			if ( ajaxRequest.readyState == 4 ) { 
				 /* Upon successful HTTP request 200 = OK  */
				if ( ajaxRequest.status == 200 ) {
					/* delay is only needed for testing */
					setTimeout(function(){
						callback(ajaxRequest); 
						}, ajax.delay);
				}  
				else {
					alert("Error contacting the server :: " + ajaxRequest.status);
				}
			}
		}
				
		// send the request
		ajaxRequest.send(null);
	},
	
	/* ********************************************** 
		easiest way to decode json for javascript
	********************************************** */
	decodeJson : function( string )
	{
		return eval( '(' + string+ ')' );
	}
	
};

	 