/*
 * Copyright 2004, Peter Rowntree. All Rights Reserved.
 * http://www.hdyn.com/wr/common/contact.php?addr=pr
 */

//returns string on error
function getFlashPlugin(mt)
{
   if(typeof navigator == 'undefined' || typeof navigator.mimeTypes == 'undefined')
      return 0;
   var plugin = navigator.mimeTypes[mt];
   if(typeof plugin == 'undefined')
      return 1;
   plugin=plugin.enabledPlugin;
   if(typeof plugin == 'undefined')
      return 2;
   return plugin;
}

//as array; null on error
function getFlashVersion()
{
   var plugin=getFlashPlugin("application/x-shockwave-flash");
   if(typeof plugin == 'number') //error
      return null;
   var description=plugin.description;
   var vArr=description.match(/[\d.]+/g);
   if(vArr == null || vArr.length < 2)
      return null;
   return vArr;
}

function getFlashError(needScripting)
{
   var mt="application/x-shockwave-flash";
   var plugin=getFlashPlugin(mt);
   if(plugin == null)
      return "<span class='pop'>no Flash plugin installed</span>.";
   if(typeof plugin == 'number')
   {
      switch(plugin)
      {
         case 0:
            return "couldn't find a scriptable Flash plugin; non-standard browser DOM.";
         case 1:
            return "the mime-type: <span class='pop'>"+mt+"</span> is undefined in this browser.";
         case 2:
            return "the mime-type: <span class='pop'>"+mt+"</span> is defined in this browser, but no plugin is enabled for it.";
         default:
            return "<span class='pop'>unknown plugin error</span>.";
      }
   }
   if(!needScripting)
      return "";
   return "this browser has the plugin: <span class='pop'>"+plugin.description+"</span> enabled for mime-type: <span class='pop'>"+mt
      +"</span>, but the plugin is not scriptable. "
      +"Some plugins, in some browsers, can display movies, but can't be scripted. "
      +"Gecko-based browsers, such as FireFox, need version 6.0 r49 or higher on Windows, and the Mac OSX plugin was still not scriptable at version 7.0 r24. "
      +"Also, to be scriptable, the Flash plugin needs to be re-installed after some browser upgrades, even if the plugin is listed as enabled.";
}

function doFlashTest(needScripting,reportErrorsOnly)
{
   var holder=document.getElementById('flashTestHolder');
   if(holder == null)   //test not enabled
      return true;
   var ob=document.getElementById('flashTest');
   var err="";
   if(ob == null || typeof ob.CurrentFrame == 'undefined') 
      err=getFlashError(needScripting);
   if(err != "")
      holder.innerHTML="<span class='pop'>Flash plugin problem detected: </span>"
         +err+" The free Flash plugin can be downloaded at <a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash'>macromedia</a>.";
   else if(!reportErrorsOnly)
      holder.innerHTML="No Flash problems have been detected.";
   return err == "";
}

//to test for >= a specific version
function OKFlashVersion(version,rev)
{
   var pv=getFlashVersion();
   if(pv == null) //error
      return false;
   if(version < pv[0])
      return true;
   if(rev <= pv[1])
      return true;
   return false;
}
