<!--
/*
AjaxDelegate(url, xml, callback)
	modified by pjo to send & receive XML documents
	url = the url of the page that will do the server-side processing
	xml = the xml string to send
	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, xml, response, [argument[0]], etc.)
	where:
		url = the url of the page that did the server-side processing
		xml = the xml string originally sent
		response = the actual HTTP responseXml returned from the call
		[argument[0]], etc. = the remaining arguments that were originally passed to the AjaxDelegate constructor
*/
function AjaxDelegate(url, xml, callback)
{
	// basic properties
	this.url = url;
	this.xml = xml;
	this.callback = callback;
	this.callbackArguments = arguments;

	// methods
	this.Fetch = ajaxFetch;

	// XmlHttpRequest object
	this.request = null;
}

/*
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;

    // 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 callback function argument with the response data
					// assume text/xml, else use responseText
					
					//alert(request.responseText);
					
					if (callback != null)
                                        {
        					callbackArguments[2] = request.responseXML;
					
	        				callback.apply(this, callbackArguments);
                                        }
				} 
				else 
				{
					alert("There was a problem retrieving the XML data:\n" + request.statusText);
				}

				// clean up
				request = null;
			}
		}
									
		request.open("POST", this.url, true);		
		request.setRequestHeader("Content-Type", "text/xml");
		request.send("<?xml version='1.0' encoding='UTF-8'?>" + this.xml);
	}
}

//-->

