/*
Version 1.0  Original version
Version 1.1 OSR: 05 June 2007 Case : 07-5478 - Servery Error Fixed
*/
/*
AjaxDelegate(url, callback)
	url = the url of the page that will do the server-side processing
	callback = the name of the function to call once the call has completed

	Any number of additional arguments can also be specified. The extra
	arguments will be available to the callback function when it is called.

	The callback function will receive the following arguments:
		callback(url, response, [argument[0]], etc.)
	where:
		url = the url of the page that did the server-side processing
		response = the actual HTTP responseText returned from the call
		[argument[0]], etc. = the remaining arguments that were originally passed to the AjaxDelegate constructor
*/
function AjaxDelegate(url, callback) {
	// basic properties
	this.url = url;
	this.callback = callback;
	this.callbackArguments = arguments;

	// methods
	this.Fetch = ajaxFetch;

	// XmlHttpRequest object
	this.request = null;

	/* Asynchronous means that the processing will continue on without waiting for the server side retrieval to complete whereas
	a synchronous call would stop all other processing and wait for the response from the server. */
	this.Asynchronous = true;
}

/*
ajaxFetch()
	Asynchronously calls the url specified in the AjaxDelegate constructor.
	When the call completes, the callback specified in the AjaxDelegate constructor
	is called, passing the responseText data in.
*/
function ajaxFetch() {
	// this gets the variables into a local scope
    	var request = this.request;
    	var callback = this.callback;
    	var callbackArguments = this.callbackArguments;
    	var bAsync = this.Asynchronous;

    	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest) {
    		try {
			request = new XMLHttpRequest();
        	} catch(e) {
			request = null;
        	}
    	// branch for IE/Windows ActiveX version
    	} else if(window.ActiveXObject) {
       		try {
        		request = new ActiveXObject("Msxml2.XMLHTTP");
      		} catch(e) {
        		try {
          			request = new ActiveXObject("Microsoft.XMLHTTP");
        		} catch(e) {
          			request = null;
        		}
		}
    	}

	// if we were able to create the XmlHTTPRequest object, we can make the request
	if(request) {
		request.onreadystatechange = function () {
			if(request.readyState == 4) {
				if(request.status == 200) {
					// we replace the second argument (callback function) with the response data)
					// kind of cheesy, but it is nice and easy and works well
						// Starting of Version 1.1 - Checking if callback is an object
						if(callback)
						{
							callbackArguments[1] = request.responseText;
							callback.apply(this, callbackArguments);
						}
						//Ending of Version 1.1
				} else {
					alert("There was a problem retrieving the data:\n" + request.statusText);
				}

				// clean up
				request = null;
			}
		}
		request.open("GET", this.url, bAsync);
		request.send("");
		if(!bAsync) {
			// Starting of Version 1.1 - Checking if request is an object
			if(request)
				return request.responseText;
			// Ending  of Version 1.1
		}
	}
}



function AjaxXMLDelegate(url, callback) {
	// basic properties
	this.url = url;
	this.callback = callback;
	this.callbackArguments = arguments;

	// methods
	this.Fetch = ajaxXMLFetch;

	// XmlHttpRequest object
	this.request = null;
}




/*
ajaxXMLFetch()
	Asynchronously calls the url specified in the AjaxDelegate constructor.
	When the call completes, the callback specified in the AjaxDelegate constructor
	is called, passing the responseText data in.
*/
function ajaxXMLFetch()
{
	// this gets the variables into a local scope
    var request = this.request;
    var callback = this.callback;
    var callbackArguments = this.callbackArguments;

    	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest) {
    		try {
			request = new XMLHttpRequest();
        	} catch(e) {
			request = null;
        	}
    	// branch for IE/Windows ActiveX version
    	} else if(window.ActiveXObject) {
       		try {
        		request = new ActiveXObject("Msxml2.XMLHTTP");
      		} catch(e) {
        		try {
          			request = new ActiveXObject("Microsoft.XMLHTTP");
        		} catch(e) {
          			request = null;
        		}
		}
    	}

	// if we were able to create the XmlHTTPRequest object, we can make the request
	if(request) {
		request.onreadystatechange = function () {
			if(request.readyState == 4) {
				if(request.status == 200) {
					// we replace the second argument (callback function) with the response data)
					// kind of cheesy, but it is nice and easy and works well
					callbackArguments[1] = request.responseXML;
					if (callback !== null)
						callback.apply(this, callbackArguments);
				} else {
					alert("There was a problem retrieving the data:\n" + request.statusText);
				}

				// clean up
				request = null;
			}
		}
		request.open("GET", this.url, true);
		request.send("");
	}
}

