var peticion_http=new Object();

peticion_http.ESTADO_COMPLETO=0;
peticion_http.ESTADO_CARGANDO=1;
peticion_http.ESTADO_CARGADO=2;
peticion_http.ESTADO_INTERACTIVO=3;
peticion_http.ESTADO_COMPLETO=4;

peticion_http.crear=function(url,funcion,funcionError,metodo,parametros,contentType){ 
//Constructor
	this.url=url;
	this.req=null;
	this.onload=funcion;
	this.onerror=(funcionError)?funcionError:this.defaultError;
	this.cargarXHR(url,metodo,parametros,contentType);
}
peticion_http.crear.prototype={
	cargarXHR: function(url,metodo,parametros,contentType){
		if(window.XMLHttpRequest){ //Mozilla, Opera, Safari...
			this.req=new XMLHttpRequest();
		}else if(window.ActiveXObject){ //IE
			this.req=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if(this.req){
			try{
				var loader=this;
				this.req.onreadystatechange=function(){
					loader.onReadyState.call(loader);
				}
				this.req.open(metodo,url,true);
				if(contentType){
					this.req.setRequestHeader("Content-Type",contentType);
				}
				this.req.send(parametros);
			}catch(err){
				this.onerror.call(this);
			}
		}
	},

	onReadyState: function(){
		if(this.req.readyState==peticion_http.ESTADO_COMPLETO){
			if(this.req.status==200||this.req.status==0){
				this.onload.call(this);
			}else{
				this.onerror.call(this);
			}
		}
	},

	defaultError: function(){
		alert("Error al cargar los datos");
	}
}