function e(getid){ return document.getElementById(getid); }

var make = new Object();

make.Ajax = function(array){
	this.VerificaObjeto();
	this.url = array['url'];
	this.metodo = array['metodo'];
	this.vars = (array['metodo'] == "GET" && typeof array['vars'] == "undefined")? null : array['vars'];
	this.asincrono = (array['asincrono'])? array['asincrono'] : true;
	this.EnviaDatos();
	this.cargando =  (typeof array.cargando == "function")? array.cargando : null;
	this.cargaCompleta = array.cargaCompleta;
	this.muestraError = (typeof array.errorFuncion == "function")? array.errorFuncion : this.errorFunction;
	this.CargaDatos();
}

make.Ajax.prototype = {
	VerificaObjeto : function (){
		var majax = false;
		try {
			majax = new ActiveXObject("msxml2.XMLHTTP");
		} catch(e){
			try{
				majax=new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E){
				majax=false;
			}
		
		}
	
		if(!majax && typeof XMLHttpRequest != 'undefined'){
			majax=new XMLHttpRequest();
		}
		this.objeto=majax;
	},
	
	EnviaDatos : function(){	
		this.objeto.open(this.metodo,this.url,this.asincrono);
		if(this.metodo == "POST"){
			this.objeto.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		}
		this.objeto.send(this.vars);	
	},
	
	CargaDatos : function(){
		var este = this;
		este.objeto.onreadystatechange=function(){
			if(este.objeto.readyState == 4 && este.objeto.status == 200){
				este.respuesta = este.objeto.responseText;
				este.cargaCompleta();
			}
			else if (este.objeto.readyState == 4 && este.objeto.status == 404){
				este.muestraError();
			}
		}
		
		if(typeof this.cargando == "function"){
			this.cargando();
		}
	},
	
	errorFunction : function(){
		alert("Error:\nXMLHttpRequest.status: "+this.objeto.status+"\nXMLHttpRequest.readyState :"+this.objeto.readyState+"\nXMLHttpRequest.AllResponseHeaders: "+this.objeto.getAllResponseHeaders());
	}	
}
