// REVISION HISTORY
//	020901	pharman	original WebSphere version
//		***********************************************************************
//		NOTE: Netscape 6 sniffing is OFF allowing all Netscape 6 users to enter
//		please consult with me before changing ANYTHING. Thanks!
//		***********************************************************************
//	081701	pharman added Quicktime sniffing

// Sniffing logic:
// * Test browser version.  If it's not a good-enough browser, go to download_browser.jsp.
// * Check for plugin technology.
//   - If ActiveX, look for Flash control.
//   - If plugin, look in plugins array.
//   - If Mac IE 4, go to macie.jsp.
// * Set plugins cookie.
//
//
// Globals
var hasCookie = document.cookie.indexOf("WBOLClient") != -1;
var browser_redirect = "http://www2.warnerbros.com/web/entry/download_browser.jsp?page=http://" + location.host + escape(location.pathname);
var macie_redirect = "http://www2.warnerbros.com/web/entry/macie.jsp?page=http://" + location.host + escape(location.pathname);
var macie_browser_redirect;
var flash_redirect = "http://www2.warnerbros.com/web/entry/download_flash.jsp?page=http://" + location.host + escape(location.pathname);
var director_redirect = "http://www2.warnerbros.com/web/entry/download_director.jsp?page=http://" + location.host + escape(location.pathname);
// we have to handle Pulse redirection carefully to send them back to the content pages for installation

if (CS_Sniffer.showName != null){
	browser_redirect += "&show=" + CS_Sniffer.showName;
	macie_redirect += "&show=" + CS_Sniffer.showName;
	flash_redirect += "&show=" + CS_Sniffer.showName;
}
//
// The big sniffMe function
	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));
	// added the Gecko sniffing which is unique to Netscape 6
	//var isNav6 = (agt.indexOf("gecko") != -1);
	//if (isNav6){ is_major = 6;}
	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 = "otherplat";
	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 = "Windows16";
	}
	// 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 = "otherplat";
	}
	else if ((agt.indexOf("os/2")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1) || (agt.indexOf("ibm-webexplorer")!=-1)){
		platform = "otherplat";
	}
	else {
		platform = "otherplat";
	}
	
	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);
		}
	}
// ************************************************
// **		Mac/IE 4.x Special Handling          **
// ************************************************
//
// ** Trap mac/ie here
var moreThanFlash = false;
var sniff = true; // ** default to true since we usually want to sniff them!! **
// ** check to see if the requesting page is sniffing for 
// ** more than flash. **
for (var props in CS_Sniffer){
	if (props.indexOf("Flash") == -1 && props.indexOf("destination") == -1 && props.indexOf("showName") == -1){
		moreThanFlash = true;
	}
}
if (!useEmbeds && !useActiveX){ // ** mac/ie only **
	if (moreThanFlash){
			document.location = browser_redirect;
	}
	if (hasCookie && !moreThanFlash){ // ** we have sniffed them already and they have seen our mac/ie page lettem in **
		sniff = 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 = 0;
			}
		}
	
		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 = 0;
			}
		}
	}
	// end Flash sniff
	
	// Real sniff
	var realVersion = 0;
	if (goodBrowser) {
		if (useEmbeds) {
			var pluginPointer = (navigator.plugins["RealPlayer(tm) G2 LiveConnect-Enabled Plug-In (32-bit) "]);
	
			if (pluginPointer) {
				realVersion = 1;
			}
			else {
				realVersion = 0;
			}
		}
		if (useEmbeds && (platform == "Macintosh")){
	
			var pluginPointer = (navigator.mimeTypes["audio/x-pn-realaudio-plugin"]);
			//var pluginPointer = (navigator.plugins["RealPlayerG2 Plugin"]);
	
			if (pluginPointer) {
				realVersion = 1;
			}
			else {
				realVersion = 0;
			}
		}
		if (useActiveX){
			if (TestActiveX("rmocx.RealPlayer G2 Control.1")) {
				realVersion = 1;
			}
			else {
				realVersion = 0;
			}
		}
	}
	//end Real sniff
	
	// Windows Media Player sniff
	var wmpVersion = 0;
	if (goodBrowser) {
		if (useEmbeds) {
			var pluginPointer = (navigator.plugins["Windows Media Player Plug-in Dynamic Link Library"]);

			if (pluginPointer) {
				wmpVersion = 1;
			}
			else {
				wmpVersion = 0;
			}
		}
		if (useActiveX){
			if (TestActiveX("MediaPlayer.MediaPlayer.1")) {
				wmpVersion = 1;
			}
			else {
				wmpVersion = 0;
			}
		}
	}
	//end Windows Media Player sniff
	
	// ShockWave/Director sniff
	var directorVersion = 0;
	if (goodBrowser) {
		if (useEmbeds) {
			var pluginPointer = (navigator.plugins["Shockwave for Director"]);
	
			if (pluginPointer) {
				directorVersion = 7;
			}
			else {
				directorVersion = 0;
			}
		}
		if (useActiveX){
			if (TestActiveX("SWCtl.SWCtl.8")){
				directorVersion = 8;
		    }else if (TestActiveX("SWCtl.SWCtl.7")){
				directorVersion = 7;
		    }   
		    else {
				directorVersion = 0;
	        }
		}
	}
	// Pulse sniff
	var pulseVersion = "0000";
	if (goodBrowser) {
		if (useEmbeds){
			var pluginPointer = (navigator.plugins["PulsePlayer"]);
			if (pluginPointer != null) {
				if (pluginPointer.description.indexOf("3.5.2.5") >= 0) {
					pulseVersion = 3525;
				}
			
				if (pluginPointer.description.indexOf("4.1.1.6") >= 0) {
					pulseVersion = 4116;
				} 
				
				if (pluginPointer.description.indexOf("4.3.0.968") >= 0) {
					pulseVersion = 4309;
				}
				if (pluginPointer.description.indexOf("4.3.0.1134") >=0){
					pulseVersion = 4310;
				}
			}
		}
		if (useActiveX){
			document.writeln("<OBJECT ID='PulsePlayerVersion' CLASSID='CLSID:D6016EE7-A8FF-11D1-B37E-A4759ECD7909' WIDTH=0 HEIGHT=0></OBJECT>");
			
			var pluginPointer = document.all["PulsePlayerVersion"].Version;
			switch(pluginPointer) {
				case "3.5.2.8":
					pulseVersion = 3525;
					break;
				case "4.1.1.6":
					pulseVersion = 4116;
					break;
				case "4.3.0.968":
					pulseVersion = 4309;
					break;
				case "4.3.0.1134":
					pulseVersion = 4310;
					break;
				default:
					pulseVersion = "0000";
			}
		}
			
	}
	// Quicktime sniff
	var quicktimeVersion = 0;
	if (goodBrowser) {
		if (useEmbeds){
			for (var i = 0; i < navigator.plugins.length; i++){
				var nplc = navigator.plugins[i].name;
				nplc = nplc.toLowerCase();
				if (nplc.indexOf("quicktime") >= 0){
					quicktimeVersion = 1;
					break;
				}
			}
		}
		if (useActiveX){
			if (TestActiveX("QuickTimeCheckObject.QuickTimeCheck.1")){
				quicktimeVersion = 1;
			}
		}
	}
			
if (sniff){	
	var sniffCookie = "";
	if (goodBrowser) {
		var sep = "<^>";
		sniffCookie = ("platform=" + platform + sep
			+ "isIE=" + isIE + sep
			+ "isNav=" + isNav + sep
			+ "is_major=" + is_major + sep);
		
		sniffCookie += "flashVersion=" + flashVersion + sep;
		sniffCookie += "wmpVersion=" + wmpVersion + sep;
		sniffCookie += "realVersion=" + realVersion + sep;
		sniffCookie += "directorVersion=" + directorVersion + sep;
		sniffCookie += "pulseVersion=" + pulseVersion + sep;
		sniffCookie += "quicktimeVersion=" + quicktimeVersion + sep;
		document.cookie = "WBOLClient=" + sniffCookie + "; path=/;";
	}	

	// Use the browser/plugin information...
	
	// Is the browser good enough?
	if (!goodBrowser) {
		document.location = browser_redirect;
	}
	// Was it impossible to detect plugins?
	else if (!useEmbeds && !useActiveX) {
		document.location = macie_redirect;
	}
	// Do we need Flash?
	else if (flashVersion < CS_Sniffer.needFlashVersion) {
		document.location = flash_redirect;
	}
	// Do we need Director?
	else if (directorVersion < CS_Sniffer.needDirectorVersion) {
		document.location = director_redirect;
	}
	// clearance granted, proceed
	//else if (location.pathname.toLowerCase().indexOf(".html") >= 0 || (location.pathname.length == 1 && location.pathname.toLowerCase().indexOf("/") == 0)){
	//	location.replace(CS_Sniffer.destination);
	//}
}
