/*********************************************************************
Acrobat/Reader web browser plug-in detection
Author: nyee
Copyright 2005 Adobe Systems, Inc.

Detects ability to display Adobe PDF from within browsers that 
Acrobat or Reader have an integration component
**********************************************************************/

if (window.ActiveXObject) {
  document.writeln('<object id="pdfobj" classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="1" height="1" style="display:none"></object>');
}

AcrobatDetect.prototype.detect = function() {
  var plugins = navigator.plugins;  
  if (plugins && plugins.length) {
  	for (var i = 0; i < plugins.length; i++) {
      if (plugins[i].name.search(/adobe acrobat/i) != -1) {
        var desc = plugins[i].description;
        this.installed = true;
        this.version = parseInt(desc.slice(desc.search(/version /i) + 8).split(' '));
        if (isNaN(this.version)) {
          // not in "version X.XX" format, try "vX.XX" format
          this.rawVersion = desc.slice(desc.search(/v[0-9]/i) + 1).split(' ');
          this.version = parseInt(desc.slice(desc.search(/v[0-9]/i) + 1).split(' '));
        }
        break;
      }
  	}
  } else if (window.pdfobj) {
    if (typeof(pdfobj) == "object") {
      try {
        var components = pdfobj.getVersions().split(',');
        for (var count in components) {
          var singleComponent = components[count].split('=');
          if (singleComponent[0].search(/ewh32/i) != -1) {
            this.installed = true;
            this.version = parseInt(singleComponent[1]);
            break;
          }
        }
      } catch(e) {
      }
    }
  }
  
  if (window.hbx) {
    if (this.isIEWin || this.isMozWin || this.isSafari) {
      if (this.installed) {
        if (!isNaN(this.version)) {
          hbx.hc4 = this.version + '|' + this.uaClean;
        }
      } else {
        hbx.hc4 = "Unknown";
      }
    }
  }
}

/* 
 * class method to strip illegal chars out of the user-agent string 
 *
 * meant for passing to WSS
 */
function AcrobatDetectStripIllegals(a) {
  a = a.split("&").join("-");
  a = a.split("'").join("");
  a = a.split("#").join(" ");
  a = a.split("$").join(" ");
  a = a.split("%").join(" ");
  a = a.split("^").join(" ");
  a = a.split("*").join(" ");
  a = a.split(":").join(" ");
  a = a.split("!").join(" ");
  a = a.split("<").join(" ");
  a = a.split(">").join(" ");
  a = a.split("~").join(" ");
  a = a.split(";").join("_");
  return a;
}
AcrobatDetect.stripIllegals = AcrobatDetectStripIllegals;

function AcrobatDetect() {
  this.ua = navigator.userAgent;
  this.uaClean = AcrobatDetect.stripIllegals(this.ua);
  this.mac = ( this.ua.search(/mac/i) != -1 );
  this.win = ( (this.ua.search(/win/i) != -1) && !this.mac );
  this.ie = ( (this.ua.search(/msie/i) != -1) && (this.ua.search(/opera/i) == -1) );
  this.safari = ( (this.ua.search(/applewebkit/i)!=-1) && (this.ua.search(/safari/i)!=-1) && (this.ua.search(/omniweb/i)==-1) );
  this.moz = ( (navigator.product) && (navigator.product.search(/gecko/i) != -1) && !this.safari ) ? true : false;
  this.isIEWin = this.ie && this.win;
  this.isMozWin = this.moz && this.win;
  this.isSafari = this.safari && this.mac;

  this.installed = false;
  this.version = null;
  this.detect();
}
