/*
	$Id: ajax.js 4294 2007-12-18 04:02:57Z mjhorne $

	This file is part of ayudaCMS
	Copyright 2007: ayuda IT
	http://www.ayuda.com.au

	For licencing details, please see LICENCE.txt in the ayudaCMS directory.
*/

	var request;
		
	function retrieveURL(url, synchronous, callback, args, htmlResponse) {

		request = new Request();

		request.synchronous = synchronous;
			
		if(!args) {
			args = new Array();
		}

		request.callback = callback;
		request.callbackArgs = args;

		request.htmlResponse = htmlResponse;

		if(!request.synchronous) {
			request.xmlHTTP.onreadystatechange = processStateChange;
		}

		try {
			if(request.xmlHTTP.synchronous) {
				request.xmlHTTP.open("GET", url, false);
			} else {
				request.xmlHTTP.open("GET", url, true); 
			}
		} catch (e) {
		}

		request.xmlHTTP.send(null);
	}

	function processStateChange()  {
	
		if (request.xmlHTTP.readyState == 4)  { // Complete
			if (request.xmlHTTP.status == 200) { // OK response
				if(!request.htmlResponse)
				{
					request.callbackArgs['response'] = request.xmlHTTP.responseXML;
				}
				else
				{
					request.callbackArgs['response'] = request.xmlHTTP.responseText;
				}

				if(request.callback)
				{
					request.callback(request.callbackArgs);
				}
			}
		}
	}

	function Request() {
		if (window.XMLHttpRequest) { 
			this.xmlHTTP = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE 6
			this.xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
