//--------------------------------------------------------------------------------------------------//
//--------------------------------------------------------------------------------------------------//
function GetXmlHttpObject(handler)
{
        var objXmlHttp=null
        if (navigator.userAgent.indexOf("Opera")>=0)
        {
                objXmlHttp=new XMLHttpRequest();
                objXmlHttp.onload=handler;
                objXmlHttp.onerror=handler;
                return objXmlHttp;
        }
        if (navigator.userAgent.indexOf("MSIE")>=0)
        {
                var strName="Msxml2.XMLHTTP";
                if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
                {
                        strName="Microsoft.XMLHTTP";
                }
                try
                {
                        objXmlHttp=new ActiveXObject(strName);
                        objXmlHttp.onreadystatechange=handler;
                        return objXmlHttp;
                }
                catch(e)
                {
                        alert("Error. ActiveX puede estar deshabilitado");
                        return;
                }
        }
        if (navigator.userAgent.indexOf("Mozilla")>=0)
        {
                objXmlHttp=new XMLHttpRequest();
                objXmlHttp.onload=handler;
                objXmlHttp.onerror=handler;
                return objXmlHttp;
        }
}
//--------------------------------------------------------------------------------------------------//
/*
Envía una petición ajax a la url indicada
url              : url del script que se va a ejecutar
parametros       : parametros a pasar
funcionRetorno   : funcion de retorno
tipoRequest      : POST o GET
asincrono        : asincrono o sincrono, TRUE o FALSE
*/
function peticionAjax(url,parametros,funcionRetorno,tipoRequest,asincrono)
{

        if(tipoRequest=='POST')
        {
                xmlHttp=GetXmlHttpObject(funcionRetorno)
                xmlHttp.open("POST",url,asincrono);
                xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
                xmlHttp.send(parametros);
        }
        else if(tipoRequest=="GET")
        {
                url    = url+'?'+parametros;
                xmlHttp=GetXmlHttpObject(funcionRetorno)
                xmlHttp.open("GET", url , asincrono)
                xmlHttp.send(null)
        }
}

function ejecutaJS()
{
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
      eval(xmlHttp.responseText);
   }
}
function muestraHTML()
{
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
      document.getElementById(elementoAjax).innerHTML=xmlHttp.responseText;
   }
}

