
function criaXMLHttpRequest()
{
var XMLHTTPREQUEST_IE = new Array(
  "Msxml2.XMLHTTP.6.0",
  "Msxml2.XMLHTTP.5.0",
  "Msxml2.XMLHTTP.4.0",
  "Msxml2.XMLHTTP.3.0",
  "Msxml2.XMLHTTP",
  "Microsoft.XMLHTTP"
);
  var oXMLhttp = null;

  // Cria o HttpRequest para o respectivo navegador.
  if (window.XMLHttpRequest != null)
    oXMLhttp = new window.XMLHttpRequest();
  else if (window.ActiveXObject != null)
  {
    // Percorre no IE a procura do objeto ActiveX na biblioteca mais recente
    var bCriado = false;
    for (var ind = 0;
         ind < XMLHTTPREQUEST_IE.length && ! bCriado; ind++)		
    {
      try
      {
        oXMLhttp = new ActiveXObject(XMLHTTPREQUEST_IE[ind]);
        bCriado = true;
      }
      catch (ex)
      {}
    }
  }

  // Tratamento de erro caso não encontre nenhum.
  if (oXMLhttp == null)
    alert("Falha no HttpRequest():\n\n"
      + "Objeto XMLHttpRequest não foi criado.");

  // Retorna o objeto instanciado ou não
  return oXMLhttp;
}

