/**
 * browser.js
 *
 * Version 0.0 20040505
 *
 * (c) Top 21 GmbH
 *
 * Browser-Funktionen (Browser detection, Popups etc...)
 *
 */
// Liste m\u00f6glicher msxml-Versionen
//Passende Version kommt in diese Variable
// Browser Detection
var isIE = navigator.userAgent.toLowerCase().indexOf("msie") > - 1;
var isMoz = document.implementation && document.implementation.createDocument;

function BrowserSniffer()
{
   var ua = navigator.userAgent;
   this.isOpera = function()
   {
      return /Opera/.test(ua);
   }
   this.isSafari = function()
   {
      return /Safari/.test(ua);
   }
   this.isGecko = function()
   {
      return navigator.product == "Gecko" && !(this.isOpera() || this.isSafari());
   }
   this.isIEWin = function()
   {
      return window.external && /Win/.test(ua);
   }
   this.isIEMac = function()
   {
      return window.external && /Mac/.test(ua);
   }
   this.getVersion = function()
   {
      if(this.isIEWin() || this.isIEMac())
      {
         return Number(ua.match(/MSIE ([0-9.]+)/)[1]);
      }
      else if(this.isSafari())
      {
         return Number(ua.match(/[0-9.]+$/));
      }
      else if(this.isGecko())
      {
         return parseFloat(ua.match(/rv:([0-9.]+)/)[1]);
      }
      else if(this.isOpera())
      {
         return Number(ua.match(/Opera ([0-9.]+)/)[1]);
      }
      else 
      {
         return null;
      }
   }
   this.getType = function()
   {
      switch(true)
      {
         case this.isIEWin() :
            {
               return "Internet Explorer[Win]";
            }
         case this.isIEMac() :
            {
               return "Internet Explorer[Mac]";
            }
         case this.isOpera() :
            {
               return "Opera";
            }
         case this.isSafari() :
            {
               return "Safari";
            }
         case this.isGecko() :
            {
               return "Mozilla";
            }
      }
   }
   this.getShortType = function()
   {
      switch(true)
      {
         case this.isIEWin() :
            {
               return "IEwin";
            }
         case this.isIEMac() :
            {
               return "IEmac";
            }
         case this.isOpera() :
            {
               return "ope";
            }
         case this.isSafari() :
            {
               return "saf";
            }
         case this.isGecko() :
            {
               return "moz";
            }
      }
   }
   this.getLanguage = function()
   {
      if(this.isIEWin() || this.isIEMac())
      {
         return navigator.userLanguage;
      }
      else if(this.isGecko())
      {
         return navigator.language.substring(0, 2);
      }
   }
   this.getXMLParserVersion = function()
   {
      if(this.isIEWin())
      {
         var idList = new Array("MSXML2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XmlDom");
         // found progID flag
         var bFound = false;
         for(var i = 0; i < idList.length && !bFound; i++)
         {
            try
            {
               var oDoc = new ActiveXObject(idList[i]);
               o2Store = idList[i];
               bFound = true;
            }
            catch(objException)
            {
               // trap; try next progID
            }
         }
         if(!bFound)
         throw "Sarissa_Exception: Could not retreive a valid progID of Class: " + idList[idList.length - 1] + ". (original exception: " + e + ")";
         idList = null;
         return o2Store;
      }
      else if(this.isGecko() && this.getVersion() > 1.2)
      {
         return "GeckoXML";
      }
      else 
      {
         return false;
      }
   }
}
