var aOnLoadHandlers = null;
window.onload = attachValidateHandlers; //callOnLoadFunctions;

//clever ajax class
//http://weblogs.macromedia.com/mesh/archives/2006/01/encapsulating_a.html
function Ajax(dataUrl, responseHandler)
{
    this._dataUrl = dataUrl;
    this._responseHandler = responseHandler;
}
Ajax.prototype._dataUrl = null;
Ajax.prototype._http = null;
Ajax.prototype._responseHandler = null;

/*** Ajax Class members ***/

// Calls correct ajax handler function http.readystate changes.
Ajax.prototype.handleAjaxResponse = function()
{
	// readyState 4 = complete. Look at loaded answer.
	if (this._http.readyState == 4)
	{
		if(this._http.status == "200")
		{
			this._responseHandler(this._http.responseText);
		}
	}
}

// Sends an ajax http query to the provided url
Ajax.prototype.sendAjaxQuery = function(ajaxQueryString)
{
    if(this._http==null)
    {
        this._http = this.getHTTPObject();
    }

    //set the var so we can scope the callback
	var _this = this;
	
	//sends the rules and value to the asp page to be validated
	this._http.open("GET", this._dataUrl +"?"+ ajaxQueryString, true);
	this._http.onreadystatechange = function(){_this.handleAjaxResponse()};
	this._http.send(null);
}

// Gets the http object, specific to client browser.
Ajax.prototype.getHTTPObject = function()
{
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
	try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
	xmlhttp = false;
	}
	}
	@else
	xmlhttp = false;
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try 
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch(e)
		{
			xmlhttp = false;
		}
	}
	return xmlhttp;
}

/*** OnLoad Functions ***/

// Adds an onLoad handler function.
function addOnLoadHandler(h)
{
    if(aOnLoadHandlers != null)
    {
    //alert("add to array\n\n" + h);
        aOnLoadHandlers.push(h);
    }
    else
    {
        //alert("new array\n\n" + h);
        aOnLoadHandlers = new Array(h);
    }
}

// Call all onLoad functions
function callOnLoadFunctions()
{

    for(onLoadFunction in aOnLoadHandlers)
    {
        //alert("function\n\n" + onLoadFunction);
        onLoadFunction;
    }
}