function CargarPagina(pagina, destino, espera)
{
	destino = (typeof(arguments[1]) == "undefined")?"#cuerpo" : arguments[1];
	espera = (typeof(arguments[2]) == "undefined")? true : arguments[2];

	if (espera)
	{
		/*$(destino).ajaxStart(function(){
		   $(this).load("espera.html");
		 });*/
		 $(destino).html("<img src=\"imagenes/loading.gif\">&nbsp;Cargando / Loading...");
	}

	$(destino).load(pagina,
					function(responseText, status)
					{
						if (!ErrorAjax(status, this))
						{
							ScrollTop(this);
							CambiarEnlaces(this);
						}
					});
}

function MostrarEspera()
{
	$("#cuerpo").load("espera.html");
}

function ErrorAjax(estado, elemento)
{
	if (estado != "success")
	{
		$(elemento).html("<b>No se encontró la página solicitada</b>");
		return true;
	}

	return false;
}

function ScrollTop(elemento)
{
	$(elemento).scrollTop(0);
}

function CambiarEnlaces(contexto)
{
	$("a", contexto).each(
		function(){
			if (!$(this).attr("target") &&
				$(this).attr("href").indexOf("mailto:") == -1)
			{
				if ($(this).attr("href").indexOf(".htm") == -1 &&
					$(this).attr("href").indexOf(".html") == -1)
				{
					$(this).attr("target", "_blank");
				}
				else
				{
					$(this).attr("href", "javascript:CargarPagina('" + $(this).attr("href") + "')");
					$(this).attr("target", "_self");
				}
			}
		});
}
