function Requester()
{
	this.action = null;
	this.XML = null;
	this.commInterface = null;

	// Initialise XMLHttpRequest object
	this.resetXMLHR();
	return true;
}




/* Check if the XMLHttpRequest object is available */
Requester.prototype.isAvailable = function()
{
	if (this.commInterface == null)
	{
		return false;
	}
	
	return true;
}




/* Execute the action which has been associated with the completion of this object */
Requester.prototype.executeAction = function()
{
	// If XMLHR object has finished retrieving the data
	if (this.commInterface.readyState == 4)
	{
//alert("state="+this.commInterface.status+this.commInterface.responseXML+this.commInterface.responseText);
		// If the data was retrieved successfully
		try
		{
		
			if (this.commInterface.status == 200)
			{
				this.responseText = this.commInterface.responseXML;
				this.action();
			}
			// IE returns status = 0 on some occasions, so ignore
			else if (this.commInterface.status != 0)
			{
				alert("There was an error while retrieving the URL: " + this.commInterface.statusText);
			}
		}
		catch (error)
		{
		}
	}

	return true;
}




/* Return responseText */
Requester.prototype.getText = function()
{
	return this.commInterface.responseText;
}




/* Return responseXML */
Requester.prototype.getXML = function()
{
	return this.commInterface.responseXML;
}




/* Initialise XMLHR object and load URL */
Requester.prototype.loadURL1 = function(URL, CGI)
{
	this.resetXMLHR();
	this.commInterface.open("GET", URL + "?" + CGI);
	this.commInterface.send(null);

	return true;
}
/* Initialise XMLHR object and load URL */
Requester.prototype.loadURL = function(URL)
{
	this.resetXMLHR();
	this.commInterface.open("GET", URL, true);
	this.commInterface.send(null);
	return true;
}

Requester.prototype.loadURLpost = function(URL,data)
{
	this.resetXMLHR();
	this.commInterface.open("POST", URL, true);
//	this.commInterface.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    this.commInterface.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
//	alert(data);
	this.commInterface.send(data);

	return true;
}
Requester.prototype.loadURLpostn = function(URL,data)
{
	this.resetXMLHR();
	this.commInterface.open("POST", URL, true);
	this.commInterface.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//	alert(data);
	this.commInterface.send(data);

	return true;
}

Requester.prototype.reset = function()
{
	this.resetXMLHR();
	return true;
}
Requester.prototype.open = function(URL)
{
	this.commInterface.open("GET", URL, true);
	return true;
}
Requester.prototype.send = function(data)
{
	this.commInterface.send(data);
	return true;
}



/* Turn off existing connections and create a new XMLHR object */
Requester.prototype.resetXMLHR = function()
{
	var self = this;

	if (this.commInterface != null && this.commInterface.readyState != 0 && this.commInterface.readyState != 4)
	{
		this.commInterface.abort();
	}
	
	try
	{
		this.commInterface = new XMLHttpRequest();
		this.commInterface.onreadystatechange = self.executeAction;

	}
	catch (error)
	{
		try
		{
			this.commInterface = new ActiveXObject("MSXML2.XMLHTTP.3.0");
		}
		catch (error)
		{
			return false;
		}
	}

	this.commInterface.onreadystatechange = function()
		{
			self.executeAction();

			return true;
		};

	return true;
}




/* Assign the function which will be executed once the XMLHR object finishes retrieving data */
Requester.prototype.setAction = function(actionFunction)
{
	this.action = actionFunction;

	return true;
}
