// BROWSER DETECTION
	var agt = navigator.userAgent.toLowerCase();
	var appVer = navigator.appVersion.toLowerCase();
	var is_ff = (agt.indexOf("firefox") != -1);
	var is_nn = (agt.indexOf("netscape") != -1);
	var is_opera = (agt.indexOf("opera") != -1);
	var is_mac = (agt.indexOf("mac") != -1);
	var is_safari = ((agt.indexOf("safari") != -1) && (agt.indexOf("mac")!=-1)) ? true : false;
	var is_konq = (agt.indexOf("konqueror") != -1);
	var is_khtml = (is_safari || is_konq) ? true : false;
	var is_ie = ((appVer.indexOf("msie") != -1) && (!is_opera) && (!is_khtml));
	var is_pc_ie  = ((agt.indexOf("msie") != -1) && (agt.indexOf("win") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("webtv") == -1));
	var is_sv2 = (agt.indexOf("sv1") != -1);
	var is_xp = (agt.indexOf("windows nt 5.1") != -1) || (agt.indexOf("windows xp") != -1);
	var is_mce = (agt.indexOf("media center") != -1);
	var is_vista = (agt.indexOf("windows nt 6") != -1);

// OS DETECTION
// we'll cheat a little and infer the OS from the browser
function osDetect() {
	var osInfo = {
		supported: false,
		versionInfo: null
	}
	if (is_mce) {
		osInfo.supported = true;
		osInfo.versionInfo = "MCE";
	} else if (is_xp || is_vista) {
		osInfo.supported = true;
	}
	return osInfo;
}
// VIDEO DETECTION
// detect ActiveX or defer to plugin for other browsers
function wmpDetect() {
	var wmpInfo = {
		installed: false,
		scriptable: false,
		type: null,
		versionInfo: null
	}
	var wmp64 = "MediaPlayer.MediaPlayer.1";
	var wmp7 = "WMPlayer.OCX.7";
	if ((window.ActiveXObject && navigator.userAgent.indexOf('Windows') != -1) || window.GeckoActiveXObject) {
		wmpInfo.type = "ActiveX";
		var wmp_player = axoCreate(wmp7);
		if (wmp_player) {
			wmpInfo.installed = true;
			wmpInfo.scriptable = true;
			wmpInfo.versionInfo = wmp_player.versionInfo;
			return wmpInfo;
		} else {
			wmp_player = axoCreate(wmp64);
			if (wmp_player) {
				wmpInfo.installed = true;
				wmpInfo.scriptable = true;
				wmpInfo.versionInfo = "6.4";
				return wmpInfo;
			} else {
				// FF2/WMP11 doesn't support the gecko WMP control
				// look for the port25.technet.com plugin
				var wmp_player = navigator.mimeTypes && navigator.mimeTypes["application/x-ms-wmp"] && navigator.mimeTypes["application/x-ms-wmp"].enabledPlugin;
				if (wmp_player) {
					wmpInfo.installed = true;
					wmpInfo.scriptable = true;
					wmpInfo.versionInfo = "11";
					return wmpInfo;
				} else {
					wmpInfo.installed = false;
					wmpInfo.versionInfo = "none";
					return wmpInfo;
				}
			}
		}
	} else if (navigator.mimeTypes) {
		wmpInfo.type = "NetscapePlugin";
		var wmp_player = navigator.mimeTypes['application/x-mplayer2'].enabledPlugin;
		if (wmp_player) {
			wmpInfo.installed = true;
			wmpInfo.scriptable = false;
			wmpInfo.versionInfo = "PluginVersion";
			return wmpInfo;
		} else {
			// alert("no media player for navigator");
		}
		return wmpInfo;
	} else {
		// alert("no media player at all");
	}
}

function axoCreate(id) {
	var error;
	var axo_control = null;
	try {
		if (window.ActiveXObject) {
			axo_control = new ActiveXObject(id);
		} else if (window.GeckoActiveXObject) {
			axo_control = new GeckoActiveXObject(id);
		}
	} catch (e) { }
	return axo_control;
}

function wmpCreate(url) {
	var str = "";
	var videoPlayerWidth = "320";
	var videoPlayerHeight = "240";
	
	
	if (is_ff) {
		// create for FF
		if (parseInt(wmp_detect.versionInfo) == 10) {
			str = '<object id="videoPlayer" type="application/x-oleobject" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="' + videoPlayerWidth + '" height="' + videoPlayerHeight + '">';
			str += '<embed id="videoPlayer" name="videoPlayer" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" showstatusbar="true" stretchtofit="false" showcontrols="0" autostart="0" autoplay="false" width="' + videoPlayerWidth + '" height="' + videoPlayerHeight + '" loop="false" src="' + url + '" />';
		} else if (parseInt(wmp_detect.versionInfo) == 11) {
			str = '<object id="videoPlayer" type="application/x-ms-wmp" data="' + url + '" width="' + videoPlayerWidth + '" height="' + videoPlayerHeight+'">';
		} else {
			return false;
		}
	} else {
		// create for IE             
		str = '<object id="videoPlayer" type="application/x-oleobject" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="' + videoPlayerWidth + '" height="' + videoPlayerHeight + '">';
	}

	str += '<param name="URL" value="' + url + '" />';
	str += '<param name="uiMode" value="none" />';
	str += '<param name="enableContextMenu" value="true" />';
	str += '<param name="windowlessVideo" value="true" />';
	str += '<param name="stretchToFit" value="false" />';
	str += '<param name="showControls" value="0" />';
	str += '<param name="autoStart" value="false" />';

	str += '</object>';
	return str;
}

var os_detect, wmp_detect, events_enabled = false;
function systemCheck() {
	// first check the OS
	os_detect = osDetect();
	
	if (!os_detect.supported) {
		document.getElementById("msr_failOperatingSystem").style.display = "block";
		return false;
	}
	// we have a supported OS; check WMP
	wmp_detect = wmpDetect();
	if (parseInt(wmp_detect.versionInfo) < 10) {
		document.getElementById("msr_failWMP").style.display = "block";
		return false
	} else if (is_ff && !wmp_detect.installed) {
		// couldn't find a WMP plugin for FireFox
		if(getFFversion() > 2)
		{
			document.getElementById("msr_failFF3").style.display = "block";
		}
		else
		{
			document.getElementById("msr_failFF").style.display = "block";
		}

	/*} else if (os_detect.versionInfo == "MCE" && parseInt(wmp_detect.versionInfo) == 10) {
		// MCE with WMP10 has a dodgy upgrade path
		document.getElementById("msr_failMCE").style.display = "block";
		return false;*/
	} else {
		document.getElementById("msr_pass").style.display = "block";
		document.getElementById("videoHolder").innerHTML = wmpCreate("");
		setTimeout("wmpTestEvents()", 100);
	}
}

function wmpTestEvents() {
	// this should trigger the OpenStateChange event
	// which sets the variable events_enabled to true
	document.getElementById("videoPlayer").URL = "shuffle";
}

// if we don't get a positive response from the video
// playback, we'll show some troubleshooting tips;
// if our event test didn't work, we'll show the response 
// almost immediately; otherwise we will wait a longer interval
// since we don't know if we'll actually get an error;
// UPDATE: looks like the video will cause an error if 
// the initial upgrade is cancelled or goes bad-- but not every
// upgrade step throws an error. So, keep the timer.
// a positive response will clear the timer
var responseTimer;
function wmpTest(inURL) {
	// show the progress indicator
	document.getElementById("progress_indicator").style.display = "block";
	clearResponses();
	var wmpTarget = document.getElementById("videoPlayer");
	if (wmpTarget) {
		wmpTarget.URL = inURL;
		if (wmpTarget.controls.isAvailable("Play")) {
			wmpTarget.controls.play();
		}
	}
//	var responseWait = (events_enabled) ? 10000 : 1000;
//	responseTimer = setTimeout("initiateFailureResponse()", responseWait);
	if (!events_enabled) responseTimer = setTimeout("initiateFailureResponse()", 1000);
}

// separate function to allow user access to troubleshooting info
function showTroubleshootingInfo() {
	
	document.getElementById("troubleshooting").style.display = "block";
	if (is_vista) document.getElementById("vista_troubleshooting").style.display = "block";
	if (is_ff) {jqN('#directShowCatalog').css({height:"auto"});}
}

function initiateFailureResponse(e) {
	// hide the progress indicator
	document.getElementById("progress_indicator").style.display = "none";
	if (!events_enabled) {
		// we won't hear anything from wmp events, just show all the messages now
		document.getElementById("event_installer_ie").style.display = "none";
		document.getElementById("event_installer_ff").style.display = "none";
		document.getElementById("noevent_installer").style.display = "block";
		document.getElementById("error_message").style.display = "none";
		showTroubleshootingInfo();
	} else {
		// either we've waited a bit and heard nothing, or we've gotten a proper error event
		document.getElementById("noevent_installer").style.display = "none";
		document.getElementById("event_installer_ie").style.display = "none";
		document.getElementById("event_installer_ff").style.display = "none";
		if (e) document.getElementById("error_message").style.display = "block";
		else document.getElementById("error_message").style.display = "none";
		showTroubleshootingInfo();
	}
}
function clearResponses(e) {
	document.getElementById("noevent_installer").style.display = "none";
	document.getElementById("event_installer_ie").style.display = "none";
	document.getElementById("event_installer_ff").style.display = "none";
	if (e) document.getElementById("error_message").style.display = "none";
	else document.getElementById("error_message").style.display = "none";
	document.getElementById("troubleshooting").style.display = "none";
}
/* all available playstate values
   0 Undefined
   1 Stopped
   2 Paused
   3 Playing
   4 ScanForward
   5 ScanReverse
   6 Buffering
   7 Waiting
   8 MediaEnded
   9 Transitioning
   10 Ready
   11 Reconnecting
*/
// This should be good enough to validate the DRM playback...
function wmpPlayStateChange(newState)  {
	switch (newState) {
		case 3: // is playing
			wmpSuccess();
		break;
	}
}
// ... But if wmpPlayStateChange isn't good enough, remove it
// and rely entirely on this
function wmpScriptCommand(bstrType, bstrParam) {
	if (bstrType == "DRM_CHECK" && bstrParam == "PLAY_OK") wmpSuccess();
	else initiateFailureResponse();
}
function wmpSuccess() {
	// hide the progress indicator
	document.getElementById("progress_indicator").style.display = "none";
	if (responseTimer) {
		// don't bother showing the troubleshooting tips
		clearTimeout(responseTimer);
	}
	//jqN('#directShowCatalog').css({height:"auto"});
	if (is_ff) {
		jqN('#directShowCatalog').css({height:"auto"});
		document.getElementById("event_installer_ff").style.display = "inline";
	} else {
		document.getElementById("event_installer_ie").style.display = "inline";
	}
	document.getElementById("noevent_installer").style.display = "none";
	document.getElementById("error_message").style.display = "none";
	document.getElementById("troubleshooting").style.display = "none";
	document.getElementById("vista_troubleshooting").style.display = "none";
}
function wmpError(e) {
	if (responseTimer) {
		// don't bother showing the troubleshooting tips
		clearTimeout(responseTimer);
	}
	initiateFailureResponse(e);

	if((e.errorCode == "-1072885296")&& (parseInt(wmp_detect.versionInfo) == 10)){
		var msgStr = "The test video was unable to play successfully.  We've detected that you're using Windows Media Player 10.";
		msgStr += " A Microsoft update can be installed that can resolve this issue. Please visit ";  
		msgStr += "<a href='http://www.microsoft.com/downloads/details.aspx?FamilyID=73c2650f-be61-4bd6-8408-1fd6e7827cd8&DisplayLang=en' target='_blank'>http://www.microsoft.com/downloads/details.aspx?FamilyID=73c2650f-be61-4bd6-8408-1fd6e7827cd8&DisplayLang=en</a>";
		msgStr += " and install the Windows Media Player 10 update then return to this page and try the test video again.";

		messager(msgStr);
	}
	else if (e.errorCode) {
		messager(e.errorDescription + " <b>" + e.errorCode + "</b>");
	} else {
		messager(e);
	}
}
function messager(str) {
	document.getElementById("error").innerHTML = str;
}

