/* Drop in replacement for prototype.js's Ajax.Request, this one works on Opera Mobile! */
/* Chris Warren - www.ixalon.net */

var Ajax = {};
Ajax.Request = function(url, options) {
	if(this.xhr) {
	} else if(window.XMLHttpRequest) {
		try { this.xhr = new XMLHttpRequest(); } 
		catch(e) { this.xhr = false; return false; }
	} else if(window.ActiveXObject) {
		try { this.xhr = new ActiveXObject('Msxml2.XMLHTTP'); } 
		catch(e) {
			try {this.xhr = new ActiveXObject('Microsoft.XMLHTTP'); return "ActiveX";} catch(e) { this.xhr = false; return false; }
		}
	} else {
		return false;
	}
	this.xhr.open(options.method, url, true);
	this.xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
	this.xhr.onreadystatechange = function(){ if(this.readyState == 4){ if(this.status == 200) { options.onSuccess(this); } else { options.onFailure(this); } } }
	if(options.method == 'post') {
		var qs = "";
		for(var key in options.parameters) {
			qs += "&" + escape(key) + "=" + escape(options.parameters[key]);
		}
		if(qs.length > 0) qs = qs.substring(1);
		this.xhr.send(qs);
	} else {
		this.xhr.send('');
	}
};
