
// initialize global variables
var pluginFound = false;
var pluginName;

function goURL(redirectURL) 
{
   window.location.href = redirectURL;
   return;
}

function canDetectPlugins() 
{
	// IE doesn't recognize the navigator.plugins array
   if(navigator.plugins && navigator.plugins.length > 0 ) 
   {
      return true;
   } 
   else 
   {
      return false;
   }
}

function detectAcrobat() 
{
   pluginFound = detectPlugin('Acrobat','Reader'); 

   if (!pluginFound && !canDetectPlugins()) // must be IE
   {
   	var adobeVersion = IEPDFVersion();

   	if (adobeVersion != null)
   		pluginFound = true;
   }
   
   return pluginFound;
}

function detectPlugin() 
{
   // allow for multiple checks in a single pass
   var pluginArgs = detectPlugin.arguments;
   var pluginFound = false;
   var numFound = 0;

   // if plugins array is there 
   if (navigator.plugins && navigator.plugins.length > 0) 
   {
      var pluginsArrayLength = navigator.plugins.length;
      for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) 
      {
         // loop through all desired names and check each against the current plugin name
         for(namesCounter=0; namesCounter < pluginArgs.length; namesCounter++) 
         {
				var navPlugin = navigator.plugins[pluginsArrayCounter].name;
				var navDescr = navigator.plugins[pluginsArrayCounter].description;
				var argPlugin = pluginArgs[namesCounter];

            // if desired plugin name is found in either plugin name or description
            if( (navPlugin.indexOf(argPlugin) >= 0) || 
                (navDescr.indexOf(argPlugin) >= 0) ) 
            {
               // this name was found
               numFound++;
            }   
         }
         
         // did we find one ?
         if(numFound > 0) 
         {
            pluginFound = true;
            pluginName = navigator.plugins[pluginsArrayCounter].name;
            break;
         }
      }
   }
   return pluginFound;
} 


/**
* Determines version of the Acrobat Reader plugin for FireFox and Netscape
* @returns the major version of the plugin or null if PDF is not supported
*/
function OtherPDFVersion() 
{
   var version = null;
   var plugin = navigator.plugins["Adobe Acrobat"];
   if (plugin == null) return null;
   if (plugin.description == "Adobe PDF Plug-In For Firefox and Netscape") {
      version = '8.0';
   } 
   else 
   {
      version = plugin.description.split('Version ')[1] + '.0';
   }
   return version;
}

/**
* Determines version of the Acrobat Reader plugin for InternetExplorer.
* @returns the major version of the plugin and returns null if PDF is not supported
*/
function IEPDFVersion() 
{
   var version = null;
   if (hasActiveXObject('AcroPDF.PDF.1')) 
   {
      version = '7.0';
   }
   if (hasActiveXObject('PDF.PdfCtrl.1')) 
   {
      version = '4.0';
   }
   for (var i=2; i<10; i++) 
   {
      if (hasActiveXObject('PDF.PdfCtrl.' + i)) 
      {
         version = i + '.0';
      }
   }
   return version;
}

/**
* Helper method to determine if IE contains an ActiveXObject for the Adobe plugin
* @param name - the name of an ActiveXObject, i.e. the Adobe Reader plugin
* @returns true if the browser contains the ActiveXObject
*/
function hasActiveXObject(name) 
{
   var has = false;
   try 
   {
      activeXObject = new ActiveXObject(name);
      if (activeXObject != null) 
      {
        has = true;
      }
   } 
   catch (e) 
   {
      has = false;
   }
   return has;
}
