//
// JavaScript Browser Sniffer
//

var	browser	= new browserSniffer();

function browserSniffer()
{
    // convert all characters to lowercase to simplify testing
    this.agt=navigator.userAgent.toLowerCase();
    this.appVer = navigator.appVersion.toLowerCase();
//alert("agt=" + this.agt );
//alert("appVer=" + this.appVer );

    // *** BROWSER VERSION ***

    this.is_minor = parseFloat(this.appVer);
    this.is_major = parseInt(this.is_minor);

    // 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

    this.iePos  = this.appVer.indexOf('msie');
    if (this.iePos !=-1) {
       this.is_minor = parseFloat(this.appVer.substring(this.iePos+5,this.appVer.indexOf(';',this.iePos)))
       this.is_major = parseInt(this.is_minor);
    }

    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_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.agt.indexOf('gecko/')!=-1) && 
                    ((navigator.vendor=="")||(navigator.vendor=="Mozilla")||(navigator.vendor=="Firefox")||(navigator.vendor=="Safari")));
    if (this.is_moz) {
       this.is_gver = (navigator.productSub)?navigator.productSub:0;
       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_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_moz)));

    // 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   
    // this.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_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_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_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_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);

// 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_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));

    // end new
	
    // *** JAVASCRIPT VERSION CHECK ***
    // Useful to workaround Nav3 bug in which Nav3
    // loads <SCRIPT LANGUAGE="JavaScript1.2">.
    // updated 020131 by dragle
    this.is_js = "Undefined";
    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_opera5up) this.is_js = 1.3; // 020214 - 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;
    
    // 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

	// Javascript Versions
    this.is_js10	= (this.is_js == 1.0) ? "true":"false";
    this.is_js10up	= (this.is_js >= 1.0) ? "true":"false";
    this.is_js11	= (this.is_js == 1.1) ? "true":"false";
    this.is_js11up	= (this.is_js >= 1.1) ? "true":"false";
    this.is_js12	= (this.is_js == 1.2) ? "true":"false";
    this.is_js12up	= (this.is_js >= 1.2) ? "true":"false";
    this.is_js13	= (this.is_js == 1.3) ? "true":"false";
    this.is_js13up	= (this.is_js >= 1.3) ? "true":"false";
    this.is_js14	= (this.is_js == 1.4) ? "true":"false";
    this.is_js14up	= (this.is_js >= 1.4) ? "true":"false";
    this.is_js15	= (this.is_js == 1.5) ? "true":"false";
    this.is_js15up	= (this.is_js >= 1.5) ? "true":"false";
    this.is_js16	= (this.is_js == 1.6) ? "true":"false";
    this.is_js16up	= (this.is_js >= 1.6) ? "true":"false";
    
    // 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

    // 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);
    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_sun4  = (this.agt.indexOf("sunos 4")!=-1);
    this.is_sun5  = (this.agt.indexOf("sunos 5")!=-1);
    this.is_sun6  = (this.agt.indexOf("sunos 6")!=-1);
    this.is_sun7  = (this.agt.indexOf("sunos 7")!=-1);
    this.is_sun8  = (this.agt.indexOf("sunos 8")!=-1);
    this.is_suni86= (this.is_sun && (this.agt.indexOf("i86")!=-1));
    this.is_irix  = (this.agt.indexOf("irix") !=-1);    // SGI
    this.is_irix5 = (this.agt.indexOf("irix 5") !=-1);
    this.is_irix6 = ((this.agt.indexOf("irix 6") !=-1) || (this.agt.indexOf("irix6") !=-1));
    this.is_hpux  = (this.agt.indexOf("hp-ux")!=-1);
    this.is_hpux9 = (this.is_hpux && (this.agt.indexOf("09.")!=-1));
    this.is_hpux10= (this.is_hpux && (this.agt.indexOf("10.")!=-1));
    this.is_hpux11= (this.is_hpux && (this.agt.indexOf("11.")!=-1));
    this.is_aix   = (this.agt.indexOf("aix") !=-1);      // IBM
    this.is_aix1  = (this.agt.indexOf("aix 1") !=-1);
    this.is_aix2  = (this.agt.indexOf("aix 2") !=-1);
    this.is_aix3  = (this.agt.indexOf("aix 3") !=-1);
    this.is_aix4  = (this.agt.indexOf("aix 4") !=-1);
    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="COOKIE_TEST=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());

	this.platform	= navigator.platform;
	this.name		= navigator.appName;

// ------------------------------------------------------------------------
//	final test for Mozilla
// ------------------------------------------------------------------------

	if ( this.is_moz )
	{
		this.name	= "Mozilla";	// override from Netscape
	}

// ------------------------------------------------------------------------
//	determine what is supported
// ------------------------------------------------------------------------

	this.supported_ie	= false;
	this.supported_nav	= false;
	this.supports_div	= false;
	if ( this.is_ie6up )
	{
		this.supported_ie	= true;
		this.supported_nav	= false;
	}
	else if ( this.is_nav6up || this.is_moz )
	{
		this.supported_ie	= false;
		this.supported_nav	= true;
	}
	if ( this.is_ie		||
		this.is_ie6up	||
		this.is_nav6	||
		this.is_nav6up	||
		this.is_moz )
	{
		this.supports_div	= true;
	}

	return ( this );
}

