// *********************************************************************
// * cchAjax.js
// *
// * Copyright 2007 CCH, a Wolters Kluwer business
// *********************************************************************
function CchAjax_startRequest( )
{
	// If we're already in the middle of a request, let's stop
	// the request before we start a new one.
	if (this.request != null)
	{
		this.request.abort();
		this.request = null;
	}
	// Create the object that we'll use to make the request
	if (window.XMLHttpRequest)
	{
		this.request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		this.request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		// AJAX isn't supported by this browser.
		return;
	}
	this.request.onreadystatechange = new Function("window." + this.wid + ".stateChange();");
	this.request.open("GET", this.url, true);
	this.request.send(null);
}
function CchAjax_stateChange( )
{
	if (this.request.readyState == 4)
	{
		if (!this.gotResponse)
		{
			this.gotResponse = true;
			if (this.request.status == 200)
			{
				// Yay!  We've got something.
				this.processResult(this.request.responseText, true);
			}
			else
			{
				this.processResult(this.request.statusText, false);
			}
		}
	}
}
function CchAjax_processResult(res, success)
{
	alert("You have not defined a processResult for your instance of CchAjax!\nURL=\"" + this.url + "\"");
}
function CchAjax_toString( )
{
	return "[Object CchAjax (" + this.url + ")]";
}
function CchAjax(url)
{
	this.url = url;
	this.wid = "CchAjax" + (Math.floor(Math.random() * 8675309) % 1000);
	window[this.wid] = this;
	this.gotResponse = false;
	this.request = null;
}
CchAjax.prototype.processResult = CchAjax_processResult;
CchAjax.prototype.startRequest = CchAjax_startRequest;
CchAjax.prototype.stateChange = CchAjax_stateChange;
CchAjax.prototype.toString = CchAjax_toString;