var Ajax = {
	getXMLHttpRequest : function() {
		var obj = null;
		if (window.XMLHttpRequest)
			obj = new XMLHttpRequest();
		else
		{
			try	{
				obj = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				try {
					obj = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					throw new Error("Your browser does not support AJAX");
				}
			}
		}
		return obj;
	},

	/**
	*	@param	string	url destino
	*	@param	object	opciones y eventos.
	*
	*	Propiedades del objeto:
	*		method 		: string	post|get,
	*		params 		: string	query string,
	*		async		: boolean,
	*		onLoading	: function	funcion a ejecutar mientras el estado es 'loading',
	*		onComplete	: function	funcion a ejecutar cuando se completo el request,
	*		onError		: function	funcion a ejecutar cuando hubo un fallo,
	*		onProgress	: function	funcion a ejecutar mientras se reciben datos (solo XMLHttpRequest)
	*/
	request : function(url, options) {
		var xmlhttp = this.getXMLHttpRequest();
		if (url == null) url = window.location.href;
		var method = options.method ? options.method.toUpperCase() : 'GET';
		var params = options.params ? options.params : '';
		var async = typeof options.async != 'undefined' ? options.async : true;
		
		xmlhttp.onreadystatechange = function(e) {
			if (!e) var e = window.event;
			if (xmlhttp.readyState > 0 && xmlhttp.readyState < 4 && typeof options.onLoading == 'function')
				options.onLoading(xmlhttp, e);
			if (xmlhttp.readyState == 4)
			{
				if (xmlhttp.status == 200 && typeof options.onComplete == 'function')
					options.onComplete(xmlhttp, e);
				else if (xmlhttp.status != 200 && typeof options.onError == 'function')
					options.onError(xmlhttp, e);
			}
		};
		
		if (typeof xmlhttp.onprogress != 'undefined' && 
			typeof options.onProgress == 'function')
				xmlhttp.onprogress = options.onProgress;
		
		if (method == 'POST')
		{
			xmlhttp.open("POST", url, async);
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xmlhttp.send(params);
		}
		else
		{
			url = (url.split('?')[1]) ? url + '&' + params : url.replace(/\?/, '') + '?' + params;
			xmlhttp.open("GET", url.replace(/&$/, ''), async);
			xmlhttp.send(null);
		}
		
		return xmlhttp;
	}
};