// :::::::::::::::::::::::::::::::::::
// ::::::::: Funciones AJAX ::::::::::
// :::::::::::::::::::::::::::::::::::

// Crear Objeto Ajax
function new_ajax(file)
{
	xmlhttp=false;
	this.AjaxFailedAlert = "Su navegador no soporta las funcionalidades de este sitio y podria experimentarlo de forma diferente a la que fue pensada. Por favor habilite javascript en su navegador para verlo normalmente.\n";
	this.requestFile = file;
	this.encodeURIString = true;
	this.execute = false;
	if (window.XMLHttpRequest)
	{
		this.xmlhttp = new XMLHttpRequest();
        if (this.xmlhttp.overrideMimeType)
		{
			this.xmlhttp.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject)
	{ // IE
		try
		{
			this.xmlhttp  = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{ 
			try
		 	{
			 	this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				this.xmlhttp = null;
			}
       	}
		if (!this.xmlhttp  && typeof XMLHttpRequest!='undefined')
		{	
			this.xmlhttp = new XMLHttpRequest();
		    if (!this.xmlhttp)
			{
				this.failed = true; 
			}
		}
	}
	return this.xmlhttp ;
}

function load_page_ajax(pagina, variable_valor, metodo, capa) 
{ 
        var aleatorio=Math.random();  //variable auxiliar para solucionar la cache de IE del lado cliente
		var url;
		
		ajax=new_ajax(pagina); 
		
		url = pagina + "?" + variable_valor + "&id=" + aleatorio 
		
		if (metodo.toUpperCase()=='POST')
		{
			ajax.open("POST", url, true);
		}
		if (metodo.toUpperCase()=='GET')
		{
			ajax.open("GET", url + aleatorio, true);
		}

        ajax.onreadystatechange=function() 
        { 
			// if (ajax.readyState==4 && (ajax.status==200 || window.location.href.indexOf("http")==-1)) 
            // { 
			//		document.getElementById(id_contenido).innerHTML=ajax.responseText;
            // } 
			// *****************************************************
			if (ajax.readyState==1)
			{
				document.getElementById(capa).innerHTML = "<br><p align='center' style='font-size:11px; color:#00618A; font-family:Arial'><img src='imagenes/spinner.gif' border='0' vspace = '5' ><br>Aguarde por favor ...</p><br>&nbsp;";
			}
			if (ajax.readyState==4)
			{	
				if(ajax.status==200)
				{
					document.getElementById(capa).innerHTML = ajax.responseText;
				}
				else
				{
					if(ajax.status==404)
					{
						capa.innerHTML = "<br><p align='center' style='font-size:11px; color:#00618A; font-family:Arial'>La direcci&oacute;n no existe.</p><br>&nbsp;";
                    }
                    else
                    { 
						capa.innerHTML = "<br><p align='center' style='font-size:11px; color:#00618A; font-family:Arial'>Error: " + ajax.status; + "</p><br>&nbsp;"; 
                    }
				}
			}
			// *****************************************************
        } 

		if (metodo.toUpperCase()=='POST')
		{
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send(variable_valor);
		}
		if (metodo.toUpperCase()=='GET')
		{
        	ajax.send(null);
		}
} 
