/*
 * jsBrwSniff v0.6
 *
 * A browser sniffer library
 * http://jsbrwsniff.sf.net
 *
 * Released under the GNU LGPL license
 * Author: Pau Garcia i Quiles <paugq AT users DOT sourceforge DOT net>
 * Updated: June 23, 2005 by Joey Lott <joey AT person13 DOT com>
 *
 */
function BrowserSniffer(obj) {

    (this.isEmpty(obj) ? this.userAgent=navigator.userAgent.toLowerCase() : this.userAgent=obj);

    if (this.userAgent.search(/omniweb[\/\s]v?(\d+([\.-]\d)*)/) != -1) {
    // Omniweb
        this.browser="omniweb";
        this.browserVersion=this.userAgent.match(/omniweb[\/\s]v?(\d+([\.-]\d)*)/)[1];
        (this.browserVersion > 4.5 ? this.engine="khtml" : this.engine="omniweb");
        (this.userAgent.search(/omniweb[\/\s]((\d+([\.-]\d)*)-)?v(\d+([\.-]\d)*)/) == -1 ?       this.engineVersion=this.userAgent.match(/omniweb[\/\s](\d+([\.-]\d)*)/)[1] :        this.engineVersion=this.userAgent.match(/omniweb[\/\s]((\d+([\.-]\d)*)-)?v(\d+([\.-]\d)*)/)[4]);
        
    } else if (this.userAgent.search(/opera[\/\s](\d+(\.?\d)*)/) != -1) {
    // Opera
        this.browser="opera";
        this.browserVersion=this.userAgent.match(/opera[\/\s](\d+(\.?\d)*)/)[1];
        this.engine="opera";
        this.engineVersion=this.browserVersion;
        
    } else if (this.userAgent.search(/crazy\s?browser\s(\d+(\.?\d)*)/) != -1) {
    // Crazy Browser
        this.browser="crazy";
        this.browserVersion=this.userAgent.match(/crazy\s?browser\s(\d+(\.?\d)*)/)[1];
        this.engine="msie";
        this.engineVersion=this.getMSIEVersion();
        
    } else if (this.userAgent.search(/myie2/) != -1) {
    // MyIE2
        this.browser="myie2";
        this.engine="msie";
        this.engineVersion=this.userAgent.match(/msie\s(\d+(\.?\d)*)/)[1];
        
    } else if (this.userAgent.search(/netcaptor/) != -1) {
    // NetCaptor
        this.browser="netcaptor";
        this.browserVersion=this.userAgent.match(/netcaptor\s(\d+(\.?\d)*)/)[1];
        this.engine="msie";
        this.engineVersion=this.getMSIEVersion();
        
    } else if (this.userAgent.search(/avant\sbrowser/) != -1) {
    // Avant Browser
        this.browser="avantbrowser";
        this.engine="msie";
        this.engineVersion=this.getMSIEVersion();
        
    } else if (this.userAgent.search(/msn\s(\d+(\.?\d)*)/) != -1) {
    // MSN Explorer
        this.browser="msn";
        this.browserVersion=this.userAgent.match(/msn\s(\d+(\.?\d)*)/)[1];
        this.engine="msie";
        this.engineVersion=this.getMSIEVersion();
        
    } else if (this.userAgent.search(/msie\s(\d+(\.?\d)*)/) != -1) {
    // MS Internet Explorer
        this.browser="msie";
        this.browserVersion=this.getMSIEVersion();
        this.engine="msie";
        this.engineVersion=this.browserVersion;
        
    } else if (this.userAgent.search(/powermarks\/(\d+(\.?\d)*)/) != -1) {
    // PowerMarks
        this.browser="powermarks";
        this.browserVersion=this.userAgent.match(/powermarks\/(\d+(\.?\d)*)/)[1];
        this.engine="msie";
        try {
            this.engineVersion=this.getMSIEVersion();
        } catch (e) { }
        
} else if (this.userAgent.search(/konqueror[\/\s](\d+([\.-]\d)*)/) != -1) {
    // Konqueror
        this.browser="konqueror";
        this.browserVersion=this.userAgent.match(/konqueror[\/\s](\d+([\.-]\d)*)/)[1];
        this.engine="khtml";
        
    } else if (this.userAgent.search(/safari\/(\d)*/) != -1) {
    // Safari
        this.browser="safari";
        this.browserVersion=this.userAgent.match(/safari\/(\d+(\.?\d*)*)/)[1];
        this.engine="khtml";
        this.engineVersion=this.userAgent.match(/applewebkit\/(\d+(\.?\d*)*)/)[1];
        
    } else if(this.userAgent.search(/zyborg/) != -1) {
    // Zyborg (SSD)
        this.browser="zyborg";
        this.browserVersion=this.userAgent.match(/zyborg\/(\d+(\.?\d)*)/)[1];
        this.engine="robot";
        this.engineVersion="-1"
        
    } else if (this.userAgent.search(/netscape6[\/\s](\d+([\.-]\d)*)/) != -1) {
    // Netscape 6.x
        this.browser="netscape";
        this.browserVersion=this.userAgent.match(/netscape6[\/\s](\d+([\.-]\d)*)/)[1];
        this.engine="gecko";
        this.engineVersion=this.getGeckoVersion();
        
    } else if (this.userAgent.search(/netscape\/(7\.\d*)/) != -1) {
    // Netscape 7.x
        this.browser="netscape";
        this.browserVersion=this.userAgent.match(/netscape\/(7\.\d*)/)[1];
        this.engine="gecko";
        this.engineVersion=this.getGeckoVersion();
        
    } else if (this.userAgent.search(/galeon[\/\s](\d+([\.-]\d)*)/) != -1) {
    // Galeon
        this.browser="galeon";
        this.browserVersion=this.userAgent.match(/galeon[\/\s](\d+([\.-]\d)*)/)[1];
        this.engine="gecko";
        this.engineVersion=this.getGeckoVersion();
        
    } else if (this.userAgent.search(/nautilus[\/\s](\d+([\.-]\d)*)/) != -1) {
    // Nautilus
        this.browser="nautilus";
        this.browserVersion=this.userAgent.match(/nautilus[\/\s](\d+([\.-]\d)*)/)[1];
        this.engine="gecko";
        this.engineVersion=this.getGeckoVersion();
        
    } else if (this.userAgent.search(/firefox[\/\s](\d+([\.-]\d)*)/) != -1) {
    // Firefox
        this.browser="firefox";
        this.browserVersion=this.userAgent.match(/firefox[\/\s](\d+([\.-]\d)*)/)[1];
        this.engine="gecko";
        this.engineVersion=this.getGeckoVersion();
        
    } else if (this.userAgent.search(/k-meleon[\/\s](\d+([\.-]\d)*)/) != -1) {
    // K-Meleon
        this.browser="kmeleon";
        this.browserVersion=this.userAgent.match(/k-meleon[\/\s](\d+([\.-]\d)*)/)[1];
        this.engine="gecko";
        this.engineVersion=this.getGeckoVersion();
        
    } else if (this.userAgent.search(/firebird[\/\s](\d+([\.-]\d)*)/) != -1) {
    // Firebird
        this.browser="firebird";
        this.browserVersion=this.userAgent.match(/firebird[\/\s](\d+([\.-]\d)*)/)[1];
        this.engine="gecko";
        this.engineVersion=this.getGeckoVersion();
        
    } else if (this.userAgent.search(/phoenix[\/\s](\d+([\.-]\d)*)/) != -1) {
    // Phoenix
        this.browser="phoenix";
        this.browserVersion=this.userAgent.match(/phoenix[\/\s](\d+([\.-]\d)*)/)[1];
        this.engine="gecko";
        this.engineVersion=this.getGeckoVersion();
        
    } else if (this.userAgent.search(/camino[\/\s](\d+([\.-]\d)*)/) != -1) {
    // Camino
        this.browser="camino";
        this.browserVersion=this.userAgent.match(/camino[\/\s](\d+([\.-]\d)*)/)[1];
        this.engine="gecko";
        this.engineVersion=this.getGeckoVersion();
        
    } else if (this.userAgent.search(/epiphany[\/\s](\d+([\.-]\d)*)/) != -1) {
    // Epiphany
        this.browser="epiphany";
        this.browserVersion=this.userAgent.match(/epiphany[\/\s](\d+([\.-]\d)*)/)[1];
        this.engine="gecko";
        this.engineVersion=getGeckoVersion();
        
    } else if (this.userAgent.search(/chimera[\/\s](\d+([\.-]\d)*)/) != -1) {
    // Chimera
        this.browser="chimera";
        this.browserVersion=this.userAgent.match(/chimera[\/\s](\d+([\.-]\d)*)/)[1];
        this.engine="gecko";
        this.engineVersion=this.getGeckoVersion();
        
    } else if (this.userAgent.search(/icab[\s\/]?(\d+(\.?\d)*)/) !=-1) {
    // iCab
        this.browser="icab";
        this.browserVersion=this.userAgent.match(/icab[\s\/]?(\d+(\.?\d)*)/)[1];
        this.engine="icab";
        this.engineVersion=this.browserVersion;
        
    } else if (this.userAgent.search(/netfront\/(\d+([\._]\d)*)/) != -1) {
    // NetFront
        this.browser="netfront";
        this.browserVersion=this.userAgent.match(/netfront\/(\d+([\._]\d)*)/)[1];
        this.engine="netfront";
        this.engineVersion=this.browserVersion;
        
    } else if (this.userAgent.search(/netscape4\/(\d+([\.-]\d)*)/) != -1) {
    // Netscape 4.x
        this.browser="netscape";
        this.browserVersion=this.userAgent.match(/netscape4\/(\d+([\.-]\d)*)/)[1];
        this.engine="mozold";
        this.engineVersion=this.browserVersion;
        
    } else if ( (this.userAgent.search(/mozilla\/(4.\d*)/) != -1) && (this.userAgent.search(/msie\s(\d+(\.?\d)*)/) == -1) ) {
        this.browser="netscape";
        this.browserVersion=this.userAgent.match(/mozilla\/(4.\d*)/)[1];
        this.engine="mozold";
        this.engineVersion=this.browserVersion;
        
    } else if ((this.userAgent.search(/mozilla\/5.0/) != -1) && (this.userAgent.search(/gecko\//) != -1)) {
    // Mozilla Seamonkey
        this.browser="mozsea";
        this.browserVersion=this.userAgent.match(/rv\x3a(\d+(\.?\d)*)/)[1];
        this.engine="gecko";
        this.engineVersion=this.getGeckoVersion();
        
    } else if (this.userAgent.search(/elinks/) != -1) {
    // ELinks
        this.browser="elinks";
        (this.userAgent.search(/elinks\/(\d+(\.?\d)*)/) == -1 ?
this.browserVersion=this.userAgent.match(/elinks\s\x28(\d+(\.?\d)*)/)[1] :
this.browserVersion=this.userAgent.match(/elinks\/(\d+(\.?\d)*)/)[1]);
        this.engine="elinks";
        this.engineVersion=this.browserVersion;
        
    } else if (this.userAgent.search(/w3m\/(\d+(\.?\d)*)/) != -1) {
    // w3m
        this.browser="w3m"
        this.browserVersion=this.userAgent.match(/(^w3m|\sw3m)\/(\d+(\.?\d)*)/)[2];
        this.engine="w3m";
        this.engineVersion=this.browserVersion;
        
    } else if (this.userAgent.search(/links/) != -1) {
    // Links
        this.browser="links";
        (this.userAgent.search(/links\/(\d+(\.?\d)*)/) == -1 ? this.browserVersion=this.userAgent.match(/links\s\x28(\d+(\.?\d)*)/)[1] : this.browserVersion=this.userAgent.match(/links\/(\d+(\.?\d)*)/)[1]);
        this.engine="links";
        this.engineVersion=this.browserVersion;
        
    } else if (this.userAgent.search(/java[\/\s]?(\d+([\._]\d)*)/) != -1) {
    // Java (as web-browser)
        this.browser="java";
        this.browserVersion=this.userAgent.match(/java[\/\s]?(\d+([\._]\d)*)/)[1];
        this.engine="java";
        this.engineVersion=this.browserVersion;
        
    } else if(this.userAgent.search(/lynx/) != -1) {
    // Lynx (SSD)
        this.browser="lynx";
        this.browserVersion=this.userAgent.match(/lynx\/(\d+(\.?\d)*)/)[1];
        this.engine="libwww-fm";
        this.engineVersion=this.userAgent.match(/libwww-fm\/(\d+(\.?\d)*)/)[1];
        
    } else if(this.userAgent.search(/dillo/) != -1) {
    // Dillo (SSD)
        this.browser="dillo";
        this.browserVersion=this.userAgent.match(/dillo\s*\/*(\d+(\.?\d)*)/)[1];
        this.engine="dillo";
        this.engineVersion=this.browserVersion;
        
    } else if(this.userAgent.search(/wget/) != -1) {
    // wget (SSD)
        this.browser="wget";
        this.browserVersion=this.userAgent.match(/wget\/(\d+(\.?\d)*)/)[1];
        this.engine="robot";
        this.engineVersion="-1"
        
    } else if(this.userAgent.search(/googlebot\-image/) != -1) {
    // GoogleBot-Image (SSD)
        this.browser="googlebotimg";
        this.browserVersion=this.userAgent.match(/googlebot\-image\/(\d+(\.?\d)*)/)[1];
        this.engine="robot";
        this.engineVersion="-1"
        
    } else if(this.userAgent.search(/googlebot/) != -1) {
    // GoogleBot (SSD)
        this.browser="googlebot";
        this.browserVersion=this.userAgent.match(/googlebot\/(\d+(\.?\d)*)/)[1];
        this.engine="robot";
        this.engineVersion="-1"
        
    } else if(this.userAgent.search(/msnbot/) != -1) {
    // MSNBot (SSD)
        this.browser="msnbot";
        this.browserVersion=this.userAgent.match(/msnbot\/(\d+(\.?\d)*)/)[1];
        this.engine="robot";
        this.engineVersion="-1"
        
    } else if(this.userAgent.search(/turnitinbot/) != -1) {
    // Turnitin (SSD)
        this.browser="turnitinbot";
        this.browserVersion=this.userAgent.match(/turnitinbot\/(\d+(\.?\d)*)/)[1];
        this.engine="robot";
        this.engineVersion="-1"
        
    } else {
        this.browser="unknown";
        
    }

    this.majorVersion = (this.isEmpty(this.version) ? -1 : (this.hasDot(this.version) ? this.version : this.version.match(/(\d*)(\.\d*)*/)[1]))

    this.minorVersion = (!this.isEmpty(this.version) ? (!this.hasDot(this.version) ? this.version.match(/\.(\d*([-\.]\d*)*)/)[1] : 0) :
-1)

    if (this.userAgent.search(/windows\sce/) != -1) {
        this.os="wince";
        try {
            this.osVersion=this.userAgent.match(/windows\sce\/(\d+(\.?\d)*)/)[1];
        } catch (e) { }
        
    } else if ( (this.userAgent.search(/windows/) !=-1) || ((this.userAgent.search(/win9\d{1}/) !=-1))
) {
        this.os="win";
        if (this.userAgent.search(/nt\s5\.1/) != -1) {
            this.osVersion="xp";
        } else if (this.userAgent.search(/nt\s5\.0/) != -1) {
            this.osVersion="2000";
        } else if ( (this.userAgent.search(/win98/) != -1) || (this.userAgent.search(/windows\s98/)!=
-1 ) ) {
            this.osVersion="98";
        } else if (this.userAgent.search(/windows\sme/) != -1) {
            this.osVersion="me";
        } else if (this.userAgent.search(/nt\s5\.2/) != -1) {
            this.osVersion="win2k3";
        } else if ( (this.userAgent.search(/windows\s95/) != -1) || (this.userAgent.search(/win95/)!=
-1 ) ) {
            this.osVersion="95";
        } else if ( (this.userAgent.search(/nt\s4\.0/) != -1) || (this.userAgent.search(/nt4\.0/) ) !=
-1) {
            this.osVersion="nt4";
        }

        
    } else if (this.userAgent.search(/linux/) !=-1) {
        this.os="linux";
        try {
            this.osVersion = this.userAgent.match(/linux\s?(\d+(\.?\d)*)/)[1];
        } catch (e) { }
        
    } else if (this.userAgent.search(/mac\sos\sx/) !=-1) {
        this.os="macosx";
        
    } else if (this.userAgent.search(/freebsd/) !=-1) {
        this.os="freebsd";
        try {
            this.osVersion = this.userAgent.match(/freebsd\s(\d(\.\d)*)*/)[1];
        } catch (e) { }
        
    } else if (this.userAgent.search(/sunos/) !=-1) {
        this.os="sunos";
        try {
            this.osVersion=this.userAgent.match(/sunos\s(\d(\.\d)*)*/)[1];
        } catch (e) { }
        
    } else if (this.userAgent.search(/irix/) !=-1) {
        this.os="irix";
        try {
            this.osVersion=this.userAgent.match(/irix\s(\d(\.\d)*)*/)[1];
        } catch (e) { }
        
    } else if (this.userAgent.search(/openbsd/) !=-1) {
        this.os="openbsd";
        try {
            this.osVersion = this.userAgent.match(/openbsd\s(\d(\.\d)*)*/)[1];
        } catch (e) { }
        
    } else if ( (this.userAgent.search(/macintosh/) !=-1) || (this.userAgent.search(/mac\x5fpowerpc/)
!= -1) ) {
        this.os="macclassic";
        
    } else if (this.userAgent.search(/os\/2/) !=-1) {
        this.os="os2";
        try {
            this.osVersion=this.userAgent.match(/warp\s((\d(\.\d)*)*)/)[1];
        } catch (e) { }
        
    } else if (this.userAgent.search(/openvms/) !=-1) {
        this.os="openvms";
        try {
            this.osVersion=this.userAgent.match(/openvms\sv((\d(\.\d)*)*)/)[1];
        } catch (e)  { }
        
    } else if ( (this.userAgent.search(/amigaos/) !=-1) || (this.userAgent.search(/amiga/) != -1) ) {
        this.os="amigaos";
        try {
            this.osVersion=this.userAgent.match(/amigaos\s?(\d(\.\d)*)*/)[1];
        } catch (e) { }
        
    } else if (this.userAgent.search(/hurd/) !=-1) {
        this.os="hurd";
        
    } else if (this.userAgent.search(/hp\-ux/) != -1) {
        this.os="hpux";
        try {
            this.osVersion=this.userAgent.match(/hp\-ux\sb\.[\/\s]?(\d+([\._]\d)*)/)[1];
        } catch (e) { }
        
    } else if ( (this.userAgent.search(/unix/) !=-1) || (this.userAgent.search(/x11/) != -1 ) ) {
        this.os="unix";
        
    } else if (this.userAgent.search(/cygwin/) !=-1) {
        this.os="cygwin";
        
    } else if (this.userAgent.search(/java[\/\s]?(\d+([\._]\d)*)/) != -1) {
        this.os="java";
        try {
            this.osVersion=this.userAgent.match(/java[\/\s]?(\d+([\._]\d)*)/)[1];
        } catch (e) { }
        
    } else if (this.userAgent.search(/palmos/) != -1) {
        this.os="palmos";
        
    } else if (this.userAgent.search(/symbian\s?os\/(\d+([\._]\d)*)/) != -1) {
        this.os="symbian";
        try {
            this.osVersion=this.userAgent.match(/symbian\s?os\/(\d+([\._]\d)*)/)[1];
        } catch (e) { }
        
    } else {
        this.os="unknown";
        
    }

//    if (this.engine!="msie") {
        if ( (this.engine=="gecko") || (this.engine="opera") || (this.engine="khtml") || (this.engine="mozold")) {
        // Non-IE Flash plug-in detection

        if (navigator.plugins && navigator.plugins.length) {
            x = navigator.plugins["Shockwave Flash"];
            if (x) {
                this.hasFlash = 2;
                if (x.description) {
                    y = x.description;
                    this.flashVersion = y.charAt(y.indexOf('.')-1);
                }
            } else {
                this.hasFlash = 1;
            }
            if (navigator.plugins["Shockwave Flash 2.0"]) {
                this.hasFlash = 2;
                this.hasFlash = 2;
            }
        } else if (navigator.mimeTypes && navigator.mimeTypes.length) {
            x = navigator.mimeTypes['application/x-shockwave-flash'];
            if (x && x.enabledPlugin) {
                this.hasFlash = 2;
            } else {
                this.hasFlash = 1;
            }
        }

   

  } else if (this.engine=="msie") {
      // IE flash detection.
       for(var i=7; i>0; i--) {
           try {
               var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
               this.flashVersion = i;
               break;
               //return;
           } catch(e) { }
       }

       if (this.flashVersion>0) {
           this.hasFlash=2
       } else {
           this.hasFlash=1
       }
   
   } else {
       this.hasFlash=0;
       this.flashVersion=0;
       
   }
}

// Return Gecko version
BrowserSniffer.prototype.getGeckoVersion = function() {
    return this.userAgent.match(/gecko\/([0-9]+)/)[1];
}

// Return MSIE version
BrowserSniffer.prototype.getMSIEVersion = function() {
    return this.userAgent.match(/msie\s(\d+(\.?\d)*)/)[1];
}

/* FOR INTERNAL USE ONLY. THIS FUNCTIONS ARE SUBJECT TO CHANGE, DON'T TRUST THEM */
// Is input empty?
BrowserSniffer.prototype.isEmpty = function(input) {
    return (input==null || input =="")
}

// Does this string contain a dot?
BrowserSniffer.prototype.hasDot = function(input) {
    return (input.search(/\./) == -1)
}
/* END OF FOR INTERNAL USE ONLY FUNCTIONS */