﻿var LeerPagina=false;
var Destino="";

function EscribirEnCapa(Texto)
{
	document.getElementById(Destino).innerHTML=Texto;
}

function CargarPagina(URL, CapaDestino)
{
	LeerPagina=false;
	Destino=CapaDestino;
	if (window.ActiveXObject)
	{
		try
		{
			LeerPagina=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				LeerPagina=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){}
		}
	}
	else if (window.XMLHttpRequest)
	{
		LeerPagina=new XMLHttpRequest();
		if (LeerPagina.overrideMimeType) LeerPagina.overrideMimeType('text/xml');
	}
	
	if (!LeerPagina)
	{
		EscribirEnCapa("<font color=\"red\">El navegador no es compatible con esta característica.</font>");
		return false;
	}
	
	LeerPagina.onreadystatechange=RecibirDatos;
	LeerPagina.open('GET', URL, true);
	LeerPagina.send(null);
}
  
function RecibirDatos()
{
	if (LeerPagina.readyState==1) EscribirEnCapa("<div style=\"text-align: center;\"><img src=\"imagenes/cargando.gif\"></div>");
	else if (LeerPagina.readyState==4)
	{
		if (LeerPagina.status==200)
		{
			Resultado=LeerPagina.responseText;
			EscribirEnCapa(Resultado)
		}
		else EscribirEnCapa("<font color=\"rojo\">Se ha producido un error de lectura</font>");
	}
}
