/**
 * PDF Detection Javascript
 *
 * Date: 2005/01/12 23:30:34
 * @author Shaun Thomas <sthomas@townnews.com>
 * @version 1.3
 * @package e-edition
 */

var bHasPDF = false;
var bUseVB = false;

/**
* Determines if the user has a PDF plugin installed.
*
* @return boolean
* True on plugin detection, false otherwise.
*/
function detectPDF()
{
  bHasPDF = false;

  // Before we do any checking, see if there is a cookie set that overrides
  // our checks.  This is in case there's a PDF viewer we're not looking for.

  if (document.cookie.indexOf("eeHasPDF=") > -1)
    return true;

  // The plugin array works for everything except for IE on windows, or
  // Mac IE versions < 5.0.

  if (navigator.plugins != null && navigator.plugins.length > 0)
  {
    var oPlugin = null;

    for (i=0; i < navigator.plugins.length; i++ )
    {
      oPlugin = navigator.plugins[i];
      sTest = oPlugin.name + ' ' + oPlugin.description;
      sTest = sTest.toLowerCase();

      if (sTest.indexOf("adobe acrobat") > -1 || sTest.indexOf("pdf") > -1)
        bHasPDF = true;
    }
  }

  // Win IE has to use an ActiveX control we set up beforehand.

  if (!bHasPDF && bUseVB)
    detectIEPDF();

  return bHasPDF;

} // End function detectPDF.

// Here we write out the VBScript block for MSIE Windows.  This writes a
// function we can call from our detection method, should it be required.

var sUserAgent = navigator.userAgent.toLowerCase();

if ((sUserAgent.indexOf('msie') != -1) && (sUserAgent.indexOf('win') != -1))
{
  document.writeln('<scr' + 'ipt language="VBscript">');

  document.writeln('bUseVB = False');
  document.writeln('If ScriptEngineMajorVersion >= 2 then');
  document.writeln('  bUseVB = True');
  document.writeln('End If');

  document.writeln('Function detectIEPDF()');
  document.writeln('  on error resume next');
  document.writeln('  For i = 1 to 10');
  document.writeln('    bCheck1 = IsObject(CreateObject("PDF.PdfCtrl." & i))');
  document.writeln('    bCheck2 = IsObject(CreateObject("AcroPDF.PDF." & i))');
  document.writeln('    if bCheck1 or bCheck2 Then');
  document.writeln('      bHasPDF = True');
  document.writeln('      break');
  document.writeln('    End If');
  document.writeln('  Next');
  document.writeln('End Function');

  document.writeln('</scr' + 'ipt>');

} // End IE ActiveX code block.
