﻿// JScript File
var acrobatPDFversion;
if ($.browser.msie) {
  acrobatPDFversion = IEPDFVersion();
}else{
  acrobatPDFversion = OtherPDFVersion();
}

/**
* Determines version of the Acrobat Reader plugin for FireFox and Netscape
* @returns the major version of the plugin and returns 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 with a given name
* @param name - the name of an ActiveXObject
* @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;
}
