var user_agent = navigator.userAgent.toLowerCase();

//Internet Explorer check
function validateIEUsage(){
	if ((user_agent.indexOf("msie") != -1)){
		return true;
	}
	return false;
}

//Internet Explorer versie hoger dan 5.5 check
function validateIE55()
{
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
      if (rv >= 5.5) {
      	return true
      } 
  }
  return false;
}

//Windows Media Player versie hoger dan 9.0 check
try{
	var VLD_mediaPlayer = new ActiveXObject("WMPlayer.OCX");
	var VLD_WMPversion = parseInt(VLD_mediaPlayer.versionInfo);
} catch (e) {}

function validateWMP(){
	var playerIsOk = false;
	try{		
		if(VLD_WMPversion >= 9)
			playerIsOk = true;
		else
			playerIsOk = false;
	}catch(e){};
	
	return playerIsOk;
}

function writeLoadingError(errorState){

	document.write('<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0">');
	document.write('	<tr>');
	document.write('		<td width="100%" height="33%" colspan="3">&nbsp;</td>');
	document.write('	</tr>');
	document.write('	<tr>');
	document.write('		<td width="20%" height="34%">&nbsp;</td>');
	document.write('		<td width="80%" height="34%" valign="middle" align="center">');
	document.write('			<table width="100%" cellpadding="0" cellspacing="0" border="0">');
	document.write('				<tr>');
	document.write('					<td class="errorLabel" width="60%"><img src="img/warning.png" border="0"> Error loading the Media Player</td>');
	document.write('					<td width="40%">&nbsp;</td>');
	document.write('				</tr>');
	document.write('				<tr>');
	document.write('					<td width="100%" colspan="2">&nbsp;</td>');
	document.write('				</tr>');
	document.write('				<tr>');
	document.write('					<td class="errorLabel" width="60%">Javascript Enabled</td>');
	document.write('					<td width="40%"><img src="img/ok.png" border="0" width="20" height="20"></td>');
	document.write('				</tr>');

	if (errorState == 'noie'){
		document.write ('				<tr>');
		document.write ('					<td class="errorLabel" width="60%">Internet Explorer</td>');
		document.write ('					<td width="40%"><img src="img/error.png" border="0" width="20" height="20"></td>');
		document.write ('				</tr>');
		document.write ('				<tr>');
		document.write ('					<td width="100%" colspan="2" class="errorNotification">Please use Microsoft Internet Explorer (<a class="error" href="http://www.microsoft.com/windows/ie/downloads/default.mspx" target="_BLANK">Download</a>).</td>');
		document.write ('				</tr>');
	}

	else if (errorState == 'noie55' || errorState == 'nowmp9'){
		document.write ('				<tr>');
		document.write ('					<td class="errorLabel" width="60%">Internet Explorer</td>');
		document.write ('					<td width="40%"><img src="img/ok.png" border="0" width="20" height="20"></td>');
		document.write ('				</tr>');

	}

else{
		document.write ('				<tr>');
		document.write ('					<td class="errorLabel" width="60%">Internet Explorer</td>');
		document.write ('					<td width="40%"><img src="img/ok.png" border="0" width="20" height="20"></td>');
		document.write ('				</tr>');
}

if (errorState == 'noie55'){
		document.write ('				<tr>');
		document.write ('					<td class="errorLabel" width="60%">Internet Explorer version 5.5 or higher</td>');
		document.write ('					<td width="40%"><img src="img/error.png" border="0" width="20" height="20"></td>');
		document.write ('				</tr>');
		document.write ('				<tr>');
		document.write ('					<td width="100%" colspan="2" class="errorNotification">Your installation of Microsoft Internet Explorer needs an update! <a class="error" href="http://www.microsoft.com/windows/ie/downloads/default.mspx" target="_BLANK">(Click here to update)</a></td>');
		document.write ('				</tr>');

}
else if (errorState == 'nowmp9'){
		document.write ('				<tr>');
		document.write ('					<td class="errorLabel" width="60%">Internet Explorer version 5.5 or higher</td>');
		document.write ('					<td width="40%"><img src="img/ok.png" border="0" width="20" height="20"></td>');
		document.write ('				</tr>');

}

else {
		document.write ('				<tr>');
		document.write ('					<td class="errorLabel" width="60%">Internet Explorer version 5.5 or higher</td>');
		document.write ('					<td width="40%">&nbsp;</td>');
		document.write ('				</tr>');
	
}

if (errorState == 'nowmp9'){
		document.write ('				<tr>');
		document.write ('					<td class="errorLabel" width="60%">Windows Media Player 9.0 or higher</td>');
		document.write ('					<td width="40%"><img src="img/error.png" border="0" width="20" height="20"></td>');
		document.write ('				</tr>');
		document.write ('				<tr>');
		document.write ('					<td width="100%" colspan="2" class="errorNotification">Your installation of Windows Media Player needs an update! <a class="error" href="http://www.microsoft.com/windows/windowsmedia/download/default.asp" target="_BLANK">(Click here to update)</a></td>');
		document.write ('				</tr>');
}
else {
		document.write ('				<tr>');
		document.write ('					<td class="errorLabel" width="60%">Windows Media Player 9.0 or higher</td>');
		document.write ('					<td width="40%">&nbsp;</td>');
		document.write ('				</tr>');
}
				
	document.write ('			</table>');
	document.write ('		</td>');
	document.write ('		<td width="20%" height="34%">&nbsp;</td>');
	document.write ('	</tr>');
	document.write ('	<tr>');
	document.write ('		<td width="100%" height="33%" colspan="3">&nbsp;</td>');
	document.write ('	</tr>');
	document.write ('</table>');
}

function checkAndLaunch(){
	
	var allSettingsOk = false;
	if (validateIEUsage()){
		if(validateIE55()){
			if(validateWMP()){
				allSettingsOk = true;
			}
			else{
				//Geen of oude Windows Media Player
				writeLoadingError('nowmp9');
			}
		}
		else{
			//IE lager dan 5.5
			writeLoadingError('noie55');
		}
	}
	else{
		//Geen IE
		writeLoadingError('noie');
	}
	if (allSettingsOk){
		drawMediaplayer();
	}
}
