/**************************************************/
/* WISEXS AJAX HANDLER                            */
/*                                                */
/* VERSION	: 1.01                                */
/* AUTHOR	: A.H. Miedema                        */
/* DATE		: 2008/01/09                          */
/**************************************************/

function Ajax()
{
	this.requestHandler;
	this.errorHandler;
	this.server;
	this.result;
	
	var self = this;
	
	// PUBLIC
	//////////////////////////////////////////////////
	
	// Set the result handlers
	this.setRequestHandler = function(h) { this.requestHandler = h; }
	this.setErrorHandler   = function(h) { this.errorHandler = h; }
	
	this.init              = function(rh, eh)
	{
		try
		{
			this.server = new XMLHttpRequest();
		} catch(e)
		{
			try
			{
				this.server = new ActiveXObject('Msxml2.XMLHTTP');
			} catch(e)
			{
				try
				{
					this.server = new ActiveXObject('MMicrosoft.XMLHTTP');
				} catch(e)
				{
					// Browser does not support Ajax, return false
					alert('Browser does not support Ajax, return false');
					return false;
				}
			}
		}
		
		this.setRequestHandler(rh);
		this.setErrorHandler(eh);
		
		this.server.onreadystatechange = this.getReadyState;
	}
	
	// Make the call to the server
	this.call              = function(url)
	{
		if(!this.server)
		{
			alert('The Ajax application has not been initialized');
			return false;
		}
		
		this.server.open('GET', url);
		this.server.send(null);
	}
	
	// PRIVATE
	//////////////////////////////////////////////////
	this.getReadyState     = function()
	{
		if(self.server.readyState == 4)
		{
			self.result = self.server.responseXML;
			self.requestHandler(self.result);
			
			return;
		}
	}
}