function AJAX()
{
	this.requestObject = null;
	this.url = null;
	this.userCallbackFunction = null;
		
	this.init = function()
	{
		if(this.requestObject)
		{
			this.requestObject.abort();
			this.requestObject = null;
		}
		
		if(window.XMLHttpRequest)
		{
			// Mozilla-based browsers
			this.requestObject = new XMLHttpRequest();
		}
		else if(window.ActiveXObject)
		{
			// IE
			ro = new ActiveXObject("Msxml2.XMLHTTP");
			if(!ro)
				ro = new ActiveXObject("Microsoft.XMLHTTP");
			
			if(ro)
				this.requestObject = ro;
		}
	}
	
	this.setURL = function(url)
	{
		this.url = url;
	}
	
	this.setCallback = function(func)
	{
		this.userCallbackFunction = func;
	}
	
	this.sendRaw = function(method, data)
	{
		if(!this.requestObject || !this.url)
			return;
		
		this.requestObject.onreadystatechange = this.userCallbackFunction;
		this.requestObject.open(method, this.url, true); // async call
		if(method.toLowerCase() == "post")
			this.requestObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		this.requestObject.send(data);
	}
	
	this.sendArray = function(method, arr)
	{
		this.sendObject(method, arr);
	}
	
	this.sendObject = function(method, obj)
	{
		var data = "";
		for(var key in obj)
			data += "&"+encodeURIComponent(key)+"="+encodeURIComponent(obj[key]);
		this.sendRaw(method, data);
	}
	
	this.sendValue = function(method, name, value)
	{
		var obj = new Object();
		obj[name] = value;
		this.sendObject(method, obj);
	}
	
	/* 
	To be called from within the userCallbackFunction to check for the receipt of the response
	Return values: 
		 0 - not ready
		 1 - ready and successful
		-1 - ready and failed
	*/
	this.responseIsReady = function()
	{
		if(!this.requestObject)
			return 0;
		
		if(this.requestObject.readyState == 4)  // Finished processing request
		{
			if(this.requestObject.status == 200 || this.requestObject.status == undefined)  // Success; 'undefined' for damn Safari bug
				return 1;
			else  // Failure
				return -1;
		}
		
		return 0;
	}
	
	this.getResponse = function()
	{
		if(this.responseIsReady() != 1)
			return null;
		return this.requestObject.responseText;
	}
	
	this.getResponseXML = function()
	{
		if(this.responseIsReady() != 1)
			return null;
		return this.requestObject.responseXML;
	}
	
	
	this.init();
}