var oPlugin = new Object();

oPlugin.ActiveXDetected      	= false;
oPlugin.FlashDetected       	= false;
oPlugin.FlashMajorVersion	= 0;
oPlugin.FlashVersionString   	= '';
oPlugin.AuthorwareDetected   	= false;
oPlugin.RealDetected         	= false;
oPlugin.MediaPlayerDetected  	= false;
oPlugin.MediaPlayerVersion   	= 0;
oPlugin.QuickTimeDetected    	= false;
oPlugin.QuickTimeVersion     	= 0;
oPlugin.AcrobatNDetected     	= false;
oPlugin.Acrobat4Detected	= false;
oPlugin.Acrobat78Detected	= false;
oPlugin.AcrobatVersion       	= 0;
oPlugin.CookiesDetected      	= false;
oPlugin.JavaDetected         	= false;
oPlugin.JavaEnabled		= false;
oPlugin.JavaVersion	 	= '';
oPlugin.JavaSubVersion		= 0;
oPlugin.VBScriptDetected     	= false;

//-------------------------------------------------------------------------
// DETECT ALL PLUGINS

function fncDetectPlugins()
{
	fncDetectPluginActiveX();
	fncDetectPluginFlash();
	fncDetectPluginReal();
	fncDetectPluginMediaPlayer();
	fncDetectPluginQuickTime();
	fncDetectPluginAcrobat(); 
	fncDetectCookies();
	fncDetectJava();
	fncDetectVBScript();
}

//-------------------------------------------------------------------------
// DETECT ACTIVEX

function fncDetectPluginActiveX()
{
	if (window.ActiveXObject)
	  oPlugin.ActiveXDetected = true;
	else if (navigator.plugins && navigator.plugins.length)
	{
		// Gecko provides an ActiveX plugin
		for (var x=0; x < navigator.plugins.length; x++)
		{
			if (navigator.plugins[x].name.indexOf('ActiveX') != -1 && window.GeckoActiveXObject)
			{
				oPlugin.ActiveXDetected = true;
				break;
			}
		}
	} 
}

function fncBuildActiveXControl(strProgID)
{
var oActiveXControl = null;

if (oPlugin.ActiveXDetected)
{
	if (oBrowser.isGecko)
	{
		try { oActiveXControl = new GeckoActiveXObject(strProgID); }
		catch (e) {}
	}
	else if (oBrowser.isIE)
	{
		try { oActiveXControl = new ActiveXObject(strProgID); }
		catch (e) {}
	}
}

return oActiveXControl;
}


//-------------------------------------------------------------------------
// DETECT VBSCRIPT
function fncDetectVBScript()
{		
	// Requires detectVBScript.vbs script loaded in <HEAD> of parent document    
	if (typeof(blnVBScriptLoaded) != "undefined")
	{
		if (blnVBScriptLoaded)
			oPlugin.VBScriptDetected = true;
	}
}


//-------------------------------------------------------------------------
// DETECT REAL
function fncDetectPluginReal()
{
	if (oPlugin.ActiveXDetected)
	{ 
		var astrRealProgIDs = new Array("RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)", "rmocx.RealPlayer G2 Control", "RealVideo.RealVideo(tm) ActiveX Control (32-bit)");
		
		for (var i=0; i<=astrRealProgIDs.length-1; i++)
		{
			for (var x=10; x>=1; x-=1)
			{ 
				x = parseFloat(x); 
				var oTmpPlugin = fncBuildActiveXControl(astrRealProgIDs[i] + '.'+x);
				
				if (oTmpPlugin)
				{ 
					oPlugin.RealDetected = true; 
					break;
				} 
			}       
		}
	}
	
	if (navigator.plugins && navigator.plugins.length && !oPlugin.RealDetected)
	{ 
		for (x=0; x<navigator.plugins.length; x++)
		{ 
			if (navigator.plugins[x].name.indexOf('RealPlayer') != -1)
			{ 
			  oPlugin.RealDetected = true; 
			  break; 
			} 
		} 
	} 
	
	if (!oPlugin.RealDetected)
		oPlugin.RealDetected = fncLookupInMimeTypes('realplayer'); 
}


//-------------------------------------------------------------------------
// DETECT MEDIAPLAYER
// It is not possible to detect the presence of the Windows Media Player
//   from within Internet Explorer for the Macintosh.

// MacOSX NS7 - no version - finds "Video for Windows" in plugins list

function fncDetectPluginMediaPlayer()
{
	if (oPlugin.ActiveXDetected)
	{ 
		for (var x=10; x>=1; x-=1)
		{ 
			var oTmpPlugin = null;
			oTmpPlugin = fncBuildActiveXControl('WMPlayer.OCX.'+x);
			
			if (oTmpPlugin)
			{ 
				oPlugin.MediaPlayerDetected = true;       
				// Gecko bug requires double "get versionInfo"
				parseFloat(oTmpPlugin.versionInfo);       
				oPlugin.MediaPlayerVersion = parseFloat(oTmpPlugin.versionInfo); 
				break;
			} 
		}
		
		if (!oPlugin.MediaPlayerDetected)
		{
			var oTmpPlugin = null;
			oTmpPlugin = fncBuildActiveXControl('MediaPlayer.MediaPlayer.1');
			
			if (oTmpPlugin)
			{ 
				oPlugin.MediaPlayerDetected = true;          
				oPlugin.MediaPlayerVersion = 5.2; 
			} 
		}
	}
	else
	{
		if (navigator.mimeTypes && navigator.mimeTypes["application/x-mplayer2"] && navigator.mimeTypes["application/x-mplayer2"].enabledPlugin) {
		   oPlugin.MediaPlayerDetected = true;          
		   oPlugin.MediaPlayerVersion = 5.2; 
		}
		if (navigator.mimeTypes && navigator.mimeTypes["video/x-ms-asf"]) {
		   oPlugin.MediaPlayerDetected = true;          
		   oPlugin.MediaPlayerVersion = 6.3; 
		}
		if (navigator.mimeTypes && navigator.mimeTypes["video/x-ms-wm"] && navigator.mimeTypes["video/x-ms-wmv"]) {
		   oPlugin.MediaPlayerDetected = true;          
		   oPlugin.MediaPlayerVersion = 6.4; 
		}
		if (navigator.mimeTypes && navigator.mimeTypes["application/x-drm-v2"] && navigator.mimeTypes["application/x-drm-v2"].enabledPlugin) {
		   oPlugin.MediaPlayerDetected = true;          
		   oPlugin.MediaPlayerVersion = 7; 
		}
		if (navigator.mimeTypes && navigator.mimeTypes["application/x-ms-wmd"] && navigator.mimeTypes["application/x-ms-wmd"].enabledPlugin) {
		   oPlugin.MediaPlayerDetected = true;          
		   oPlugin.MediaPlayerVersion = 7; 
		}
	}
		
	if (navigator.plugins && navigator.plugins.length && !oPlugin.MediaPlayerDetected)
	{ 
		for (var x=0; x<navigator.plugins.length; x++)
		{ 
			var strPluginName = navigator.plugins[x].name.toLowerCase();
			var strPluginDescription = navigator.plugins[x].description.toLowerCase();
			if (strPluginName.indexOf('windows media') >= 0 || strPluginDescription.indexOf('windows media') >= 0)
			{ 
				oPlugin.MediaPlayerDetected=true; 
				break; 
			} 
		} 
	}
	if (navigator.mimeTypes && navigator.mimeTypes.length && !oPlugin.MediaPlayerDetected)
	{
		for (var x=0; x<navigator.mimeTypes.length; x++)
		{ 
			var strMimeDescription = navigator.mimeTypes[x].description.toLowerCase();
			if (strMimeDescription.indexOf('windows media') >= 0 || strMimeDescription.indexOf('microsoft video') >= 0 || strMimeDescription.indexOf('video for windows') >= 0)
			{ 
				oPlugin.MediaPlayerDetected=true; 
				break; 
			} 
		} 
	} 
}

function fncDetectPluginFlash()
{
	var versionNumArray;
	
	if (navigator.plugins.length)
	{
		for (var x = 0; x < navigator.plugins.length; x++)
		{
			if (navigator.plugins[x].name.indexOf('Flash') != -1)
			{
				oPlugin.FlashDetected = true;
				
				versionNumArray = navigator.plugins[x].description.match(/\d+/g);	// find all numbers of arbitrary length; 0 -> 2 tends to be version data
				oPlugin.FlashMajorVersion = parseInt(versionNumArray[0]);
					
				if (versionNumArray.length == 3)
					oPlugin.FlashVersionString = versionNumArray[0] + "." + versionNumArray[1] + "." + versionNumArray[2];
				else
					oPlugin.FlashVersionString = versionNumArray[0] + ".x";
	
				break;
			} // end if
		} // end for
	} // end if
	
	// IE browsers
	else
	{
		for (var x = 11; x >= 5; x--)
		{
			oPlugin.FlashDetected = detectActiveXControl("ShockwaveFlash.ShockwaveFlash." + x);
	
			if(oPlugin.FlashDetected)
			{
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + x);
				
				if (oPlugin.FlashVersionString = axo.GetVariable("$version"))
				{
					var ieFlashTempArray;
					
					ieFlashTempArray = oPlugin.FlashVersionString.split(" ");
					ieFlashTempArray = ieFlashTempArray[1];
					ieFlashTempArray = ieFlashTempArray.replace(/,/g, ".");
					oPlugin.FlashVersionString = ieFlashTempArray;
					ieFlashTempArray = ieFlashTempArray.split(".");
					
					oPlugin.FlashMajorVersion = parseInt(ieFlashTempArray[0]);				
				}
				
				break;
			}
		}
	}
}

//-------------------------------------------------------------------------
// DETECT QUICKTIME
function fncDetectPluginQuickTime()
{
	if (oPlugin.ActiveXDetected)
	{ 
		for (var x=10; x>=1; x-=1)
		{
			var oTmpPlugin = null;
			oTmpPlugin = fncBuildActiveXControl('QuickTimeCheckObject.QuickTimeCheck.'+x);
			if (oTmpPlugin)
			{ 
			  oPlugin.QuickTimeDetected = oTmpPlugin.IsQuickTimeAvailable(0); 
			  // Gecko bug requires double "get versionInfo"
			  parseFloat(oTmpPlugin.QuickTimeVersion);       
			  oPlugin.QuickTimeVersion=parseInt(oTmpPlugin.QuickTimeVersion.toString(16).substring(0,3))/100; 
			  break;
			}
		}
	} 
	if (navigator.plugins && navigator.plugins.length && !oPlugin.QuickTimeDetected)
	{ 
		for (var x=0; x<navigator.plugins.length; x++)
		{ 
			var strPluginName = navigator.plugins[x].name.toLowerCase();
			var strPluginDescription = navigator.plugins[x].description.toLowerCase();
			
			if (strPluginName.indexOf('quicktime') != -1)
			{ 
				oPlugin.QuickTimeDetected=true; 
				if (strPluginName.indexOf(' ') >= 0)
				{
					var astrPluginName = strPluginName.split(' ');
					for (var i=0;i<astrPluginName.length;i++)
					{
						if (!isNaN(parseInt(astrPluginName[i])))
						{
							oPlugin.QuickTimeVersion = astrPluginName[i];
							break;
						}
					}
				}
				
				break; 
			}
			else if (strPluginDescription.indexOf('quicktime') != -1)
			{
				oPlugin.QuickTimeDetected=true; 
				if (strPluginDescription.indexOf(' ') >= 0)
				{
					var astrPluginName = strPluginDescription.split(' ');
					
					for (var i=0;i<astrPluginName.length;i++)
					{
						if (!isNaN(parseInt(astrPluginName[i])))
						{
							oPlugin.QuickTimeVersion = astrPluginName[i];
							break;
						}
					}
				}
				
				break; 
			}
		} 
	} 
}


//-------------------------------------------------------------------------
// DETECT ACROBAT

function fncDetectPluginAcrobat()
{
	var detectableWithVB = false;
	
	// Mozilla-type browsers
	if (navigator.plugins && navigator.plugins.length)
	{
		for (var x = 0, l = navigator.plugins.length; x < l; ++x )
		{
			// make sure 'Shockwave Flash' isn't pulled by mistake
			if ((navigator.plugins[x].description.indexOf('Adobe PDF') != -1 || navigator.plugins[x].description.indexOf('Adobe Acrobat') != -1) && oPlatform.isWin)
			{
				// pre-8 versions use 'Adobe Acrobat'...v8 reads only 'Adobe PDF'
				if (navigator.plugins[x].description.indexOf('PDF') == -1) // not found
				{
					oPlugin.AcrobatNDetected = true;
					
					oPlugin.AcrobatVersion = parseFloat(navigator.plugins[x].description.split('Version ')[1]);
	
					if (oPlugin.AcrobatVersion.toString().length == 1)
						oPlugin.AcrobatVersion+='.0';
				}
				else
				{
					oPlugin.Acrobat78Detected = true;
					oPlugin.AcrobatVersion = '7.0 or higher';
				}
					
				break;
			} // end if
		} // end for
	} // end if
	
	// IE browsers
	else
	{
		for (x=2; x<10; x++)
		{
			try
			{
				oPlugin.AcrobatNDetected = detectActiveXControl('PDF.PdfCtrl.' + x);
				
				if (oPlugin.AcrobatNDetected)
				{
					oPlugin.AcrobatVersion = x + '.0';
					break;
				}
			}
		
			catch(e) {}
		}
	
		try
		{
			oPlugin.Acrobat4Detected = detectActiveXControl('PDF.PdfCtrl.1');
			
			if (oPlugin.Acrobat4Detected)
				oPlugin.AcrobatVersion='4.0';
		}
		catch(e) {}
		
		try
		{
			oPlugin.Acrobat78Detected = detectActiveXControl('AcroPDF.PDF.1');
			
			if (oPlugin.Acrobat78Detected)
				oPlugin.AcrobatVersion='7 or newer';
		}
		catch(e) {}
	}
}

//-------------------------------------------------------------------------
// JAVA FUNCTIONS

function fncDetectJava()
{
	var javaIndex;
	var javaTestString;
	var javaControlFound = false;
	
	// reset version string
	oPlugin.JavaVersion = "";
	
	if (navigator.javaEnabled())
	{
		oPlugin.JavaEnabled = true;
	
		var version = PluginDetect.getVersion("Java", 'js/getJavaInfo.jar');
								
		if (version != null)
		{
			var re = new RegExp(',', 'g');
			oPlugin.JavaVersion = version.replace(re, '.');
			
			oPlugin.JavaDetected = true;
		}
	}
}

function RescanBrowser()
{
	oPlugin.JavaVersion = '';
	fncGetElementById("idReportJava").innerHTML = '';
	
	fncIsClientOK();
}


//-------------------------------------------------------------------------
// COOKIE FUNCTIONS

function fncDetectCookies()
{
	var exp = new Date(); 
	exp.setTime(exp.getTime() + 1800000); 
	
	// first write a test cookie 
	setCookie("cookies", "cookies", exp, false, false, false); 
	oPlugin.CookiesDetected = (document.cookie.indexOf('cookies') != -1);
	
	// now delete the test cookie 
	exp = new Date(); 
	exp.setTime(exp.getTime() - 1800000); 
	setCookie("cookies", "cookies", exp, false, false, false); 
	}
	
	function setCookie(name, value, expires, path, domain, secure) { 
	var curCookie = name + "=" + escape(value) + 
	((expires) ? "; expires=" + expires.toGMTString() : "") + 
	((path) ? "; path=" + path : "") + 
	((domain) ? "; domain=" + domain : "") + 
	((secure) ? "; secure" : ""); 
	document.cookie = curCookie; 
}



//-------------------------------------------------------------------------
// PLUGIN UTILITY FUNCTIONS

function fncLookupInMimeTypes(strMimeType)
{
	// works for mac ie & nav
	var intNumMatches = 0;
	var strMimeTypes1 = "";
	var strMimeTypes2 = "";
	var strMimeTypes3 = "";
	var strMimeTypes4 = "";
	if (navigator.mimeTypes.length) {
	for (var x=0; x<navigator.mimeTypes.length; x++)
	{ 
	  
	  var strMimeDescription = navigator.mimeTypes[x].description;
	if (strMimeDescription.toLowerCase().indexOf(strMimeType.toLowerCase()) >= 0)
		intNumMatches ++;
	  }
	}
	
	if (intNumMatches > 0) 
		return true;
	else
		return false;
}

function fncLookupInPlugins(strPlugin)
{
	// works for mac ie & nav
	var intNumMatches = 0;
	if (navigator.plugins.length) {
	for (var x=0; x<navigator.plugins.length; x++) { 
	var strMimeDescription = navigator.plugins[x].description;
	if (strMimeDescription.toLowerCase().indexOf(strPlugin.toLowerCase()) >= 0) {
	  intNumMatches ++;
	}
	  }
	}
	
	return (intNumMatches > 0);
}
	
function fncPadNum(number)
{
	var strPaddedNumber = number + "";  // force passed value to string
	while (strPaddedNumber.length < 3) {
	strPaddedNumber = "0" + strPaddedNumber;
	}
	return strPaddedNumber;
}