function ajax(url, async, method, postdata, run, handleResponseText, handleError)
{
 	this.url = url||false;
 	this.async = true;

	async = async||false;
 	if(async == false)
 		this.async = false;

 	this.method = "GET";
 	method = method||false;
 	if(method)
 	{
 		if(method.toUpperCase() == "HEAD" || method.toUpperCase() == "POST" )
 			this.method = method;
 	}

 	this.postdata = postdata||false;
	
 	var response = null;
	this.getResponse = function () { return response; }

	handleResponseText = handleResponseText||false;
	handleError = handleError||false;
 	var callback = function (text){ response = text;}  // this is run inside of the callback to handle successful requests...
 	if(handleResponseText)
 		callback = handleResponseText;

 	this.setSuccessHandler = function(func) { callback = func; };
 	errorHandler = false; // this is run inside of the callback to handle unsuccessful requests...
 	//errorHandler = function(status){ alert('returned status:'+status); };
 	if(handleError)
 		errorHandler = handleError;

	var create_xml_object = function()
	{
		var newobj=false;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		// JScript gives us Conditional compilation, we can cope with old IE versions and security blocked creation of the objects.
	 	try
		{
	  		newobj = new ActiveXObject("Msxml2.XMLHTTP");
	 	}
		catch(e)
		{
	  		try
			{
	   			newobj = new ActiveXObject("Microsoft.XMLHTTP");
	  		}
			catch(E)
			{
	   			newobj = false;
	  		}
	 	}
		@end @*/
		if (!newobj && typeof XMLHttpRequest!='undefined')
		{
	  		newobj = new XMLHttpRequest();
		}

		return newobj;
	}

	var xmlhttp = create_xml_object();

	var synccallback = function ()
	{
		if (xmlhttp.status == 200)
		{
		 	if(callback)
         		callback(xmlhttp.responseText);
		}
		else
		{
			if(errorHandler)
				errorHandler(xmlhttp.status);
		}

		xmlhttp.abort();
	}

	var asynccallback = function ()
	{
		if(xmlhttp.readyState == 4)
		{
		 	if(xmlhttp.status == 200)
		 	{
				if(callback)
        			callback(xmlhttp.responseText);
         	}
         	else
			{
				if(errorHandler)
					errorHandler(xmlhttp.status);
			}

			xmlhttp.abort();
		}
	}

	this.reqcallback = synccallback;

	if(this.async)
		this.reqcallback = asynccallback;

	this.query = function ()
	{
		xmlhttp.abort();

		if(this.async)
		{
			xmlhttp.onreadystatechange = this.reqcallback;
		}

		xmlhttp.open(this.method, this.url, this.async);

		if(this.method.toUpperCase() == 'POST')
		{
			xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
//			alert('before'+this.postdata);
			xmlhttp.send(this.postdata);
//			alert('after'+this.postdata);
		}
		else
		{
			xmlhttp.send(null);
		}

		return false;
	}

	run = run||false;
	if(run)
	{
		this.query();
	}

	//this.toString = function (){ alert("URL:     "+this.url+"\nASYNC:   "+this.async+"\nMETHOD:  "+this.method+"\nREQCALLBACK: "+this.reqcallback+"\nPOSTDATA:"+this.postdata); }
}
