
//Retorna una conexió AJAX en cas de tenir suport AJAX al browser.
//Retorna null en cas contrari.
   function getAjaxConn(){
     var ajconn=null;

      if (browserSupportsAjax()){
         if (typeof ActiveXObject != "undefined"){
            try{
               ajconn=new ActiveXObject("Msxml2.XMLHTTP");
            }catch (e){
               try{
                  ajconn=new ActiveXObject("Microsoft.XMLHTTP");
               }catch (e){
                  try{
                     ajconn=new ActiveXObject("Msxml2.XMLHTTP.4.0");
                  }catch (e){
                     ajconn=null;
                  }
               }
            }
         }else{
            try{
               ajconn=new XMLHttpRequest();
            }catch(e){
               try{
                  ajconn=window.createRequest();
               }catch(e){
                  ajconn=null;
               }
            }
         }
      }
      return ajconn;
   }

//Retorna un text amb el motiu pel qual el navegador no suporta AJAX
   function getNoAjaxReason(){

      var retMsg=null;

      if (!browserSupportsAjax()){
         retMsg="Tu browser no soporta AJAX.";
      }
      if (!ActiveXEnabledOrUnnecessary()){
         retMsg="No tienes activado el ActiveX."
      }
      return retMsg;
   }

//Retorna un valor booleà afirmatiu si el browser suporta AJAX i negatiu en cas contrari.
   function browserSupportsAjax(){
       if (typeof XMLHttpRequest == "undefined" && typeof ActiveXObject == "undefined" && window.createRequest == "undefined"){
            return false;
        }
        return true;
    }

// Detects if the browser can use ActiveX if necessary
    function ActiveXEnabledOrUnnecessary (){
        if (typeof ActiveXObject != "undefined")
        {
            var xhr = null;
            try{
                xhr=new ActiveXObject("Msxml2.XMLHTTP");
            }catch (e){
                try{
                    xhr=new ActiveXObject("Microsoft.XMLHTTP");
                }catch (e2){
                    try{
                        xhr=new ActiveXObject("Msxml2.XMLHTTP.4.0");
                    }catch (e3){
                        xhr=null;
                    }
                }
            }
            if (xhr == null)
            {
                return false;
            }
        }
        return true;
    }

