/*****
* 
* Plugin detection Script
* 
* Description:	detects some plugins of user
* Author:		Matthias von Deetzen
* Copyright:	CeWe Color AG & Co OhG
* 
*****/

var detectableWithVB = false;

function PluginDetection()
{
	this.detectJava = function() {
		if (window.navigator.javaEnabled() == true) {
			return true;
		}
		else {
			return false;
		}
	}
	this.detectActiveX = function() {
		return false;
	}
	this.canDetectPlugins = function() {
		if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
			return true;
		} else {
			return false;
		}
	}
	this.detectActiveX = function() {
		try {
			new ActiveXObject("Shell.UIHelper");
		}
		catch (e) {
			return false;
		}
		return true;
	}
	this.detectFlash = function() {
		pluginFound = this.detectPlugin('Shockwave','Flash'); 
		if(!pluginFound && detectableWithVB) {
			pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
		}
		return pluginFound;
	}
	this.detectDirector = function() { 
		pluginFound = this.detectPlugin('Shockwave','Director'); 
		if(!pluginFound && detectableWithVB) {
			pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
		}
		return pluginFound;
	}
	this.detectQuickTime = function() {
		pluginFound = this.detectPlugin('QuickTime');
		if(!pluginFound && detectableWithVB) {
			pluginFound = detectQuickTimeActiveXControl();
		}
		return pluginFound;
	}
	this.detectReal = function() {
		pluginFound = this.detectPlugin('RealPlayer');
		if(!pluginFound && detectableWithVB) {
		pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
			detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
			detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
		}	
		return pluginFound;
	}
	this.detectWindowsMedia = function() {
		pluginFound = this.detectPlugin('Windows Media');
		if(!pluginFound && detectableWithVB) {
			pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
		}
		return pluginFound;
	}

	this.detectPlugin = function() {
		var daPlugins = this.detectPlugin.arguments;
		var pluginFound = false;
		if (navigator.plugins && navigator.plugins.length > 0) {
			var pluginsArrayLength = navigator.plugins.length;
			for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
				var numFound = 0;
				for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
					if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
						(navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
						numFound++;
					}
				}
				if(numFound == daPlugins.length) {
					pluginFound = true;
					break;
				}
			}
		}
		return pluginFound;
	} // detectPlugin

	
	this.java = this.detectJava();
	this.activex = this.detectActiveX();

	if (navigator.appVersion.indexOf("Win")!=-1) this.OSname="windows";
	if (navigator.appVersion.indexOf("Mac")!=-1) this.OSname="macos";
	if (navigator.appVersion.indexOf("X11")!=-1) this.OSname="unix";
	if (navigator.appVersion.indexOf("Linux")!=-1) this.OSname="linux";

	/*
	if (this.canDetectPlugins()) {
		this.flash = this.detectFlash();
		this.director = this.detectDirector();
		this.quicktime = this.detectQuickTime();
		this.realplayer = this.detectReal();
		this.windowsmedia = this.detectWindowsMedia();
	}
	*/
};

// 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('\'and the following function handles QuickTime');
	document.writeln('Function detectQuickTimeActiveXControl()');
	document.writeln('  on error resume next');
	document.writeln('  detectQuickTimeActiveXControl = False');
	document.writeln('  If detectableWithVB Then');
	document.writeln('    detectQuickTimeActiveXControl = False');
	document.writeln('    hasQuickTimeChecker = false');
	document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
	document.writeln('    If IsObject(hasQuickTimeChecker) Then');
	document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
	document.writeln('        detectQuickTimeActiveXControl = True');
	document.writeln('      End If');
	document.writeln('    End If');
	document.writeln('  End If');
	document.writeln('End Function');

	document.writeln('</scr' + 'ipt>');
}

