/********************* Ajax Class *********************************************/
// Provide the XMLHttpRequest class for IE 5.x-6.x:
if( typeof XMLHttpRequest == "undefined" ) XMLHttpRequest = function()
{
	try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
	try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
	try { return new ActiveXObject("Msxml2.XMLHTTP") } catch(e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
	throw new Error( "This browser does not support XMLHttpRequest." )
};

function Ajax()
{
	var STATE = {UNINITIALIZED:0, LOADING:1, LOADED:2, INTERACTIVE:3, COMPLETE:4};
	var STATUS = {OK:200};

	this.postRequest = function(url, params, opt)
	{
		var xhr = new XMLHttpRequest();

		xhr.onreadystatechange = function()
		{
			switch(xhr.readyState)
			{
				case STATE.UNINITIALIZED:
					if(opt.onFailure)
						opt.onFailure(xhr, opt);
					delete(xhr);
					break;
				case STATE.LOADING:
				case STATE.LOADED:
				case STATE.INTERACTIVE:
					if(opt.onLoading) opt.onLoading(xhr, opt);
					break;
				case STATE.COMPLETE:
					if(xhr.status == STATUS.OK)
						if(opt.onSuccess) opt.onSuccess(xhr, opt);
					else
						if(opt.onFailure) opt.onFailure(xhr, opt);
					delete(xhr);
					break;
			}
		};
		xhr.open("POST", url, true);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr.setRequestHeader("Content-length", params.length);
		xhr.setRequestHeader("Connection", "close");
		xhr.send(params);
	}
}
