var agt = navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
var isNav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
		&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
		&& (agt.indexOf('webtv')==-1));
var isNav4 = (isNav && (is_major == 4));
var isNav4up = (isNav && (is_major >= 4));
var isNavonly	  = (isNav && ((agt.indexOf(";nav") != -1) ||
				  (agt.indexOf("; nav") != -1)) );
var isNav5up = (isNav && (is_major >= 5));

var isIE   = (agt.indexOf("msie") != -1);
var isIE3  = (isIE && (is_major < 4));
var isIE4  = (isIE && (is_major == 4) && (agt.indexOf("msie 4.") != -1) );
var isIE4up  = (isIE  && (is_major >= 4));
var isIE5  = (isIE && (is_major == 4) && (agt.indexOf("msie 5.") != -1) );
var isIE5up  = (isIE  && !isIE3 && !isIE4);
if (isIE5 && (is_major == 4)) { is_major = 5; }

// *** PLATFORM ***
// 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 platform = "Other";
if (((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1))) {
	platform = "Windows95";
}
else if (agt.indexOf("mac")!=-1) {
	platform = "Macintosh";
}
else if ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1)) {
	platform = "Windows98";
}
else if ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1)) {
	platform = "WindowsNT";
}
// is this a 16 bit compiled version?
else if ((agt.indexOf("win16")!=-1) || (agt.indexOf("16bit")!=-1) ||
         (agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("windows 16-bit")!=-1) ) {
	platform = "Windows 16";
}
// 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".
else if (agt.indexOf("windows") != -1) {
	platform = "Windows";
}
else if ((agt.indexOf("os/2")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1) || (agt.indexOf("ibm-webexplorer")!=-1)){
	platform = "OS2";
}
else {
	platform = "Other";
}

var goodBrowser = ((isNav && is_minor > 4.04) || (isIE4up));
var useEmbeds = false, useActiveX = false;
if (goodBrowser) {
	// Win IE uses ActiveX.
	if (isIE4up && platform.indexOf("Win") != -1) {
		useActiveX = true;
	}
	// Otherwise, use embeds, unless it is Mac IE 4.
	else if (isIE4 && platform == "Macintosh") {
		useEmbeds = false;
	}
	else {
		useEmbeds = true;
		navigator.plugins.refresh(false);
	}
}

// Version numbers:
// -1: User does not have plugin.
//  0: Don't know if user has plugin.
// +x: Version number of plugin.

// Flash sniff
var flashVersion = 0;
if (goodBrowser) {
	if (useEmbeds) {
		var pluginPointer = (navigator.plugins["Shockwave Flash"] || navigator.plugins["ShockwaveFlash"]);

		if (pluginPointer != null) {
			if (pluginPointer.description.indexOf("5.") != -1) {
				flashVersion = 5;
			}
			else if (pluginPointer.description.indexOf("4.") != -1) {
				flashVersion = 4;
			}
			else if (pluginPointer.description.indexOf("3.") != -1) {
				flashVersion = 3;
			}
		}
		else {
			flashVersion = -1;
		}
	}

	if (useActiveX) {
		if (TestActiveX("ShockwaveFlash.ShockwaveFlash.5")) {
			flashVersion = 5;
		}
		else if (TestActiveX("ShockwaveFlash.ShockwaveFlash.4")) {
			flashVersion = 4;
		}
		else if (TestActiveX("ShockwaveFlash.ShockwaveFlash.3")) {
			flashVersion = 3;
		}
		else {
			flashVersion = -1;
		}
	}
}
// end Flash sniff

