Xhr = function(url, onload, wait, onerror)
{
	this.url = url; 
	this.req = null; 
	this.onload = onload; 
	this.wait = (wait)?wait:this.defaultWait; 
	this.onerror = (onerror)?onerror:this.defaultError; 
}

Xhr.prototype.READY_STATE_UNINITIALIZED = 0; 
Xhr.prototype.READY_STATE_LOADING = 1; 
Xhr.prototype.READY_STATE_LOADED = 2; 
Xhr.prototype.READY_STATE_INTERACTIVE = 3; 
Xhr.prototype.READY_STATE_COMPLETE = 4;

Xhr.prototype.sendRequest = function(params, method)
{
	if (window.XMLHttpRequest)
	{
		this.req = new XMLHttpRequest(); 
	}
	else if (window.ActiveXObject)
	{
		this.req = new ActiveXObject("Microsoft.XMLHTTP"); 
	}
	if (this.req)
	{
		try
		{
			var loader = this; 
			this.req.onreadystatechange = function() 
			{ 
				loader.onReadyState.call(loader); 
			}
			this.req.open(method, this.url, true); 
			this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
			this.req.send(params);
		}
		catch (e)
		{
			this.onerror.call(this);
		}
	}
}
Xhr.prototype.onReadyState = function()
{
	var req = this.req; 
	var state = req.readyState; 
	if (state == this.READY_STATE_COMPLETE)
	{	
		this.onload.call(this); 
	}
	else if (state == this.READY_STATE_INTERACTIVE)
	{
		this.wait.call(this); 
	}
}

Xhr.defaultWait = function()
{
	
}

Xhr.defaultError = function()
{
	alert("error"); 
}
