// [*]
//
// If this Microsoft Internet Explorer 4.5 for Macintosh, plugins detection is impossible
//
// [*]

function CanDetectPlugins()
{
	if (navigator.appVersion.indexOf("PPC")!=-1 && navigator.userAgent.indexOf("MSIE 4")!=-1)
		return false;
	else
		return true;
}

// [*]
//
// Check if it's an IE Windows Browser
//
// [*]

function IsIE()
{
	if ( (navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1) )
		return true;
	else
		return false;
}


// [*]
//
// Parse plugins collection with strings to find
// User has to pass strings to be found in plugin name and description
// Ex. "Shockwave","Flash","5"
//
// [*]

function IsPlugIn()
{
	// search for the right plugin among all those have been installed
	allFound = false
	plugInsCollection = navigator.plugins
	
	for (i=0;i<plugInsCollection.length;i++)
	{

		// Get plugin description
	        plugInDescription = " " + plugInsCollection[i].description
		plugInName = " " + plugInsCollection[i].name

		for (j=0;j<arguments.length;j++)
		{
			if (plugInDescription.indexOf(" " + arguments[j])!=-1 || plugInName.indexOf(" " + arguments[j])!=-1)
				allFound = true
			else
			{
				allFound = false;
				break;
			}
		}
		
		if (allFound)
			return true;
	}

	return false
}

// [*]
//
// Determines if the latest version of Flash is installed
// RequiredVersion : user may pass a specific version
//
// [*]

function IsFlash(requiredVersion, latestFlashVersion)
{
	// If IE4 Mac, plugins can't be detected
	if(!CanDetectPlugins()) {return false;}

	// User version overrides default version
	if (typeof(requiredVersion) != "undefined" ) { flashSupportedVersion = requiredVersion; }

	// Make sure it's a string
	flashSupportedVersion+="";

	// Check if the supported version of the plugin or upper is installed
	plugInFound = false;
	
	// Check if the lastest version of the plugin is supported
	checkedVersion  = flashSupportedVersion;
	isLatestVersion = checkedVersion == latestFlashVersion;

	while (!plugInFound)
	{
		plugInFound = IsPlugIn("Shockwave","Flash", checkedVersion )
		
		// If we've just checked the lastest existing plugin version, drop the search
		if (isLatestVersion)
		{
			break;
		}
		
		// If we've just checked an old version, search for a newer plugin
		if (!isLatestVersion)
		{
			checkedVersion++;
			isLatestVersion = checkedVersion == latestFlashVersion;
		}
	}
	
	
	
	// Test if ActiveX is installed
	// Caution : successive ActiveX players can cohabit on the same machine (ShockwaveFlash.ShockwaveFlash.4,ShockwaveFlash.ShockwaveFlash.5 etc ...)
	activeXFound     = false
	
	if ( IsIE() && !plugInFound )
	{
		
		try
		{
			activeXFound = IsActiveX("D27CDB6E-AE6D-11cf-96B8-444553540000",flashSupportedVersion);
		}
		catch (e) { activeXFound = false }
	}

	// Send back test result
	if (plugInFound || activeXFound) {return true;} else {return false;}
}

// [*]
//
// Use the Client Capabilities behavior to check IE component installation
//
// [*]

function IsActiveX(activeXClsId,minVersion)
{
	if (IsIE())
	{
		document.body.addBehavior("#default#clientCaps")
		return document.body.isComponentInstalled("{" + activeXClsId + "}","componentId",minVersion)
	}
	else {return false;}
}

// [*]
//
// ver: required version
// lastvet: latestversion
// url: redirect if plugin was not faund
//
// [*]

function RedirectIfNotDetected( ver, lastver, url )
{
	if ( !IsFlash( ver,lastver) ) document.location.href = url;
}

function RedirectIfDetected( ver, lastver, url )
{
	if ( IsFlash( ver,lastver) ) document.location.href = url;
}

function RedirectIf( ver, lastver, urlTrue, urlFalse )
{
	if ( IsFlash( ver,lastver) ) 
	{
		document.location.href = urlTrue;
	}
	else
	{
		document.location.href = urlFalse;
	}
}
