// Filename: browser.js
// Project : Javascript Library
//
// Description:
// Detect the known browsers and configure the global variables to contain the browser selection
// information.
// Detects the following browsers:
//		Internet Explorer, Netscape Navigator, Opera, Konqueror, WebTV, iCab
// Detects the following operating systems:
//		Windows, Macintosh, Linux, Unix
//
// This code executes directly as it is loaded and sets the global variables with the findings.
// All functions are intended for internal use of the module only.
//
// Revision History:
// 12FEB2001 - MJT - Initial development.

// Public global constants
var BROWSERID_Other = 0;
var BROWSERID_IE4Plus = 1;
var BROWSERID_NS4 = 2
var BROWSERID_NS6 = 3
var BROWSERID_Opera5 = 4

// Public global variables for the results
var BROWSER_OperatingSystem;
var BROWSER_Program;
var BROWSER_Version;
var BROWSER_Type = BROWSERID_Other;

// Private global variables
var BROWSER_strAgent = navigator.userAgent.toLowerCase( );
var BROWSER_strTarget;
var BROWSER_Total;
var BROWSER_lngPos;

function BROWSER_InStr( strValue )
{
	var pos = BROWSER_strAgent.indexOf (strValue ) + 1;
	strTarget = strValue;
	return pos;
}

if ( BROWSER_lngPos = BROWSER_InStr( 'konqueror' ) )
{
	BROWSER_Program = 'Konqueror';
	BROWSER_OperatingSystem = 'Linux';
}
else if ( BROWSER_lngPos = BROWSER_InStr( 'opera' ) )
{
	BROWSER_Program = 'Opera';
	BROWSER_Version = BROWSER_strAgent.charAt( BROWSER_lngPos + strTarget.length );
	if ( parseInt( BROWSER_Version ) >= 5 )
	{
		BROWSER_Type = BROWSERID_Opera5;
	}
}
else if ( BROWSER_lngPos = BROWSER_InStr( 'webtv' ) )
{
	BROWSER_Program = 'WebTV';
	BROWSER_Version = BROWSER_strAgent.charAt( BROWSER_lngPos + strTarget.length );
}
else if ( BROWSER_lngPos = BROWSER_InStr( 'icab' ) )
{
	BROWSER_Program = 'iCab';
	BROWSER_Version = BROWSER_strAgent.charAt( BROWSER_lngPos + strTarget.length );
}
else if ( BROWSER_lngPos = BROWSER_InStr( 'msie' ) )
{
	BROWSER_Program = 'Internet Explorer';
	BROWSER_Version = BROWSER_strAgent.charAt( BROWSER_lngPos + strTarget.length );
	if ( parseInt( BROWSER_Version ) >= 4 )
	{
		BROWSER_Type = BROWSERID_IE4Plus;
	}
}
else if ( !BROWSER_InStr( 'compatible' ) )
{
	BROWSER_Program = 'Netscape Navigator';
	BROWSER_Version = BROWSER_strAgent.charAt( 8 );
	if ( parseInt( BROWSER_Version ) == 4 )
	{
		BROWSER_Type = BROWSERID_NS4;
	}
	else if ( parseInt( BROWSER_Version ) >= 5 )
	{
		BROWSER_Type = BROWSERID_NS6;
	}
}
else
{
	BROWSER_Program = 'Unknown';
	BROWSER_Version = '0';
}

if (!BROWSER_OperatingSystem)
{
	if ( BROWSER_InStr( 'linux' ) )
		BROWSER_OperatingSystem = 'Linux';
	else if ( BROWSER_InStr( 'x11' ) )
		BROWSER_OperatingSystem = 'Unix';
	else if ( BROWSER_InStr( 'mac' ) )
		BROWSER_OperatingSystem = 'Macintosh';
	else if ( BROWSER_InStr( 'win' ) )
		BROWSER_OperatingSystem = 'Windows';
	else
		BROWSER_OperatingSystem = 'Unknown';
}
