// JavaScript Browser Sniffer
// Eric Krok, Andy King, Michel Plungjan Jan. 31, 2002
// see http://www.webreference.com/ for more information
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
// please send any improvements to aking@internet.com and we'll
// roll the best ones in
//
// (1) browser vendor:
//     is_nav, is_ie, is_opera
// (2) browser version number:
//     is_major (integer indicating major version number: 2, 3, 4 ...)
//     is_minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
// (3) browser vendor AND major version number
//     is_nav2, is_nav3, is_nav4, is_nav4up, is_nav5, is_nav5up, 
//     is_nav6, is_nav6up, is_ie3, is_ie4, is_ie4up, is_ie5up, is_ie6...
// (4) JavaScript version number:
//     is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
// (5) OS platform and version:
//     is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98
//     is_os2
//     is_mac, is_mac68k, is_macppc
//     is_unix
//        is_sun, is_sun4, is_sun5, is_suni86
//        is_irix, is_irix5, is_irix6
//        is_hpux, is_hpux9, is_hpux10
//        is_aix, is_aix1, is_aix2, is_aix3, is_aix4
//        is_linux, is_sco, is_unixware, is_mpras, is_reliant
//        is_dec, is_sinix, is_freebsd, is_bsd
//     is_vms
//
// based in part on 
// http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
// The Ultimate JavaScript Client Sniffer
// and Andy King's object detection sniffer
//
function Platform() 
{
    // convert all characters to lowercase to simplify testing
    this.agt = navigator.userAgent.toLowerCase();
    this.appVer = navigator.appVersion.toLowerCase();

    // *** BROWSER VERSION ***

    this.is_minor = parseFloat(this.appVer);
    this.is_major = parseInt(this.is_minor);

    this.is_opera = (this.agt.indexOf("opera") != -1);
    this.is_opera2 = (this.agt.indexOf("opera 2") != -1 || this.agt.indexOf("opera/2") != -1);
    this.is_opera3 = (this.agt.indexOf("opera 3") != -1 || this.agt.indexOf("opera/3") != -1);
    this.is_opera4 = (this.agt.indexOf("opera 4") != -1 || this.agt.indexOf("opera/4") != -1);
    this.is_opera5 = (this.agt.indexOf("opera 5") != -1 || this.agt.indexOf("opera/5") != -1);
    this.is_opera6 = (this.agt.indexOf("opera 6") != -1 || this.agt.indexOf("opera/6") != -1); // new 020128- abk
    this.is_opera7 = (this.agt.indexOf("opera 7") != -1 || this.agt.indexOf("opera/7") != -1); // new 021205- dmr
    this.is_opera5up = (this.is_opera && !this.is_opera2 && !this.is_opera3 && !this.is_opera4);
    this.is_opera6up = (this.is_opera && !this.is_opera2 && !this.is_opera3 && !this.is_opera4 && !this.is_opera5); // new020128
    this.is_opera7up = (this.is_opera && !this.is_opera2 && !this.is_opera3 && !this.is_opera4 && !this.is_opera5 && !this.is_opera6); // new021205 -- dmr

    // Note: On IE, start of appVersion return 3 or 4
    // which supposedly is the version of Netscape it is compatible with.
    // So we look for the real version further on in the string
    // And on Mac IE5+, we look for is_minor in the ua; since 
    // it appears to be more accurate than appVersion - 06/17/2004

    this.is_mac = (this.agt.indexOf("mac")!=-1);
    this.iePos  = this.appVer.indexOf('msie');
    if (this.iePos !=-1) {
       if(this.is_mac) {
           this.iePos = this.agt.indexOf('msie');
           this.is_minor = parseFloat(this.agt.substring(this.iePos+5,this.agt.indexOf(';',this.iePos)));
       }
       else this.is_minor = parseFloat(this.appVer.substring(this.iePos+5,this.appVer.indexOf(';',this.iePos)));
       this.is_major = parseInt(this.is_minor);
    }

    this.is_konq = false;

    this.is_getElementById   = (document.getElementById) ? "true" : "false"; // 001121-abk
    this.is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false"; // 001127-abk
    this.is_documentElement = (document.documentElement) ? "true" : "false"; // 001121-abk

    this.is_safari = ((this.agt.indexOf('safari')!=-1)&&(this.agt.indexOf('mac')!=-1))?true:false;
    this.is_khtml  = (this.is_safari || this.is_konq);

    this.is_gecko = ((!this.is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
    this.is_gver  = 0;
    if (this.is_gecko) this.is_gver=navigator.productSub;

    this.is_moz   = ((this.agt.indexOf('mozilla/5')!=-1) && (this.agt.indexOf('spoofer')==-1) &&
                    (this.agt.indexOf('compatible')==-1) && (this.agt.indexOf('opera')==-1)  &&
                    (this.agt.indexOf('webtv')==-1) && (this.agt.indexOf('hotjava')==-1)     &&
                    (this.is_gecko) && 
                    ((navigator.vendor=="")||(navigator.vendor=="Mozilla")||(navigator.vendor=="Debian")||(navigator.vendor=="Fedora")));
    this.is_fb = ((this.agt.indexOf('mozilla/5')!=-1) && (this.agt.indexOf('spoofer')==-1) &&
                 (this.agt.indexOf('compatible')==-1) && (this.agt.indexOf('opera')==-1)  &&
                 (this.agt.indexOf('webtv')==-1) && (this.agt.indexOf('hotjava')==-1)     &&
                 (this.is_gecko) && (navigator.vendor=="Firebird"));
    this.is_fx = ((this.agt.indexOf('mozilla/5')!=-1) && (this.agt.indexOf('spoofer')==-1) &&
                 (this.agt.indexOf('compatible')==-1) && (this.agt.indexOf('opera')==-1)  &&
                 (this.agt.indexOf('webtv')==-1) && (this.agt.indexOf('hotjava')==-1)     &&
                 (this.is_gecko) && (navigator.vendor=="Firefox"||navigator.vendor=="Fedora"||navigator.vendor=="Camino"));
    if (this.agt.indexOf("firefox/") != -1 && this.is_moz && navigator.vendor != "Firefox")
    {
		this.is_fx = true;
		var fxPos = this.agt.indexOf("firefox/");
		var fxVer = this.agt.substr(fxPos+8,3);
		this.is_minor = parseFloat(fxVer);
		this.is_major = parseInt(fxVer);
		this.is_moz_ver = fxVer
    }
    else if ((this.is_moz)||(this.is_fb)||(this.is_fx)) {  // 032504 - dmr
       this.is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
       if(!(this.is_moz_ver)) {
           this.is_moz_ver = this.agt.indexOf('rv:');
           this.is_moz_ver = this.agt.substring(this.is_moz_ver+3);
           this.is_paren   = this.is_moz_ver.indexOf(')');
           this.is_moz_ver = this.is_moz_ver.substring(0,this.is_paren);
       }
       this.is_minor = this.is_moz_ver;
       this.is_major = parseInt(this.is_moz_ver);
    }
    
   this.is_fb_ver = this.is_moz_ver;
   this.is_fx_ver = this.is_moz_ver;
   
   this.is_nav  = ((this.agt.indexOf('mozilla')!=-1) && (this.agt.indexOf('spoofer')==-1)
                && (this.agt.indexOf('compatible') == -1) && (this.agt.indexOf('opera')==-1)
                && (this.agt.indexOf('webtv')==-1) && (this.agt.indexOf('hotjava')==-1)
                && (!this.is_khtml) && (!(this.is_moz)) && (!this.is_fb) && (!this.is_fx));

    // Netscape6 is mozilla/5 + Netscape6/6.0!!!
    // Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
    // Changed this to use navigator.vendor/vendorSub - dmr 060502   
    // var nav6Pos = this.agt.indexOf('netscape6');
    // if (nav6Pos !=-1) {
    if ((navigator.vendor)&&
        ((navigator.vendor=="Netscape6")||(navigator.vendor=="Netscape"))&&
        (this.is_nav)) {
       this.is_major = parseInt(navigator.vendorSub);
       // here we need is_minor as a valid float for testing. We'll
       // revert to the actual content before printing the result. 
       this.is_minor = parseFloat(navigator.vendorSub);
    }

    this.is_nav2 = (this.is_nav && (this.is_major == 2));
    this.is_nav3 = (this.is_nav && (this.is_major == 3));
    this.is_nav4 = (this.is_nav && (this.is_major == 4));
    this.is_nav4up = (this.is_nav && this.is_minor >= 4);  // changed to is_minor for
                                                // consistency - dmr, 011001
    this.is_navonly      = (this.is_nav && ((this.agt.indexOf(";nav") != -1) ||
                          (this.agt.indexOf("; nav") != -1)) );

    this.is_nav6   = (this.is_nav && this.is_major==6);    // new 010118 mhp
    this.is_nav6up = (this.is_nav && this.is_minor >= 6); // new 010118 mhp

    this.is_nav5   = (this.is_nav && this.is_major == 5 && !this.is_nav6); // checked for ns6
    this.is_nav5up = (this.is_nav && this.is_minor >= 5);

    this.is_nav7   = (this.is_nav && this.is_major == 7);
    this.is_nav7up = (this.is_nav && this.is_minor >= 7);

    this.is_ie   = ((this.iePos!=-1) && (!this.is_opera) && (!this.is_khtml));
    this.is_ie3  = (this.is_ie && (this.is_major < 4));

    this.is_ie4   = (this.is_ie && this.is_major == 4);
    this.is_ie4up = (this.is_ie && this.is_minor >= 4);
    this.is_ie5   = (this.is_ie && this.is_major == 5);
    this.is_ie5up = (this.is_ie && this.is_minor >= 5);
    
    this.is_ie5_5  = (this.is_ie && (this.agt.indexOf("msie 5.5") !=-1)); // 020128 new - abk
    this.is_ie5_5up =(this.is_ie && this.is_minor >= 5.5);                // 020128 new - abk
	
    this.is_ie6   = (this.is_ie && this.is_major == 6);
    this.is_ie6up = (this.is_ie && this.is_minor >= 6);

    this.is_ie7   = (this.is_ie && this.is_major == 7);
    this.is_ie7up = (this.is_ie && this.is_minor >= 7);

	// netscape 8 in ie mode
    if(!this.is_nav && this.agt.indexOf("netscape/") > 0) {
        var n8 = this.agt.indexOf("netscape/");
        this.is_minor = parseFloat(this.agt.substr(n8+9));
    }
    this.is_nav8up = (this.agt.indexOf("netscape/") > 0 && this.is_minor >= 8);

	// KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    
    this.is_aol   = (this.agt.indexOf("aol") != -1);
    this.is_aol3  = (this.is_aol && this.is_ie3);
    this.is_aol4  = (this.is_aol && this.is_ie4);
    this.is_aol5  = (this.agt.indexOf("aol 5") != -1);
    this.is_aol6  = (this.agt.indexOf("aol 6") != -1);
    this.is_aol7  = ((this.agt.indexOf("aol 7")!=-1) || (this.agt.indexOf("aol7")!=-1));
    this.is_aol8  = ((this.agt.indexOf("aol 8")!=-1) || (this.agt.indexOf("aol8")!=-1));

    this.is_webtv = (this.agt.indexOf("webtv") != -1);
    
    // new 020128 - abk
    
    this.is_TVNavigator = ((this.agt.indexOf("navio") != -1) || (this.agt.indexOf("navio_aoltv") != -1)); 
    this.is_AOLTV = this.is_TVNavigator;

    this.is_hotjava = (this.agt.indexOf("hotjava") != -1);
    this.is_hotjava3 = (this.is_hotjava && (this.is_major == 3));
    this.is_hotjava3up = (this.is_hotjava && (this.is_major >= 3));

    this.is_chrome = (this.agt.indexOf("chrome/") != -1);

    // end new
	
    // *** JAVASCRIPT VERSION CHECK ***
    // Useful to workaround Nav3 bug in which Nav3
    // loads <SCRIPT LANGUAGE="JavaScript1.2">.
    // updated 020131 by dragle
    if (this.is_nav2 || this.is_ie3) this.is_js = 1.0;
    else if (this.is_nav3) this.is_js = 1.1;
    else if ((this.is_opera5)||(this.is_opera6)) this.is_js = 1.3; // 020214 - dmr
    else if (this.is_opera7up) this.is_js = 1.5; // 031010 - dmr
    else if (this.is_khtml) this.is_js = 1.5;   // 030110 - dmr
    else if (this.is_opera) this.is_js = 1.1;
    else if ((this.is_nav4 && (this.is_minor <= 4.05)) || this.is_ie4) this.is_js = 1.2;
    else if ((this.is_nav4 && (this.is_minor > 4.05)) || this.is_ie5) this.is_js = 1.3;
    else if (this.is_nav5 && !(this.is_nav6)) this.is_js = 1.4;
    else if (this.is_hotjava3up) this.is_js = 1.4; // new 020128 - abk
    else if (this.is_nav6up) this.is_js = 1.5;

    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.

    else if (this.is_nav && (this.is_major > 5)) this.is_js = 1.4;
    else if (this.is_ie && (this.is_major > 5)) this.is_js = 1.3;
    else if (this.is_moz) this.is_js = 1.5;
    else if (this.is_fb||this.is_fx) this.is_js = 1.5; // 032504 - dmr
    
    // what about ie6 and ie6up for js version? abk
    
    // HACK: no idea for other browsers; always check for JS version 
    // with > or >=
    else this.is_js = 0.0;
    // HACK FOR IE5 MAC = js vers = 1.4 (if put inside if/else jumps out at 1.3)
    if ((this.agt.indexOf("mac")!=-1) && this.is_ie5up) this.is_js = 1.4; // 020128 - abk
    
    // Done with is_minor testing; revert to real for N6/7
    if (this.is_nav6up) {
       this.is_minor = navigator.vendorSub;
    }

    // *** PLATFORM ***
    this.is_win   = ( (this.agt.indexOf("win")!=-1) || (this.agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    this.is_win95 = ((this.agt.indexOf("win95")!=-1) || (this.agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    this.is_win16 = ((this.agt.indexOf("win16")!=-1) ||
               (this.agt.indexOf("16bit")!=-1) || (this.agt.indexOf("windows 3.1")!=-1) ||
               (this.agt.indexOf("windows 16-bit")!=-1) );

    this.is_win31 = ((this.agt.indexOf("windows 3.1")!=-1) || (this.agt.indexOf("win16")!=-1) ||
                    (this.agt.indexOf("windows 16-bit")!=-1));
	
	this.is_winme = ((this.agt.indexOf("win 9x 4.90")!=-1));    // new 020128 - abk
    this.is_win2k = ((this.agt.indexOf("windows nt 5.0")!=-1) || (this.agt.indexOf("windows 2000")!=-1)); // 020214 - dmr
    this.is_winxp = ((this.agt.indexOf("windows nt 5.1")!=-1) || (this.agt.indexOf("windows xp")!=-1)); // 020214 - dmr
    this.is_winxp64 = ((this.agt.indexOf("windows nt 5.2")!=-1)); // 100105 - mgc
    this.is_winvista = ((this.agt.indexOf("windows nt 6.0")!=-1) || (this.agt.indexOf("windows vista")!=-1)); // 020214 - dmr
    this.is_win7 = ((this.agt.indexOf("windows nt 6.1")!=-1) || (this.agt.indexOf("windows 7")!=-1)); // 100105 - mgc

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    this.is_win98 = ((this.agt.indexOf("win98")!=-1) || (this.agt.indexOf("windows 98")!=-1));
    this.is_winnt = ((this.agt.indexOf("winnt")!=-1) || (this.agt.indexOf("windows nt")!=-1));
    this.is_win32 = (this.is_win95 || this.is_winnt || this.is_win98 ||
                    ((this.is_major >= 4) && (navigator.platform == "Win32")) ||
                    (this.agt.indexOf("win32")!=-1) || (this.agt.indexOf("32bit")!=-1));

    this.is_os2   = ((this.agt.indexOf("os/2")!=-1) ||
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||
                    (this.agt.indexOf("ibm-webexplorer")!=-1));

    this.is_mac    = (this.agt.indexOf("mac")!=-1);
    if (this.is_mac) { this.is_win = !this.is_mac; } // dmr - 06/20/2002
    this.is_mac68k = (this.is_mac && ((this.agt.indexOf("68k")!=-1) ||
                               (this.agt.indexOf("68000")!=-1)));
    this.is_macppc = (this.is_mac && ((this.agt.indexOf("ppc")!=-1) ||
                                (this.agt.indexOf("powerpc")!=-1)));

    this.is_sun   = (this.agt.indexOf("sunos")!=-1);
    this.is_irix  = (this.agt.indexOf("irix") !=-1);    // SGI
    this.is_hpux  = (this.agt.indexOf("hp-ux")!=-1);
    this.is_aix   = (this.agt.indexOf("aix") !=-1);      // IBM
    this.is_linux = (this.agt.indexOf("inux")!=-1);
    this.is_sco   = (this.agt.indexOf("sco")!=-1) || (this.agt.indexOf("unix_sv")!=-1);
    this.is_unixware = (this.agt.indexOf("unix_system_v")!=-1);
    this.is_mpras    = (this.agt.indexOf("ncr")!=-1);
    this.is_reliant  = (this.agt.indexOf("reliantunix")!=-1);
    this.is_dec   = ((this.agt.indexOf("dec")!=-1) || (this.agt.indexOf("osf1")!=-1) ||
           (this.agt.indexOf("dec_alpha")!=-1) || (this.agt.indexOf("alphaserver")!=-1) ||
           (this.agt.indexOf("ultrix")!=-1) || (this.agt.indexOf("alphastation")!=-1));
    this.is_sinix = (this.agt.indexOf("sinix")!=-1);
    this.is_freebsd = (this.agt.indexOf("freebsd")!=-1);
    this.is_bsd = (this.agt.indexOf("bsd")!=-1);
    this.is_unix  = ((this.agt.indexOf("x11")!=-1) || this.is_sun || this.is_irix || this.is_hpux ||
                 this.is_sco ||this.is_unixware || this.is_mpras || this.is_reliant ||
                 this.is_dec || this.is_sinix || this.is_aix || this.is_linux || this.is_bsd || this.is_freebsd);

    this.is_vms   = ((this.agt.indexOf("vax")!=-1) || (this.agt.indexOf("openvms")!=-1));
// additional checks, abk
	this.is_anchors = (document.anchors) ? "true":"false";
	this.is_regexp = (window.RegExp) ? "true":"false";
	this.is_option = (window.Option) ? "true":"false";
	this.is_all = (document.all) ? "true":"false";
// cookies - 990624 - abk
	document.cookie = "cookies=true";
	this.is_cookie = (document.cookie) ? "true" : "false";
	this.is_images = (document.images) ? "true":"false";
	this.is_layers = (document.layers) ? "true":"false"; // gecko m7 bug?
// new doc obj tests 990624-abk
	this.is_forms = (document.forms) ? "true" : "false";
	this.is_links = (document.links) ? "true" : "false";
	this.is_frames = (window.frames) ? "true" : "false";
	this.is_screen = (window.screen) ? "true" : "false";

// java
	this.is_java = (navigator.javaEnabled());
}

var usrPlatform = new Platform();

// for now, support only the following browsers:
// ie 5.5+, nav 7.0+, ffox 1.0+, safari

var doRedirect = true;
if (self.location.href.toLowerCase().indexOf("/sys/help/syscheck.asp") != -1)
	doRedirect = false;

with (usrPlatform)
{
	if (!(is_ie5_5up || is_nav7up || (is_fx && is_major >= 1) || is_safari || is_chrome) )
		if (doRedirect) self.location.href = "/sys/help/info.asp?m=browser";
}
