/**
---------------------------- COPYRIGHT NOTICE --------------------------
 Copyright (C) 2003 eSchool Solutions, Inc.

 This source code software is the property of eSchool Solutions, Inc.
 Possession, use, replication, sale, distribution or the performance
 of any other acts involving this software without a license explicitly
 granted by eSchool Solutions, Inc. is illegal.
------------------------------------------------------------------------
**
** Name:    BrowserDetect.js
** Author:  eSchool Solutions
** Date:    07/18/2003
** Version: 1.0
**
** Adapted with permission from a script found at 
** http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
**
** Description:
** Gives information on browser vendor, browser version, JavaScript version, and client OS.
** Just include this script to get access to all of its variables
**/

// *** Preliminary checks ***
// convert all characters to lowercase to simplify testing
var agent = navigator.userAgent.toLowerCase();

// Get major/minor versions
// Note: On IE5, these return 4, so use isMSIE5AndUp to detect IE5.
var versionMajor = parseInt( navigator.appVersion );
var versionMinor = parseFloat( navigator.appVersion );

// *** Browser vendor checks ***
// Note: This does strict client detection, since Opera and WebTV claim to be NS.
// To be less strict, comment out the tests for opera and webtv.
var isNetscape = ( ( agent.indexOf( 'mozilla' ) != -1 ) && ( agent.indexOf( 'spoofer' ) == -1 ) &&
                    ( agent.indexOf( 'compatible' ) == -1 ) && ( agent.indexOf( 'opera' ) == -1 ) &&
                    ( agent.indexOf( 'webtv' ) == -1 ) && ( agent.indexOf( 'hotjava' ) == -1 ) );
var isNetscapeV2 = ( isNetscape && ( versionMajor == 2 ) );
var isNetscapeV3 = ( isNetscape && ( versionMajor == 3 ) );
var isNetscapeV4 = ( isNetscape && ( versionMajor == 4 ) );
var isNetscapeV4AndUp = ( isNetscape && ( versionMajor >= 4 ) );
var isNetscapeOnly = ( isNetscape && ( ( agent.indexOf( ";nav" ) != -1 ) ||
                                        ( agent.indexOf( "; nav" ) != -1) ) );
var isNetscapeV6 = ( isNetscape && ( versionMajor == 5 ) );
var isNetscapeV6AndUp = ( isNetscape && ( versionMajor >= 5 ) );
var isGecko = ( agent.indexOf( 'gecko' ) != -1 );

var isMSIE     = ( ( agent.indexOf( "msie" ) != -1 ) && ( agent.indexOf( "opera" ) == -1 ) );
var isMSIE3    = ( isMSIE && ( versionMajor < 4 ) );
var isMSIE4    = ( isMSIE && ( versionMajor == 4 ) && ( agent.indexOf( "msie 4" ) != -1 ) );
var isMSIE4AndUp  = ( isMSIE && ( versionMajor >= 4 ) );
var isMSIE5    = ( isMSIE && ( versionMajor == 4 ) && ( agent.indexOf( "msie 5.0" ) != -1 ) );
var isMSIE55  = ( isMSIE && ( versionMajor == 4 ) && ( agent.indexOf( "msie 5.5" ) != -1 ) );
var isMSIE5AndUp  = ( isMSIE && !isMSIE3 && !isMSIE4 );
var isMSIE55AndUp =( isMSIE && !isMSIE3 && !isMSIE4 && !isMSIE5 );
var isMSIE6    = ( isMSIE && ( versionMajor == 4 ) && ( agent.indexOf( "msie 6." ) != -1 ) );
var isMSIE6AndUp  = ( isMSIE && !isMSIE3 && !isMSIE4 && !isMSIE5 && !isMSIE55 );

// BUG: AOL4 returns false if IE3 is embedded browser or if this is the first browser window opened.  
// Thus the variables isAOL, isAOL3, and isAOL4 aren't 100% reliable.
var isAOL   = ( agent.indexOf( "aol" ) != -1 );
var isAOL3  = ( isAOL && isMSIE3 );
var isAOL4  = ( isAOL && isMSIE4 );
var isAOL5  = ( agent.indexOf( "aol 5" ) != -1 );
var isAOL6  = ( agent.indexOf( "aol 6" ) != -1 );

var isOpera = ( agent.indexOf( "opera") != -1 );
var isOpera2 = ( agent.indexOf( "opera 2" ) != -1 || agent.indexOf( "opera/2" ) != -1 );
var isOpera3 = ( agent.indexOf( "opera 3" ) != -1 || agent.indexOf( "opera/3" ) != -1 );
var isOpera4 = ( agent.indexOf( "opera 4" ) != -1 || agent.indexOf( "opera/4" ) != -1 );
var isOpera5 = ( agent.indexOf( "opera 5" ) != -1 || agent.indexOf( "opera/5" ) != -1 );
var isOpera5AndUp = ( isOpera && !isOpera2 && !isOpera3 && !isOpera4 );

var isWebTV = ( agent.indexOf( "webtv" ) != -1 ); 

var isTVNav = ( ( agent.indexOf( "navio" ) != -1 ) || ( agent.indexOf( "navio_aoltv" ) != -1 ) ); 
var isAOLTV = isTVNav;

var isHotJava = ( agent.indexOf( "hotjava" ) != -1 );
var isHotJava3 = ( isHotJava && ( versionMajor == 3 ) );
var isHotJava3AndUp = ( isHotJava && ( versionMajor >= 3 ) );

// *** JavaScript version check ***
var jsVersion;
if ( isNetscapeV2 || isMSIE3 ) jsVersion = 1.0;
else if ( isNetscapeV3 ) jsVersion = 1.1;
else if ( isOpera5AndUp ) jsVersion = 1.3;
else if ( isOpera ) jsVersion = 1.1;
else if ( ( isNetscapeV4 && ( versionMinor <= 4.05 ) ) || isMSIE4 ) jsVersion = 1.2;
else if ( ( isNetscapeV4 && ( versionMinor > 4.05 ) ) || isMSIE5 ) jsVersion = 1.3;
else if ( isHotJava3AndUp ) jsVersion = 1.4;
else if ( isNetscapeV6 || isGecko ) jsVersion = 1.5;
// NOTE: This code needs to be updated when newer versions of JS are released. 
// For now, 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 against jsVersion with > or >=.
else if ( isNetscapeV6AndUp ) jsVersion = 1.5;
// NOTE: MSIE5 on mac is JS v1.4
else if ( isMSIE5AndUp ) jsVersion = 1.3
// NOT: no idea for other browsers. always check for JS version with > or >=
else jsVersion = 0.0;

// *** Platform check ***
var isWin = ( ( agent.indexOf( "win" ) != -1 ) || ( agent.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.
var isWin95 = ( ( agent.indexOf( "win95" ) != -1 ) || ( agent.indexOf( "windows 95" ) != -1 ) );

// is this a 16 bit compiled version?
var isWin16 = ( ( agent.indexOf( "win16" ) != -1 ) || 
           ( agent.indexOf( "16bit" ) != -1 ) || ( agent.indexOf( "windows 3.1" ) != -1 ) || 
           ( agent.indexOf( "windows 16-bit" ) != -1 ) );  

var isWin31 = ( ( agent.indexOf( "windows 3.1" ) != -1 ) || ( agent.indexOf( "win16" ) != -1 ) ||
                ( agent.indexOf( "windows 16-bit" ) != -1 ) );

var isWinMe = ( ( agent.indexOf( "win 9x 4.90" ) != -1 ) );
var isWin2k = ( ( agent.indexOf( "windows nt 5.0" ) != -1 ) );

// NOTE: Reliable detection of Win98 may not be possible, sinceo n Nav 4.x and before 
// you'll get "Windows" in userAgent, and on Mercury client, the 32-bit version will 
// return "Win98", but the 16-bit version running on Win98 will still return "Win95".
var isWin98 = ( ( agent.indexOf( "win98" ) != -1 ) || ( agent.indexOf( "windows 98" ) != -1 ) );
var isWinNT = ( ( agent.indexOf( "winnt" ) != -1 ) || ( agent.indexOf( "windows nt" ) != -1 ) );
var isWin32 = ( isWin95 || isWinNT || isWin98 || 
                ( ( versionMajor >= 4) && ( navigator.platform == "Win32" ) ) ||
                ( agent.indexOf( "win32" ) != -1 ) || ( agent.indexOf( "32bit" ) != -1 ) );

var isOS2   = ( ( agent.indexOf( "os/2" ) != -1 ) || 
                ( navigator.appVersion.indexOf( "OS/2" ) != -1 ) ||   
                ( agent.indexOf( "ibm-webexplorer" ) != -1 ) );

var isMac    = ( agent.indexOf( "mac" ) != -1 );
// Hack IE5 js version for mac
if ( isMac && isMSIE5AndUp ) jsVersion = 1.4;
var isMac68k = ( isMac && ( ( agent.indexOf( "68k" ) != -1 ) || 
                           ( agent.indexOf( "68000" ) != -1 )));
var isMacPPC = ( isMac && ( ( agent.indexOf( "ppc" ) != -1 ) || 
                            ( agent.indexOf( "powerpc" ) != -1 ) ) );

var isSun   = ( agent.indexOf( "sunos" ) != -1 );
var isSun4  = ( agent.indexOf( "sunos 4" ) != -1 );
var isSun5  = ( agent.indexOf( "sunos 5" ) != -1);
var isSuni86= ( isSun && (agent.indexOf( "i86" ) != -1 ) );
var isIrix  = ( agent.indexOf( "irix" ) != -1 );    // SGI
var isIrix5 = ( agent.indexOf( "irix 5" ) != -1 );
var isIrix6 = ( ( agent.indexOf( "irix 6" ) != -1 ) || ( agent.indexOf( "irix6" ) != -1 ) );
var isHPUx  = ( agent.indexOf( "hp-ux" ) != -1 );
var isHPUx9 = ( isHPUx && ( agent.indexOf( "09." ) != -1 ) );
var isHPUx10= ( isHPUx && ( agent.indexOf( "10." ) != -1 ) );
var isAix   = ( agent.indexOf( "aix" ) != -1 );      // IBM
var isAix1  = ( agent.indexOf( "aix 1" ) != -1 );    
var isAix2  = ( agent.indexOf( "aix 2" ) != -1 );    
var isAix3  = ( agent.indexOf( "aix 3" ) != -1 );    
var isAix4  = ( agent.indexOf( "aix 4" ) != -1 );    
var isLinux = ( agent.indexOf( "inux") != -1 );
var isSco   = ( agent.indexOf( "sco" ) != -1 ) || ( agent.indexOf( "unix_sv" ) != -1 );
var isUnixware = ( agent.indexOf( "unix_system_v" ) != -1 ); 
var isMpras    = ( agent.indexOf( "ncr") != -1 ); 
var isReliant  = ( agent.indexOf( "reliantunix" ) != -1 );
var isDEC   = ( ( agent.indexOf( "dec" ) != -1 ) || ( agent.indexOf( "osf1" ) != -1 ) || 
       ( agent.indexOf( "dec_alpha" ) != -1 ) || ( agent.indexOf( "alphaserver" ) != -1 ) || 
       ( agent.indexOf( "ultrix" ) != -1 ) || ( agent.indexOf( "alphastation" ) != -1 ) ); 
var isSinix = ( agent.indexOf( "sinix" ) != -1 );
var isFreeBSD = ( agent.indexOf( "freebsd" ) != -1 );
var isBSD = ( agent.indexOf( "bsd" ) != -1 );
var isUnix  = ( ( agent.indexOf( "x11" ) != -1 ) || isSun || isIrix || isHPUx || 
             isSco ||isUnixware || isMpras || isReliant || 
             isDEC || isSinix || isAix || isLinux || isBSD || isFreeBSD );

var isVMS   = ( ( agent.indexOf( "vax" ) != -1 ) || ( agent.indexOf( "openvms" ) != -1 ) );

function checkBrowser()
{
  if ( !isMSIE5AndUp && !isNetscapeV6AndUp ) {
    window.location.replace("badBrowser.jsp");
  }
}
function checkBrowserStart()
{
  if ( !isMSIE5AndUp && !isNetscapeV6AndUp ) {
    window.location.replace("badBrowser.jsp");
  } else {
    window.location.replace("logOnInitAction.do");
  }
}
