var http = getHTTPObject();
var _retFunc = "";
var ajax_trabajando = 0;

function getHTTPObject() {
var xmlhttp;

   /*@cc_on
   @if (@_jscript_version >= 5)
      try {
         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      }catch (e){
         try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
         }catch (E){
            xmlhttp = false;
         }
      }
   @else
      xmlhttp = false;
   @end @*/

   if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
      try {
         xmlhttp = new XMLHttpRequest();
      }catch (e){
         xmlhttp = false;
      }
   }
   return xmlhttp;
}


function ajax_getPagina(direccion, retFunc){
   if (!ajax_trabajando){
      _retFunc = retFunc;

      http.open("GET", direccion, true);
      http.onreadystatechange = callRetFunc;
      http.send(null);

      ajax_trabajando = 1;
   }
}

function callRetFunc() {
   /*
    0 – Uninitialised
    1 – Loading
    2 – Loaded
    3 – Interactive
    4 – Completed
   */
   if (http.readyState == 4) {
      ajax_trabajando = 0;

      if (http.status == 200){
         if (_retFunc == undefined){
            document.getElementById('div_contenido').innerHTML=http.responseText;
         }else{
            eval(_retFunc);
         }
      }else{
         alert('Error ' + http.status + ': Se encontro un error al conectarse a la página solicitada.');
      }

      http = getHTTPObject();
   }
}
