/**************************************************
CheckPlugin.js
Coded by
Noel del Rosario
del.freeshell.org
del@freeshell.org
Description
Basic Plugin Detection Script
**************************************************/
// constructor function CheckPlugin
function CheckPlugin(sPluginName, sActiveXControlName, sVersion)
{
   // JavaScript hook
   function detectPlugin(sPluginName, sVersion)
   {
      var blnPluginFound = false;
      
      if (navigator.plugins && navigator.plugins.length > 0) 
      {
         for (var intPluginCount=0; intPluginCount<navigator.plugins.length; intPluginCount++)
         {
            // check to see if the plugin name exists
            if ( (navigator.plugins[intPluginCount].name.indexOf(sPluginName) >= 0) || (navigator.plugins[intPluginCount].description.indexOf(sPluginName) >= 0) )
            {
               // the plugin name has been found
               blnPluginFound = true;
               
               // check for the right version if one is provided
               if ( (sVersion != null) && (sVersion != '') )
               {
                  // version is string literal
                  if ( isNaN(sVersion) )
                  {
                     // check that the version is invalid
                     if (navigator.plugins[intPluginCount].description.indexOf(sPluginName) == -1)
                     {
                        blnPluginFound = false;
                     }
                  }
                  else
                  {
                     // set blnPluginFound to false
                     //blnPluginFound = false;
                     sVersion = parseFloat(sVersion);
                     var sDescription = navigator.plugins[intPluginCount].description.split(" ");
                     for (var intDescriptionCount=0; intDescriptionCount<sDescription.length; intDescriptionCount++)
                     {
                        if ( (!isNaN(sDescription[intDescriptionCount])) && (parseFloat(sDescription[intDescriptionCount]) >= sVersion) )
                        {
                           blnPluginFound = true;
                           break;
                        }
                     }
                  }
               }
               // the plugin has been found, get out of the for loop
               break;
            }
         }
      }
      return blnPluginFound;
   }
   // VBScript hook
   if ( (navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('Opera') == -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('blnDetectableWithVB = False');
      document.writeln('If ScriptEngineMajorVersion >= 2 then');
      document.writeln('  blnDetectableWithVB = 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 blnDetectableWithVB Then');
      document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
      document.writeln('  End If');
      document.writeln('End Function');
      
      document.writeln('</script>');
   }
   this.check = function()
   {
      if ( ((this.pluginName == null) || (this.pluginName == '')) && ((this.activeXControlName == null) || (this.activeXControlName == '')) )
      {
         alert("ERROR:\nPlease set the Plugin's Name or the ActiveX Control's Name.\n\nUSAGE:\nobj.pluginName = \"The Plugin's Name\"\nor\nobj.activeXControlName = \"The ActiveX Control's Name\"");
      }
      else
      {
         // plugin check
         if ( (this.pluginName !=null) && (this.pluginName != '') )
         {
            // check using JavaScript
            this.found = detectPlugin(this.pluginName, this.version);
         }
         // object check
         if ( (this.activeXControlName != null) && (this.activeXControlName != '') )
         {
            if ( (!this.found) && (navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('Opera') == -1) )
            {
               //check using VBScript
               this.found = detectActiveXControl(this.activeXControlName);
            }
         }
      }
   }
   this.reset = function()
   {
      this.pluginName = '';
      this.activeXControlName = '';
      this.version = '';
      this.found = false;
   }
   this.pluginName = sPluginName;
   this.activeXControlName = sActiveXControlName;
   this.version = sVersion;
   this.found = false;
}
