//<script language="JavaScript">
/*
	Author:			Robert Graves
	Created:		02/13/2001
	Last Modified:	03/05/2001

	Description:
		Extends the navigator object with added functionality
*/

fxExtendNavigator();

function fxExtendNavigator(){
	/*
		Extends the navigator object with added functionality:
			Browser version
			OS
			JavaScript Version
			VBScript Detection
			Plugin Detection
		It also caches the data in a cookie, so it does not need
		to parse the UserAgent data on every page.
	*/

	// Some constants
	navigator.unknown = 1;
	navigator.ie = 2;
	navigator.netscape = 4;
	navigator.opera = 8;

	// Properties
	navigator.type = null;
	navigator.version = null;
	navigator.os = null;
	navigator.jsVersion = 1.0;
	navigator.vbScriptEnabled = false;
	navigator.hasPlugin = fxHasPlugin;
	navigator.selectPluginDetectType = fxSelectPluginDetectType;
	navigator.setCookie = fxSetCookie;
	
	navigator.hasFlash = fxHasFlash;
	navigator.hasQuickTime = fxHasQuicktime;
	navigator.hasRealPlayer = fxHasRealPlayer;
	navigator.hasWindowsMediaPlayer = fxHasWindowsMediaPlayer;
	navigator.hasAcrobat = fxHasAcrobat;

	fxInit();

	function fxInit(){
		/*
			Checks if the data has been stored in a cookie.  If so, read it in from the
			cookie.  Otherwise parse the UserAgent string for detailed info.
		*/
		var strBrowserCookie = usat.cookie.get("BrowserSniffer");
		if (strBrowserCookie){
			eval(strBrowserCookie);
			navigator.selectPluginDetectType();
		}   // if
		else{
			fxParseUserAgent();
			document.write("<scr" + "ipt language=\"JavaScript1.1\">navigator.jsVersion = 1.1;</s" + "cript>");
			document.write("<scr" + "ipt language=\"JavaScript1.2\">navigator.jsVersion = 1.2;</s" + "cript>");
			document.write("<scr" + "ipt language=\"JavaScript1.3\">navigator.jsVersion = 1.3;</s" + "cript>");
			document.write("<scr" + "ipt language=\"JavaScript1.4\">navigator.jsVersion = 1.4;</s" + "cript>");
			document.write("<scr" + "ipt language=\"JavaScript1.5\">navigator.jsVersion = 1.5;</s" + "cript>");
			document.write("<scr" + "ipt language=\"JavaScript1.6\">navigator.jsVersion = 1.6;</s" + "cript>");
			document.write("<scr" + "ipt language=\"JavaScript2.0\">navigator.jsVersion = 2.0;</s" + "cript>");
			document.write("<scr" + "ipt language=\"VBScript\">navigator.vbScriptEnabled = true</s" + "cript>");
			document.write("<scr" + "ipt language=\"JavaScript\">navigator.selectPluginDetectType();navigator.setCookie();</s" + "cript>");
		}   // else
	}   // fxInit

	function fxParseUserAgent () {
		/*
			Function that chooses how to parse the UserAgent string depending
			on the browser name.
		*/
		var version;
		switch (navigator.appName){
			case "Microsoft Internet Explorer":
				navigator.type = navigator.ie;
				navigator.version = fxGetIEVersion();
				navigator.os = fxGetIEOS();
				break;
			case "Netscape":
				navigator.type = navigator.netscape;
				navigator.version = fxGetNetscapeVersion();
				navigator.os = fxGetNetscapeOS();
				break;
			case "Opera":
				navigator.type = navigator.opera;
				navigator.version = fxGetOperaVersion();
				navigator.os = fxGetOperaOS();
				break;
			default:
				navigator.type = navigator.unknown;
				navigator.version = parseFloat(navigator.appVersion);
				navigator.os = "Unknown";
		}   // switch
	}   // fxParseUserAgent


	function fxGetIEVersion () {
		/*
			Function that parses the IE UserAgent string to find the browser
			version.
		*/
		var strUserAgent = new String(navigator.userAgent);
		var arrUA = strUserAgent.split("MSIE ");
		return parseFloat(arrUA[1]);
	}   // fxGetIEVersion

	function fxGetNetscapeVersion () {
		/*
			Function that parses the Netscape UserAgent string to find the
			browser version.
		*/
		var strUserAgent = new String(navigator.userAgent);
		var version, arrUA;
		if (strUserAgent.indexOf("Gecko") < 0){
			// have to handle NS 6 differently from earlier versions
			version = parseFloat(navigator.appVersion);
		}   // if
		else{
			arrUA = strUserAgent.split("Netscape");
			arrUA = arrUA[1].split("/");
			version = parseFloat(arrUA[1]);
		}   // else
		return version;
	}   // fxgetIEVersion

	function fxGetOperaVersion () {
		/*
			Function that parses the Opera UserAgent string to find the
			browser version.
		*/
		var strUserAgent = new String(navigator.userAgent);
		var arrUA = strUserAgent.split("Opera/");
		return parseFloat(arrUA[1]);
	}   // fxgetIEVersion

	function fxGetIEOS () {
		/*
			Function that parses the IE UserAgent string to find the
			operating system.
		*/
		var strUserAgent = new String(navigator.userAgent);
		var arrUA = strUserAgent.split(";");
		return arrUA[2].substr(0, arrUA[2].length);
	}   // fxGetIEOS

	function fxGetNetscapeOS () {
		/*
			Function that parses the Netscape UserAgent string to find the
			operating system.
		*/
		var strOS;
		var strUserAgent = new String(navigator.userAgent);
		var arrUA = strUserAgent.split("(");
		arrUA = arrUA[1].split(";");
		if (this.version < 6) {
			strOS = arrUA[0];
		}   // if
		else {
			strOS = arrUA[2];
		}   // else
		return strOS;
	}   // fxGetNetscapeOS

	function fxGetOperaOS () {
		/*
			Function that parses the Opera UserAgent string to find the
			operating system.
		*/
		var strUserAgent = new String(navigator.userAgent);
		var arrUA = strUserAgent.split("(");
		arrUA = (new String(arrUA[1])).split(";");
		return arrUA[0];
	}   // fxGetIEOS

	function fxHasPlugin (strPluginName, strPluginObject) {
		/*
			Detects weather the browser supports the selected plugin.
			strPluginName is the name of the plugin within the navigator.plugins array.
			Since IE doesn't support the navigator.plugins array (Except in IE 5 on Mac)
			we have to call hasPlugin with the strPluginObject parameter.  This is the
			name of the ActiveXObject.
		*/
		var blnHasPlugin = false;
		switch (navigator.pluginDetectType){
			case "plugins array":
				for (var i=0;i<navigator.plugins.length;i++){
					// loop through the plugins looking for the one we want
					if (navigator.plugins[i].name.indexOf(strPluginName) >= 0){
						blnHasPlugin = true;
						break;
					}   // if
				}   // for
				break;
			case "detectPlugin function":
				blnHasPlugin = fxDetectPlugin(strPluginObject);
				break;
		}   // switch
		return blnHasPlugin;
	}   // fxHasPlugin

	function fxSelectPluginDetectType(){
		/*
			Chooses what type of plugin detection to do.  If the navigator is IE, and 
			the plugins array doesn't exist or is empty, it writes out a detectPlugin
			function specificaly for IE.  It uses JavaScript 1.3 if available, or 
			VBScript JS 1.3 is not supported.
		*/
		// If the browser stores it's plugin data in navigator.plugins array
		// like Netscape and Opera, check there
		if ((navigator.plugins) && (navigator.plugins.length > 0)){
			navigator.pluginDetectType = "plugins array";
		}   // if
		else if (navigator.type = navigator.ie){
			if (navigator.jsVersion >= 1.3){
				navigator.pluginDetectType = "detectPlugin function";
				document.write("<scr" + "ipt language=\"JavaScript1.3\">\n");
				document.write("	function fxDetectPlugin(strPluginName){\n");
				document.write("		var blnHasPlugin = false;\n");
				document.write("		try{\n");
				document.write("			var obj = new ActiveXObject(strPluginName);\n");
				document.write("			blnHasPlugin = true;\n");
				document.write("		}   // try\n");
				document.write("		catch(Exception){");
				document.write("		}\n");
				document.write("		return blnHasPlugin;\n");
				document.write("	}   // fxCheckPlugin\n");
				document.write("</s" + "cript>\n");
			}   // if
			else if (navigator.vbScriptEnabled){
				navigator.pluginDetectType = "detectPlugin function";
				document.write("<scr" + "ipt language=\"VBScript\">\n");
				document.write("	function fxDetectPlugin(strPluginName)\n");
				document.write("		on error resume next\n");
				document.write("		if (IsObject(CreateObject(strPluginName))) then\n");
				document.write("			fxDetectPlugin = true\n");
				document.write("		else\n");
				document.write("			fxDetectPlugin = false\n");
				document.write("		end If\n");
				document.write("	end function\n");
				document.write("</s" + "cript>\n");
			}   // else if
			else{
				navigator.pluginDetectType = "none";
			}   // else
		}   // else if
	}   // fxSelectPluginDetectType

	function fxSetCookie(){
		/*
			Sets the cookie BrowserSniffer to cache the extended data in 
			the navigator object instead of re-alanyzing it each time the
			page is loaded.  The cookie is set as a session cookie.
		*/
		var strCookieValue = "navigator.type=" + navigator.type + ";\n"
								+ "navigator.version=" + navigator.version + ";\n"
								+ "navigator.os=\"" + navigator.os + "\";\n"
								+ "navigator.jsVersion=" + navigator.jsVersion + ";\n"
								+ "navigator.vbScriptEnabled=" + navigator.vbScriptEnabled + ";\n";
		usat.cookie.set("BrowserSniffer", strCookieValue, null, "/");
	}   // fxSetCookie

	function fxHasFlash(fltVersion){
		var blnHasFlash = false;
		var strVersion;
		if (fltVersion){
			switch (navigator.pluginDetectType){
				case "plugins array":
					for (var i=0;i<navigator.plugins.length;i++){
						// loop through the plugins looking for the one we want
						if (navigator.plugins[i].name.indexOf("Shockwave Flash") >= 0){
							strVersion = navigator.plugins[i].description.substr(16, navigator.plugins[i].description.length);
							if (parseFloat(strVersion) >= fltVersion){
								blnHasFlash = true;
								break;
							}   // if
						}   // if
					}   // for
					break;
				case "detectPlugin function":
					blnHasFlash = fxDetectPlugin("ShockwaveFlash.ShockwaveFlash." + parseInt(fltVersion));
					break;
			}   // switch
		}   // if
		else{
			blnHasFlash = navigator.hasPlugin("Shockwave Flash", "ShockwaveFlash.ShockwaveFlash");
		}   // else
		return blnHasFlash;
	}   // fxHasFlash

	function fxHasQuicktime(){
		return navigator.hasPlugin("QuickTime", "QuickTimeCheckObject.QuickTimeCheck.1");
	}   // fxHasQuicktime

	function fxHasRealPlayer(){
		return navigator.hasPlugin("RealPlayer", "RealPlayer.RealPlayer(tm) ActiveX Control (32-bit).1");
	}   // fxHasRealPlayer

	function fxHasWindowsMediaPlayer(){
		return navigator.hasPlugin("Windows Media Player", "MediaPlayer.MediaPlayer.1");
	}   // fxHasWindowsMediaPlayer

	function fxHasAcrobat(){
		return navigator.hasPlugin("Adobe Acrobat", "PDF.PdfCtrl.1");
	}   // fxHasAcrobat
}   // fxExtendNavigator

