var ajax = new Object();

ajax.UNINITIALIZED = 0;
ajax.LOADING	   = 1;
ajax.LOADED	   = 2;
ajax.INTERACTIVE   = 3;
ajax.COMPLETE	   = 4;

ajax.initReqObj = function()
{
	var req = null;

	if( window.XMLHttpRequest )
	{
		req = new XMLHttpRequest();
	}
	else if( window.ActiveXObject )
	{
		if( !(req = new ActiveXObject( "Msxml2.XMLHTTP" )) )
		{
			req = new ActiveXObject( "Microsoft.XMLHTTP" );
		}
	}

	return req;
}

ajax.Request = function( url, args )
{
        //alert("Entered Request function."); 
	this.url      = (url) ? url : "ajax.php";
	this.callback = (args.callback) ? args.callback : alert( "*** No callback function provided ***" );
	this.method   = (args.method) ? args.method : "POST";
	this.params   = null;
	this.req      = ajax.initReqObj();
}

ajax.Request.prototype =
{
	Send:function( params )
	{
                //alert("Entered Send function."); 
		this.params = params;

		if( !this.req )
		{
			this.req = ajax.initReqObj();
		}
		else if( this.req.readyState != 0 )
		{
			this.req.abort();
			this.req = ajax.initReqObj();
		}

		if( this.req && this.callback )
		{
			if( this.method == "GET" )
			{
				with( this.req )
				{
					onreadystatechange = this.callback;
					open( this.method, this.url + "?" + this.params, true );
					send( null );
				}
			}
			else
			{
				with( this.req )
				{
					onreadystatechange = this.callback;
					open( this.method, this.url, true );
					setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					send( this.params );
				}
			}
		}
		else
		{
			console.write( "*** Error generating asynchronous request ***" );
		}
	},
	Abort:function()
	{
		if( this.req )
		{
			this.req.abort();
			this.req = ajax.initReqObj();
		}
	}
}
