// version 2.0 

/* ---------------------------------

// by Mark Hicken (nekcih@yahoo.com)

// depends on jquery 1.1.2 or later

// EXAMPLE USAGE

// set up success and failure functions
docOnLoad = function(xmlDoc) { alert("XML data OK: "+xmlDoc.responseText); }
docOnFailure = function(xmlDoc) { alert("Unable to communicate with server.\r\nPlease try again in a moment.\r\n\r\nStatus: "+xmlDoc.statusText); }

// execute asynchronous load
window.onload = function() { loadXMLDoc('myDoc.xml',  docOnLoad, docOnFailure); }
// or execute synchronous load (waits for response)
window.onload = function() { loadXMLDoc('myDoc.xml',  docOnLoad, docOnFailure, false); }

----------------------------------- */
var jqLocalAjax = {
	get: function(sUrl, fOnSuccess, fOnFailure, bAsynchronous) { // fOnSuccess and fOnFailure can be a string to eval or a function to execute
		bAsynchronous = (bAsynchronous); // booleanize it

		$.ajax({
			url: sUrl,
			type: 'GET',
			dataType: "text/xml",
			async: bAsynchronous,
			timeout: 2000,
			error: function(oXmlHttpRequest, sError) {},
			success: function(oXmlHttpRequest) {},
			complete: function(oXmlHttpRequest) {
				if(oXmlHttpRequest.statusText!='Object Not Found') {
					if(jqLocalAjax.parseXml(oXmlHttpRequest.responseText).documentElement!=null) {
						jqLocalAjax.lastLoadedText = oXmlHttpRequest.responseText;
						jqLocalAjax.lastLoadedObject = jqLocalAjax.parseXml(oXmlHttpRequest.responseText);
						fOnSuccess(jqLocalAjax.lastLoadedObject);
					}
					else { fOnFailure(oXmlHttpRequest.statusText); }
				}
				else { fOnFailure(oXmlHttpRequest.statusText); }
			}
		});
	},
	parseXml: function(sXml) { // returns a traversable XML DOM
		var doc;
		if(window.ActiveXObject) { // code for IE
			doc = new ActiveXObject("Microsoft.XMLDOM");
			//doc.setContentType('text/xml');
			doc.async = "false";
			doc.loadXML(sXml);
		}
		else { // code for Mozilla, Firefox, Opera, etc.
			var parser = new DOMParser();
			doc = parser.parseFromString(sXml, "text/xml");
		}
		
		// documentElement always represents the root node
		return doc;	
	},
	lastLoadedText: new String(),
	lastLoadedObject: new Object()
}

