/*

Minimalist Javascript AJAX class

*/

function AJAX() {

	/* --- Initialization: --- */
	
	try {
		this.xml = new XMLHttpRequest();
	} catch(e) {
		try {
			this.xml = new ActiveXObject("Msxml2.XMLHTTP");;
		} catch(e) {
			try {
				this.xml = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				window.alert('Your browser does not support AJAX. ouch!');
				return;
			}
		}
	}
	
	//this.xml._ajax = this;
	
	this.onStart = function() {};
	this.onLoad = function() {};
	this.onError = function() {};
	
	this.load = function(url, rootnode) {
		this._rootnode = rootnode;
		this.xml.open("GET",url,true);
		this.xml.send(null);
	}
	
	var _ajax = this;
	
	this.xml.onreadystatechange = function() {
		switch (_ajax.xml.readyState) {
			case 4:
				if (_ajax.xml.responseXML) {
					var nodes = _ajax.xml.responseXML.getElementsByTagName(_ajax._rootnode);
					for (i=0; i<nodes.length; i++) 
						_ajax.onLoad(nodes[i].firstChild.nodeValue);
				} else {
					_ajax.onError();
				}
			break;
			case 2:
				_ajax.onStart();
			break;
		}
	};
	
}
