var accesoAJAX=new Object();
accesoAJAX.READY_STATE_UNINITIALIZED=0;
accesoAJAX.READY_STATE_LOADING=1;
accesoAJAX.READY_STATE_LOADED=2;
accesoAJAX.READY_STATE_INTERACTIVE=3;
accesoAJAX.READY_STATE_COMPLETE=4;
// constructor delobjeto por medio de una funcion
accesoAJAX.CargadorDeDatos=function(method,uri,func) {
    this.func=func;
    this.method=method;
    this.uri=uri;
    this.req=null;
    this.cargaDeDatos(uri,func);
} // fin constructor del objeto CargadorDeNoticias

// cuerpo del objeto accesoXMLNoticias.CargadorDeNoticias
accesoAJAX.CargadorDeDatos.prototype={
    // este metodo se encarga de dirigir la operacion de carga de
    // un documento XML
    cargaDeDatos:function() {
        // PASO #1: Crea un objeto capaz de realizar la conexion
        if (window.XMLHttpRequest) {
            // en el caso para Mozilla
            this.req=new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            // en el caso para IE
            this.req=new ActiveXObject("Microsoft.XMLHTTP");
        } // if-then-else
        if (this.req) {
            // la conexion es posible, dado el DOM del cliente
            try {
                // PASO #2: establece como actuar cuando exista
                // la conexion y esta genere un evento de cargado
                // de datos
                var cargador=this;
	            
                this.req.onreadystatechange=function() {
                    cargador.onReadyState.call(cargador);
                } // fin callback onReadyStateChange

                // PASO #3: ahora intenta la conexion con el servidor
                this.req.open(
                    this.method,
                    this.uri,
                    true
                );

               // PASO #4: haz un envio de prueba, sin impacto posterior
               this.req.send(null);

            } catch (err) {
                this.defaultError.call(this);
            } // fin try-catch
        } // fin if-then
    } // fin cargaUltimasNoticias
    ,
    // este metodo se encarga de despachar acciones que operan cuando
    // el cargador de datos detone eventos de cambio en su estado, como
    // es la recepcion de informacion desde el servidor
    onReadyState:function() {
        var req=this.req;   // objeto que mantiene la comunicacion
        var listo=req.readyState;   // como se encuentra la comm?

        if (listo==accesoAJAX.READY_STATE_COMPLETE) {
            var estatusHTTP=req.status;
            if (estatusHTTP==200 || estatusHTTP==0) {
                // fue exitosa!! ve y apunta al contenido recien generado
                var data=req.responseText;
                //alert("aeduan 1");
					this.func(data);
				//alert("aeduan 2");

            } else {
                // causo error!! ve y reportalo
                this.defaultError.call(this);
            } // fin if-then-else
        } // fin if-then
    } // fin onReadyState
    ,
    defaultError:function() {
        // este metodo se encarga de reportar al cliente que ha
        // existido una falla en la comunicacion de datos con
        // el servidor
		//alert("error");
		// window.parent.location = '/jsp/error/_500.jsp';
		/*
        alert("error al cargar la informacion"
            + "\n\nreadyState:"+this.req.readyState
            + "\nstatus:"+this.req.status
            + "\nheaders:"+this.req.getAllResponseHeaders()
        );*/
    } // fin defaultError
} // fin cuerpo del objeto accesoXMLNoticias.CargadorDeNoticias
