var hasCookie = document.cookie.indexOf("WBC") != -1;
var browser_redirect = "/web/entry/download_browser.jsp?page=" + escape(location.pathname);
var macie_redirect = "/web/entry/macie.jsp?page=" + escape(location.pathname);
var macie_browser_redirect;
var flash_redirect = "/web/entry/download_flash.jsp?page=" + escape(location.pathname);
var director_redirect = "/web/entry/download_director.jsp?page=" + escape(location.pathname);
if (CS_Sniffer.showName != null){
	browser_redirect += "&show=" + CS_Sniffer.showName;
	macie_redirect += "&show=" + CS_Sniffer.showName;
	flash_redirect += "&show=" + CS_Sniffer.showName;
}
var n=navigator;d=document;ua=n.userAgent.toLowerCase();av=parseFloat(n.appVersion);an=n.appName.toLowerCase();
var os={win:ua.indexOf("win")!=-1,mac:ua.indexOf("mac")!=-1||ua.indexOf("ppc")!=-1};
var ie=ua.indexOf("msie")!=-1&&ua.indexOf("opera")==-1;
var ns=(an.indexOf("netscape")!=-1&&ua.indexOf("gecko")==-1)||ua.indexOf("netscape6")!=-1;
var wbis = {ie4:ua.indexOf("msie 4.")!=-1&&ie,ie5:ua.indexOf("msie 5.")!=-1&&ie,ie6:ua.indexOf("msie 6.")!=-1&&ie,ns:(av>=4.51)&&ns,aol5:ua.indexOf("aol 5.0")!=-1};
var wbisie=(wbis.ie4||wbis.ie5||wbis.ie6);
var wbisns=wbis.ns;
var wbispcie=(os.win&&wbisie);
var wbismacaol5=(os.mac&&wbis.aol5);
var wbismacie4=(os.mac&&wbis.ie4);
var wbismacie5=(os.mac&&wbis.ie5);
var wbisbadbw=((ie||ns)&&!(wbisie||wbisns));
var wbisotherbw=(!(ie||ns));
//alert(wbisotherbw);
var goodBrowser = (!wbisbadbw);
var useEmbeds= !wbisotherbw && !wbisbadbw && (wbisns || wbismacie5);
var useActiveX = !wbisotherbw && !wbisbadbw && wbispcie;
if (useActiveX){
        d.write("<SCR" + "IPT LANGUAGE=\"VBScript\">\n");
        d.write("Function AXC(obj)\n");
        d.write("On error resume next\n");
        d.write("AXC = IsObject(CreateObject(obj))\n");
        d.write("End Function\n");
        d.write("</SCR" + "IPT>");
}
// ************************************************
// **		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;
	}
		
}
var flashVersion = 0;
if (goodBrowser) {
	if (useEmbeds) {
		var pluginPointer = (navigator.plugins["Shockwave Flash"] || navigator.plugins["ShockwaveFlash"]);
	if (pluginPointer != null) {
			if (pluginPointer.description.indexOf("6.") != -1) {
					flashVersion = 6;
				}
				else 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 (AXC("ShockwaveFlash.ShockwaveFlash.6")) {
				flashVersion = 6;
			}
			else if (AXC("ShockwaveFlash.ShockwaveFlash.5")) {
				flashVersion = 5;
			}
			else if (AXC("ShockwaveFlash.ShockwaveFlash.4")) {
				flashVersion = 4;
			}
			else if (AXC("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 && (os.mac == "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 (AXC("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 (AXC("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 (AXC("SWCtl.SWCtl.8")){
				directorVersion = 8;
		    }else if (AXC("SWCtl.SWCtl.7")){
				directorVersion = 7;
		    }
		    else {
				directorVersion = 0;
	        }
		}
	}
	// 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 (AXC("QuickTimeCheckObject.QuickTimeCheck.1")){
				quicktimeVersion = 1;
			}
		}
	}
if (sniff){	
	if (!wbisotherbw){
		var sniffCookie = "";
		if (goodBrowser) {
			var sep = "&";
			sniffCookie += sep + "f" + flashVersion + sep;
			sniffCookie += "w" + wmpVersion + sep;
			sniffCookie += "r" + realVersion + sep;
			sniffCookie += "d" + directorVersion + sep;
			sniffCookie += "q" + quicktimeVersion;
			document.cookie = "WBC=" + sniffCookie + "; path=/;";
		}	

		// Use the browser/plugin information...

		// Is the browser good enough?
		if (wbisbadbw) {
			document.location = browser_redirect;
		}
		// Was it impossible to detect plugins?
		else if (!useEmbeds && !useActiveX && !wbisotherbw) {
			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);
		//}
	}
}
