/*	XRO.js
 * copyright (c) 2007 Eddie Roosenmaallen // rosebleed.net
 * $Id$
 */

XRO = function (params) {
//	member variables
	this.req = false;
	this.onLoadedXML	 = function(){return false};
	this.onLoadedText	 = function(){return false};
	this.onFailed		 = function(){return false};

//	one-time init
	if(window.XMLHttpRequest && !(window.ActiveXObject)) {
		try {
			this.req = new XMLHttpRequest();
		} catch(e) {
			this.req = false;
		}
	} else if(window.ActiveXObject) {
		try {
			this.req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				this.req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				this.req = false;
			}
		}
	}
	
	if (typeof(params['callback']) == 'function') {
		this.onLoaded = params['callback'];
	}
	if (typeof(params['loadedXML']) == 'function') {
		this.onLoadedXML = params['loadedXML'];
	}
	if (typeof(params['loadedText']) == 'function') {
		this.onLoadedText = params['loadedText'];
	}
	if (typeof(params['error']) == 'function') {
		this.onFailed = params['error'];
	}

	
	this.defaultProcessReqChange = function() {
		var req = this;
		if (req.readyState == 4) {
			if (req.status == 200) {
				if (req.responseXML)
					this.parent.onLoadedXML(req.responseXML);
				else
					this.parent.onLoadedText(req.responseText);
			}
			else {
				if (typeof(setErr) == 'function')
					setErr("XML Fetch failed:\n"+req.statusText);
				else
					alert("XML Fetch failed:\n"+req.statusText);
			}
		}
	}; // XRO.defaultProcessReqChange
	
	
	this.get = function(url) {
		if(this.req) {
			this.req.onreadystatechange = this.defaultProcessReqChange;
			this.req.parent = this;
			this.req.open("GET", url, true);
			this.req.send("");
		}
	};

};