// Ultimate client-side JavaScript client sniff.
// (C) Netscape Communications 1999.  Permission granted to reuse and distribute.
// Revised 7 May 99 to add is.nav5up and is.ie5up (see below). (see below).

// *** Modified under the simpler name "browser.js" by 
// *** Michel Bottin mailto:michel.bottin@culture.fr
// *** Change of constructor "Is" to "Browser" and object "is" to "browser"	

//  feb 2005 added suupport for konqueeror and safari 
//  
//


// Everything you always wanted to know about your JavaScript client
// but were afraid to ask ... "Browser" is the constructor function for "browser" object,
// which has properties indicating:
// (1) browser vendor:
//     browser.moz, browser.nav, browser.ie, browser.opera
// (2) browser version number:
//     browser.major (integer indicating major version number: 2, 3, 4 ...)
//     browser.minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
// (3) browser vendor AND major version number
//     browser.moz, browser.gecko,
//     browser.nav2, browser.nav3, browser.nav4, browser.nav4up, browser.nav6, browser.nav6up,
//     browser.ie3, browser.ie4, browser.ie4up, browser.ie5, browser.ie5up
// (4) JavaScript version number:
//     browser.js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
// (5) OS platform and version:
//     browser.win, browser.win16, browser.win32, browser.win31, browser.win95, browser.win98
//     browser.winnt
//     browser.os2,
//     browser.mac, browser.mac68k, browser.macppc
//     browser.unix
//        browser.sun, browser.sun4, browser.sun5, browser.suni86
//        browser.irix, browser.irix5, browser.irix6
//        browser.hpux, browser.hpux9, browser.hpux10
//        browser.aix, browser.aix1, browser.aix2, browser.aix3, browser.aix4
//        browser.linux, browser.sco, browser.unixware, browser.mpras, browser.reliant
//        browser.dec, browser.sinix, browser.freebsd, browser.bsd
//     browser.vms
//
// See http://www.it97.de/JavaScript/JS_tutorial/bstat/navobj.html and
// http://www.it97.de/JavaScript/JS_tutorial/bstat/Browseraol.html
// for detailed lists of userAgent strings.

//
// Note: you don't want your Nav4 or IE4 code to "turn off" or
// stop working when Nav5 and IE5 (or later) are released, so
// in conditional code forks, use client.nav4up ("Nav4 or greater")
// and client.ie4up ("IE4 or greater") instead of client.nav4 or client.ie4
// to check version in code which you want to work on future
// versions.

function versionNumber_(str) {
  var c, d = true, l = str.length, s = '';
	for (var i=0; i<l; i++) {
	  c = str.substr(i, 1);
		if (d && c == '.') { 
		  s += c; 
			d = false; 
		} else if (c != '.') {
		         if (c<'0' || c>'9') break;
		         else s += c;
					 }
//		alert (c + '\n' + s); 	  
	}
	return parseFloat(s);
}

function Browser () {   

    
	// convert all characters to lowercase to simplify testing
	var n = navigator;
	var ua = ' ' + n.userAgent.toLowerCase();
	var av  = n.appVersion.toLowerCase();
	var vendor = (n.vendor) ? n.vendor.toLowerCase(): '???';
	// *** BROWSER VERSION ***
	this.minor = parseFloat(av);
	var c, p, i, d, l, s;
	// Netscape 6.2.1: Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1
	// Mozilla  0.9.7:  Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.7) Gecko/20011221
  p = ua.indexOf('gecko')
	if (p > 0) {
    this.gecko = true;
		p = ua.indexOf('netscape6');
	  if (p > 0) this.minor = versionNumber_(ua.substring(p+10))
		else {
		  p = ua.indexOf('rv:');
			this.minor = versionNumber_(ua.substring(p+3));
		}
	}
	this.name = "???";
	this.platform = "???";
	// On IE this return 3 or 4 as version of supposedly corresponding version of Netscape.
	// We try to detect the real version
	p = av.indexOf('msie')
	if (p > 0) this.minor = parseFloat(av.substring(p+5,av.indexOf(';',p)));
	// On NS6 it is always Mozilla 5. Same effort as above
	p = ua.indexOf('netscape6');
	if (p > 0) this.minor = parseFloat(ua.substring(p+10));
	// iCab: Mozilla/4.5 (compatible; iCab Pre2.4; Macintosh; I; PPC)
	var p = ua.indexOf('iCab Pre');
	if (p > 0) this.minor = parseFloat(ua.substring(p+8,av.indexOf(p+8,av.indexOf(';'))));
	// In all cases major is the integral part of minor
	this.major = parseInt(this.minor);
	// Netscape Navigator
	this.nav  = ((ua.indexOf('mozilla')!=-1) && (ua.indexOf('spoofer')==-1)
	            && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)
	            && (ua.indexOf('webtv')==-1));
	this.nav2 = (this.nav && (this.major == 2));
	this.nav3 = (this.nav && (this.major == 3));
	this.nav4 = (this.nav && (this.major == 4));
	this.nav4up = (this.nav && (this.major >= 4));
	this.navonly  = (this.nav && ((ua.indexOf(";nav") != -1) ||
	                 (ua.indexOf("; nav") != -1)) );
	this.nav6 = (this.nav && (this.major == 6));
	this.nav6up = (this.nav && (this.major >= 6));
	if (this.nav) this.name = "Netscape";
	// Mozilla (from mozilla.org, not the Netscape version)
	this.moz = this.gecko && !this.nav6;
	if (this.moz) this.name = "Mozilla";
	/*
	if (this.moz) {this.nav6=true; this.nav6up=true; 
									this.mozMajor=this.major; this.mozMinor=this.minor;
									this.major=6; this.minor=6.0}
	else {this.mozMajor = 0; this.mozMinor = 0};
	*/
	// konqueror
	this.konqueror  = (ua.indexOf('konqueror')!=-1);
	if (this.konqueror)
	 { 
	   var tmp = ua.substring( ua.indexOf('konqueror')+10,ua.length);
	   this.major = parseInt(tmp);
	   tmp = tmp.substring( tmp.charAt('.')+2,tmp.charAt(' '));
	   this.minor = parseInt(tmp);
	 }
	
	
	// Safari
	this.safari  = (ua.indexOf('safari')!=-1);
	if (this.safari)
	 { var tmp = ua.substring( ua.indexOf('safari')+7,ua.length);
	  
	   this.major = parseInt(tmp);
	   tmp = tmp.substring( tmp.charAt('.')+1,tmp.length);

	   this.minor = parseInt(tmp);
	 }
	 
	
	// Microsoft Internet Microsoft
  this.ie   = (ua.indexOf('msie') != -1);
	this.ie3  = (this.ie && this.major < 4);
	this.ie4  = (this.ie && this.major == 4);
	this.ie4up  = (this.ie  && this.major >= 4);
	this.ie5  = (this.ie && this.major == 5) ;
	this.ie5up  = (this.ie  && this.major >= 5);
	if (this.ie) this.name = "Internet Explorer";
	// AOL
	this.aol   = (ua.indexOf("aol") != -1);
	this.aol3  = (this.aol && this.ie3);
	this.aol4  = (this.aol && this.ie4);
	if (this.AOL) this.name = 'AOL'
	// iCab
	this.icab = (ua.indexOf('icab') != -1);
	this.icab2 = (this.icab && this.major == 2);
	if (this.icab) this.name = 'iCab';
	// Opera
	this.opera = (ua.indexOf("opera") != -1);
	if (this.opera) this.name = "Opera";
	// WebTV
  this.webtv = (ua.indexOf("webtv") != -1);
	if (this.webtv) this.name = "WebTV";
	// *** JAVASCRIPT VERSION CHECK ***
	// Useful to workaround Nav3 bug in which Nav3
	// loads <SCRIPT LANGUAGE="JavaScript1.2">
	if (this.nav2 || this.ie3) this.js = 1.0
	else if (this.nav3 || this.opera) this.js = 1.1
	else if ((this.nav4 && (this.minor <= 4.05)) || this.ie4) this.js = 1.2
	else if ((this.nav4 && (this.minor > 4.05)) || this.ie5) this.js = 1.3
	else if (this.nav5) this.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.nav && (this.major > 5)) this.js = 1.5
	else if (this.ie && (this.major > 5)) this.js = 1.3
	// HACK: no idea for other browsers; always check for JS version with > or >=
	else this.js = 0.0;

	// *** PLATFORM ***
	this.win   = ( (ua.indexOf("win")!=-1) || (ua.indexOf("16bit")!=-1) );
	if (this.win) this.platform = "Windows";
	// 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.win95 = ((ua.indexOf("win95")!=-1) || (ua.indexOf("windows 95")!=-1));

	// is this a 16 bit compiled version?
	this.win16 = ((ua.indexOf("win16")!=-1) ||
	              (ua.indexOf("16bit")!=-1) || (ua.indexOf("windows 3.1")!=-1) ||
	              (ua.indexOf("windows 16-bit")!=-1) );

	this.win31 = ((ua.indexOf("windows 3.1")!=-1) || (ua.indexOf("win16")!=-1) ||
	              (ua.indexOf("windows 16-bit")!=-1));

	// 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.win98 = ((ua.indexOf("win98")!=-1) || (ua.indexOf("windows 98")!=-1));
	this.winnt = ((ua.indexOf("winnt")!=-1) || (ua.indexOf("windows nt")!=-1));
	this.win32 = ( this.win95 || this.winnt || this.win98 ||
	               ((this.major >= 4) && (n.platform == "Win32")) ||
	               (ua.indexOf("win32")!=-1) || (ua.indexOf("32bit")!=-1) );

	this.os2   = ((ua.indexOf("os/2")!=-1) ||
	              (n.appVersion.indexOf("OS/2")!=-1) ||
	              (ua.indexOf("ibm-webexplorer")!=-1));
  if (this.os2) this.platform = "OS2";

	this.mac    = (ua.indexOf("mac")!=-1);
	if (this.mac) this.platform = "Macintosh";
	this.mac68k = (this.mac && ((ua.indexOf("68k")!=-1) ||
	                           (ua.indexOf("68000")!=-1)));
	this.macppc = (this.mac && ((ua.indexOf("ppc")!=-1) ||
	                           (ua.indexOf("powerpc")!=-1)));

	this.sun   = (ua.indexOf("sunos")!=-1);
	this.sun4  = (ua.indexOf("sunos 4")!=-1);
	this.sun5  = (ua.indexOf("sunos 5")!=-1);
	this.suni86= (this.sun && (ua.indexOf("i86")!=-1));
	this.irix  = (ua.indexOf("irix") !=-1);    // SGI
	this.irix5 = (ua.indexOf("irix 5") !=-1);
	this.irix6 = ((ua.indexOf("irix 6") !=-1) || (ua.indexOf("irix6") !=-1));
	this.hpux  = (ua.indexOf("hp-ux")!=-1);
	this.hpux9 = (this.hpux && (ua.indexOf("09.")!=-1));
	this.hpux10= (this.hpux && (ua.indexOf("10.")!=-1));
	this.aix   = (ua.indexOf("aix") !=-1);      // IBM
	this.aix1  = (ua.indexOf("aix 1") !=-1);
	this.aix2  = (ua.indexOf("aix 2") !=-1);
	this.aix3  = (ua.indexOf("aix 3") !=-1);
	this.aix4  = (ua.indexOf("aix 4") !=-1);
	this.linux = (ua.indexOf("linux")!=-1);
	this.sco   = (ua.indexOf("sco")!=-1) || (ua.indexOf("unix_sv")!=-1);
	this.unixware = (ua.indexOf("unix_system_v")!=-1);
	this.mpras    = (ua.indexOf("ncr")!=-1);
	this.reliant  = (ua.indexOf("reliantunix")!=-1);
	this.dec   = ((ua.indexOf("dec")!=-1) || (ua.indexOf("osf1")!=-1) ||
	     (ua.indexOf("dec_alpha")!=-1) || (ua.indexOf("alphaserver")!=-1) ||
	     (ua.indexOf("ultrix")!=-1) || (ua.indexOf("alphastation")!=-1));
	this.sinix = (ua.indexOf("sinix")!=-1);
	this.freebsd = (ua.indexOf("freebsd")!=-1);
	this.bsd = (ua.indexOf("bsd")!=-1);
	this.unix  = ((ua.indexOf("x11")!=-1) || this.sun || this.irix || this.hpux ||
	             this.sco ||this.unixware || this.mpras || this.reliant ||
	             this.dec || this.sinix || this.aix || this.linux || this.bsd || this.freebsd);
  if (this.unix) this.name = "Unix";
	if (this.linux) this.platform = "Linux";
	this.vms   = ((ua.indexOf("vax")!=-1) || (ua.indexOf("openvms")!=-1));
	if (this.vms) this.platform = "VMS";
}

var browser;
var browserIE3Mac = false;
// this section is designed specifically for IE3 for the Mac

if ((navigator.appVersion.indexOf("Mac")!=-1) && (navigator.userAgent.indexOf("MSIE")!=-1) && 
(parseInt(navigator.appVersion)==3))
       browserIE3Mac = true;
else   browser = new Browser(); 
