function makeObject(archivo) {
  xmlhttp = false;
  this.AjaxFailedAlert = "Por favor, active JavaScript en su navegador para poder ver esta web correctamente.";
  this.requestFile = archivo;
  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) {
    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 sendAjax(archivo, mensaje_cargando, capa_receptora, parametros) {
  parametros = parametros.replace(/%0A/g,"<br />");
  ajax = makeObject(archivo);
  ajax.open("POST", archivo, true);
  ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  ajax.setRequestHeader("Content-length", parametros.length);
  ajax.setRequestHeader("Connection", "close");
  ajax.onreadystatechange = function() {
    if(ajax.readyState == 1) {
      document.getElementById(capa_receptora).innerHTML += '<p class="cargando">' + mensaje_cargando + '...</p>';
    }
    if(ajax.readyState == 4) {
      if(ajax.status == 200) {
        document.getElementById(capa_receptora).innerHTML = ajax.responseText;
      } else {
        document.getElementById(capa_receptora).innerHTML = '<p class="error">'  + ajax.status + '</p>';
      }
    }
  }
  ajax.send(parametros);
}
