// Determines if the latest version of Flash is installed
// requiredVersion : user may pass a specific version
function getFlash(requiredVersion)
{
	pluginFound      = false     // Determines if the latest version of the plugin is installed
	activeXFound     = false     // Determines if the latest version of the ActiveX is installed

	flashSupportedVersion = requiredVersion    // Supported version for Flash plugin and ActiveX
	latestFlashVersion = 7    // Latest Flash version available
	
	if (requiredVersion > latestFlashVersion)
	{
		alert("Cette version du plugin ne peut être testé. La version " + latestFlashVersion + " est la plus récente.");
		requiredVersion = latestFlashVersion;
	}

	// If this Microsoft Internet Explorer 4.5 for Macintosh, plugins detection is impossible
	plgIe4Mac = false
	if (navigator.appVersion.indexOf("PPC")!=-1 && navigator.userAgent.indexOf("MSIE 4")!=-1)
	{
		plgIe4Mac = true
	}

	// Check if it's an IE Windows Browser
	plgIeWin = false
	if ( (navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1) )
	{
		plgIeWin = true
	}

	// If IE4 Mac, plugins can't be detected
	if(plgIe4Mac)
	{
		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 = getPlugIn("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 ...)
	if (plgIeWin)
	{
		activeXFound = getActiveX("ShockwaveFlash.ShockwaveFlash." + flashSupportedVersion)
	}

	// Send back test result
	if (plugInFound || activeXFound)
	{
		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 getPlugIn()
{
	// 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
			}
		}
		
		// Send back the search result
		if (allFound)
		{
			return true
		}
    }
	// Send back the search result
	return false
}


// JSript code to determine if an ActiveX is installed
// ActiveXProgID : ActiveX progID (ex. ShockwaveFlash.ShockwaveFlash.5)

function getActiveX(activeXProgID)
{
	// Run code only if this is IE Win
	if (plgIeWin)
   {
		  try
		  {
			  var flash = new ActiveXObject(activeXProgID);
			  return true;
		  }
		  catch(e)
		  {
		  	  return false;
		  }
	}
}


// Use the Client Capabilities behavior to check IE component installation

function getIEComponent(activeXClsId,minVersion)
{
	if (plgIeWin)
	{
		// Add Client Capabilities behavior to the document body - Must be done at load time
		document.body.addBehavior("#default#clientCaps")
		
		return document.body.isComponentInstalled("{" + activeXClsId + "}","componentId",minVersion)
	}
	else
	{
		return false
	}
}

function WriteIt(text,id)
{
	if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		x.document.open();
		x.document.write(text);
		x.document.close();
	}
}

function TestObjectAW()
{
	ObjState = document.all.AXObjectTest.readyState;
	
	if (ObjState == 4)
	{
		WriteIt(lblActionNone,"AWAction");
		WriteIt(lblEtatOk,"AWEtat");			
	}
	else
	{
		WriteIt(lblEtatNOk,"AWEtat");
		WriteIt(lblAWMsgActionInstall,"AWAction");
	}
}
