// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');
    
    document.writeln('Private i, x');
    document.writeln('On Error Resume Next');
    document.writeln('MM_FlashControlInstalled = False');
    document.writeln('For i = 6 To 1 Step -1');
    document.writeln(' Set x = CreateObject("ShockwaveFlash.ShockwaveFlash." & i)');
    document.writeln(' MM_FlashControlInstalled = IsObject(x)');
    document.writeln(' If MM_FlashControlInstalled Then');
    document.writeln('   MM_FlashControlVersion = CStr(i)');
    document.writeln('   Exit For');
    document.writeln(' End If');
    document.writeln('Next');
    
    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}

var detectableWithVB = false;
var pluginFound = false;
var whoAreYou = getBrowserInfo("name");
var howOldAreYou = getBrowserInfo("version");
var haveFlash = "";
var whichFlash = "";
MM_FlashInfo();

var browserPluginInfo = new Array(whoAreYou, Math.round(howOldAreYou), haveFlash, Math.round(whichFlash));

function getBrowserInfo(info) {
 var IE4 = (document.all && !document.getElementById) ? true : false;
 var NS4 = (document.layers) ? true : false;
 var IE5 = (document.all && document.getElementById) ? true : false;
 var N6 = (document.getElementById && !document.all) ? true : false;
 var browserInfo = new Array();
 if (IE4) {
  browserInfo[0] = "IE";
  browserInfo[1] = "4";
 } else if (NS4) {
  browserInfo[0] = "NN";
  browserInfo[1] = "4";
 } else if (IE5) {
  browserInfo[0] = "IE";
  browserInfo[1] = "5";
 } else if (N6) {
  browserInfo[0] = "NN";
  browserInfo[1] = "6";
 }
 if (info == "name") {
  return browserInfo[0];
 } else if (info == "version") {
  return browserInfo[1];
 }
}


function checkFlashPlugin () {
 if (canDetectPlugins()) {
  return detectFlash();
 } else {
  return -1;
 }
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}

function detectFlash() {
    pluginFound = detectPlugin('Shockwave','Flash'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
    	alert("Falling into VB.");
	pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    if (pluginFound) {
    
    }
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin

var MM_FlashControlInstalled;	// is the Flash ActiveX control installed?
var MM_FlashControlVersion;	// ActiveX control version if installed

function MM_FlashInfo() {
    if (navigator.plugins && navigator.plugins.length > 0) {
	var implementation = "Plug-in";
	var autoInstallable = false;	// until Netscape SmartUpdate supported
	// Check whether the plug-in is installed:
	if (navigator.plugins["Shockwave Flash"]) {
	    var installed = true;
	    // Get the plug-in version and revision:
	    var words =	navigator.plugins["Shockwave Flash"].description.split(" ");
	    for (var i = 0; i < words.length; ++i) {
		if (isNaN(parseInt(words[i]))) {
		  continue;
		}
		var version = words[i];
		var revision = parseInt(words[i + 1].substring(1));
		haveFlash = 1;
		whichFlash = version;
	    }
	} else {
	    installed = false;
	}
    } else if (MM_FlashControlInstalled != null) {
	implementation = "ActiveX control";
	installed = MM_FlashControlInstalled;
	version = MM_FlashControlVersion;
	autoInstallable = true;
	haveFlash = 1;
	whichFlash = version;
    }
}
