/***********************************************************************
CONTIENE LOS METODOS AJAX UTILIZADOS PARA LA CONECCION EN EL SITIO
***********************************************************************/
function AjaxLoader(url, method) {
	
	//------------------------------------------------------
	// CONSTRUCTOR
	//------------------------------------------------------
	var _this 				= this;

	//var
	//Subo a mayuscula, para ahorrar problemas jaja
	_this.method 		= method.toUpperCase();
	
	//Url
	_this.url 			= url;
	
	//------------------------------------------------------
	// PROPIEDADES {PLUBLIC} (funciones)
	//------------------------------------------------------
    _this.whenLoaded	= false;
    _this.whenError		= false;
	_this.whenLoading	= false;
	
	//------------------------------------------------------
	// METODOS
	//------------------------------------------------------

	/*
		Crea una coneccion ajax nueva
		{PRIVATE}
	*/
	_this.createConnection = function() {
    	if(navigator.appName == "Microsoft Internet Explorer") {
    		try {
    			return new ActiveXObject('Msxml2.XMLHTTP');
    		} catch(e) {
    			try {
    				return new ActiveXObject('Microsoft.XMLHTTP');
    			} catch(e) {}
    		}
    	} else {
    		return new XMLHttpRequest();
    	}
	}
	
	/*
        Maneja los eventos segun los estados de la coneccion
        {PRIVATE}
    */
	_this.estadosChange = function() {
		if(_this.conn.readyState == 1) {
			if(_this.whenLoading) _this.whenLoading();
		} else if(_this.conn.readyState == 2) {
			
		} else if(_this.conn.readyState == 3) {
			
		} else if(_this.conn.readyState == 4) {
			if(_this.whenLoaded) _this.whenLoaded();
		}
	}
	
	/*
        Realiza el proceso de carga de la informacion
	   {PUBLIC}
    */
    _this.Load = function(param) {
		_this.param = param;
		if(_this.conn) { _this.conn.abort(); }
		_this.conn = _this.createConnection();
		
		url = (_this.method == 'POST') ? _this.url : _this.url+"?"+param;
		
		_this.conn.open(_this.method, url, true);
		_this.conn.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_this.conn.onreadystatechange = _this.estadosChange;
		
		_this.conn.send((_this.method == 'POST') ? param : null);
	}
	
	/*
        Recarga el load que se hizo ateriormente
	   {PUBLIC}
    */
    _this.Reload = function() {
		_this.Load(_this.param);	
	}
	
	/*
        Devuelve el resultado del Request
	   {PUBLIC}
    */
    _this.Response = function(type)	{
		if(type == 'text') {
			return _this.conn.responseText;
		} else if(type == 'xml') {
			return _this.conn.responseXML;
		} else {
    		return false;  
		}
	}
	
}
/***********************************************************************
XML PARSER
***********************************************************************/

function loadXML(archivo, async)
{
	var xml = false;
	
	try {
		xml = new ActiveXObject("Microsoft.XMLDOM");
	} catch (e) {
		try {
			xml = document.implementation.createDocument("", "", null);
		} catch (e) {
			window.alert(e.message);
		}
	}
	
	try {
		xml.async = (!async) ? false : async;
		xml.load(archivo);
	} catch (e) {
		window.alert(e.message);	
	}
	
	return xml;
}

///////////////////////////////////////////////////////////////////////////
// EVENTOS
///////////////////////////////////////////////////////////////////////////
function setEvent(elemento, evento, funcion) {
      if (elemento.addEventListener) {
            elemento.addEventListener(evento, funcion, false);
      } else {
            elemento.attachEvent("on"+evento, funcion);
      }
}
/***********************************************************************
MIS FUNCIONES EXTENDIDAS
***********************************************************************/