function objetoAjax(){
	var xmlhttp=false;
	//NetScape
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		// para internet Explorer
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}
	//Para Safari y Mozilla
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function peticion_http(url, capa, barra){
	//alert('url:'+url+' capa:'+capa+' barra:'+barra+'\n');
	//aki debemos mostrar el gif de cargando
	show = true;
	document.getElementById(barra).style.display = (show == true) ? "inline" : "none";		

	var divDestino = document.getElementById(capa);
	ajax=objetoAjax();
	//evitamos que haga cache
	url_unica = url+'?ms='+ new Date().getTime();
	ajax.open("GET", url_unica,true);
	/*original
	ajax.open("GET", url);
	*/
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			//trakeo de estatus de la chiva esta 200 es igual a OK 404 no encontrado
			/*alert('Status is ' + ajax.status+' - '+ajax.statusText);
			if (ajax.status == 200) {
       		  alert('Status is ' + ajax.status+' - '+ajax.statusText);
      		}*/
			
			if (ajax.status == 200) {
				//antes de imprimir el resultado ocultamos el gif de cargando
				show = false;
				document.getElementById(barra).style.display = (show == true) ? "inline" : "none";		
				// imprimimos el resultado
				//paso = encodeURIComponent(ajax.responseText);
				paso = Utf8.decode(ajax.responseText);
				divDestino.innerHTML = paso;
			} else {
				//validamos ell tipo de error para que el usuario sepa maás que petter con nuestro bussiness
				if(ajax.status == 404){
  				document.getElementById(barra).style.display = "none";		
					alert('Lo lamentamos el archivo que solicitaste YA NO EXISTE en el servidor, \n porfavor contacta con soporte.\n');
				} else {
  				document.getElementById(barra).style.display = "none";		
					alert('ˇFalló la carga!\n\n El estatus de Ajax es: ' + ajax.status+' - '+ajax.statusText+'\n\n Por favor reintente la operación,\n es posible que por problemas de red no pudimos antender su petición.');
				}
			}
		}
	}
	// Original, importante dejar NULL para los firefoxes y los demas
	ajax.send(null);
}

var Utf8 = {

	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}
