// initialize global variables
var detectableWithVB = false;
var FlashPluginFound = false;
var flash = false;

function candetectPluginFlashs() {
	if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
	} else {
	return false;
	}
}

function detectFlash() {
	FlashPluginFound = detectPluginFlash('Shockwave','Flash'); 
	// if not found, try to detect with VisualBasic
	if(!FlashPluginFound && detectableWithVB) {
		FlashPluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
	}
	// FLASH VERSION CHECKING
	flash = new Object();
	flash.installed=false;
	flash.version='0.0';
	
	if (navigator.plugins && navigator.plugins.length){
		for (x=0; x<navigator.plugins.length; x++){
			if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1){
				flash.version = navigator.plugins[x].description.split('Shockwave Flash ')[1];
				flash.installed = true;
				break;
			}
		}
	}else if (window.ActiveXObject){
		for (x=2; x<10; x++){
			try{
				oFlash=eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash."+x+"');");
				if (oFlash){
					flash.installed=true;
					flash.version=x+'.0';
				}
			}catch(err){
			}
		}
	}
	flash.intVersion=parseInt(flash.version);
	flash.ver2=(flash.installed && flash.intVersion >= 2) ? true:false;
	flash.ver3=(flash.installed && flash.intVersion >= 3) ? true:false;
	flash.ver4=(flash.installed && flash.intVersion >= 4) ? true:false;
	flash.ver5=(flash.installed && flash.intVersion >= 5) ? true:false;
	flash.ver6=(flash.installed && flash.intVersion >= 6) ? true:false;
	flash.ver7=(flash.installed && flash.intVersion >= 7) ? true:false;
	flash.ver8=(flash.installed && flash.intVersion >= 8) ? true:false;
	flash.ver9=(flash.installed && flash.intVersion >= 9) ? true:false;
	return FlashPluginFound;
}

function detectDirector() { 
	FlashPluginFound = detectPluginFlash('Shockwave','Director'); 
	// if not found, try to detect with VisualBasic
	if(!FlashPluginFound && detectableWithVB) {
		FlashPluginFound = detectActiveXControl('SWCtl.SWCtl.1');
	}
	return FlashPluginFound;
}

function detectPluginFlash() {
	// allow for multiple checks in a single pass
	var daPlugins = detectPluginFlash.arguments;
	// consider FlashPluginFound to be false until proven true
	var FlashPluginFound = 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) {
		FlashPluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
		}
	}
	}
	return FlashPluginFound;
} // detectPluginFlash


// 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('\'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>');
}