var name = navigator.appName;
var agent = navigator.userAgent.toLowerCase();

// detect browser type
var isOpera = agent.indexOf("opera") != -1;
var isNetscape = agent.indexOf("netscape") != -1;
var isIE = ( (name.indexOf("Microsoft") != -1) && !isOpera );
var seemsOK = (document.getElementById && document.createElement);

// find ie or gecko version
var geckoVersion = geckoGetRv();
var ieVersion = getIEVersion();

// detect platform
var isWindows = agent.indexOf("win") != -1;
var isMac = agent.indexOf("mac") != -1;
var isUnix = agent.indexOf("x11") != -1;

// check flash player is v7 or above
var MM_contentVersion = 6;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
	var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	for (var i = 0; i < words.length; ++i)  {
		if (isNaN(parseInt(words[i])))
			continue;
		var MM_PluginVersion = words[i]; 
	}
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<script language="VBScript"\> \n');
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</script\> \n');
}

// -------------------- functions ------------------------

// open download pages
function checkRequirements() {
	var browserOK = checkBrowser();
	var noFlash = !MM_FlashCanPlay;
	if (!browserOK) {
		popWindow('shared_files/browser_needed.htm', 'require');
	}
	if (noFlash) {
		popWindow('shared_files/flash_needed.htm', 'require');
	}
}

// get IE version
function getIEVersion() {
	if (!isIE)	return -1;
	var version = navigator.userAgent.split("MSIE");
	return parseFloat(version[1]);
}

// get gecko version
function geckoGetRv() {
  if (navigator.userAgent.indexOf('rv:') == -1)
    return -1;
  var rvValue = 0;
  var ua = navigator.userAgent.toLowerCase();
  var rvStart = ua.indexOf('rv:');
  var rvEnd = ua.indexOf(')', rvStart);
  var rv = ua.substring(rvStart+3, rvEnd);
  var rvParts = rv.split('.');
  var exp = 1;
  
  for (var i = 0; i < rvParts.length; i++)  {
    var val = parseInt(rvParts[i]);
    rvValue += val / exp;
    exp *= 100;
  }
  
  return rvValue;
}

// check if browser is ok
function checkBrowser () {
	// gecko version in Netscape 6.2 and up ok all platforms
	if(geckoVersion > 0.0902) return true;
	else if (geckoVersion <= 0.0902 && geckoVersion != -1) seemsOK = false;
	// ie 5+ ok on windows
	else if (isWindows && isIE && (ieVersion >= 5)) return true;
	// ie 5 on mac is ok
	else if (isMac && isIE) {
		if  (parseInt(ieVersion) == 5) return true;
		else seemsOK = false;
	}
	// all others forget it
	else
		return false;
}