// JavaScript Document

// Copyright © 2000 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

// initialize a variable to test for JavaScript 1.1.
// which is necessary for the window.location.replace method
var javascriptVersion1_1 = false;

javascriptVersion1_1 = true;


// initialize global variables
var detectableWithVB = false;
var pluginFound = false;


function goURL(daURL) {
  // if the browser can do it, use replace to preserve back button
  if(javascriptVersion1_1) {
  window.location.replace(daURL);
  } else {
  window.location = daURL;
  }
  return;
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
  // check for redirection
  if( redirectURL && ((pluginFound && redirectIfFound) || 
  (!pluginFound && !redirectIfFound)) ) {
  // go away
  goURL(redirectURL);
  return pluginFound;
  } else {
  // stay here and return result of plugin detection
  return pluginFound;
  }  
}

function canDetectPlugins() {
  if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
  return true;
  } else {
  return false;
  }
}

function detectFlash(redirectURL, redirectIfFound) {
  pluginFound = detectPlugin('Shockwave','Flash'); 
  // if not found, try to detect with VisualBasic
  if(!pluginFound && detectableWithVB) {
  pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
  }
  // check for redirection
  return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectDirector(redirectURL, redirectIfFound) { 
  pluginFound = detectPlugin('Shockwave','Director'); 
  // if not found, try to detect with VisualBasic
  if(!pluginFound && detectableWithVB) {
  pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
  }
  // check for redirection
  return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectQuickTime(redirectURL, redirectIfFound) {
  pluginFound = detectPlugin('QuickTime');
  // if not found, try to detect with VisualBasic
  if(!pluginFound && detectableWithVB) {
  pluginFound = detectQuickTimeActiveXControl();
  }
  return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectReal(redirectURL, redirectIfFound) {
  pluginFound = detectPlugin('RealPlayer');
  // if not found, try to detect with VisualBasic
  if(!pluginFound && detectableWithVB) {
  pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
  }  
  return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
  pluginFound = detectPlugin('Windows Media');
  // if not found, try to detect with VisualBasic
  if(!pluginFound && detectableWithVB) {
  pluginFound = detectActiveXControl('wmplayer.ocx');
  }
  return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
  // allow for multiple checks in a single pass
  var daPlugins = detectPlugin.arguments;
  // consider pluginFound to be false until proven true
  var pluginFound = false;
  // if plugins array is there and not fake
  if (navigator.plugins && navigator.plugins.length > 0) {
  var pluginsArrayLength = navigator.plugins.length;
  // for each plugin...
  for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
    // loop through all desired names and check each against the current plugin name
    var numFound = 0;
    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
  // if desired plugin name is found in either plugin name or description
  if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
    // this name was found
    numFound++;
  }   
    }
    // now that we have checked all the required names against this one plugin,
    // if the number we found matches the total number provided then we were successful
    if(numFound == daPlugins.length) {
  pluginFound = true;
  // if we've found the plugin, we can stop looking through at the rest of the plugins
  break;
    }
  }
  }
  return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -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('detectableWithVB = False');
  document.writeln('If ScriptEngineMajorVersion >= 2 then');
  document.writeln('  detectableWithVB = 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 detectableWithVB Then');
  document.writeln('   detectActiveXControl = IsObject(CreateObject(activeXControlName))');
  document.writeln('  End If');
  document.writeln('End Function');

  document.writeln('\'and the following function handles QuickTime');
  document.writeln('Function detectQuickTimeActiveXControl()');
  document.writeln('  on error resume next');
  document.writeln('  detectQuickTimeActiveXControl = False');
  document.writeln('  If detectableWithVB Then');
  document.writeln('  detectQuickTimeActiveXControl = False');
  document.writeln('  hasQuickTimeChecker = false');
  document.writeln('  Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
  document.writeln('  If IsObject(hasQuickTimeChecker) Then');
  document.writeln('    If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
  document.writeln('    detectQuickTimeActiveXControl = True');
  document.writeln('    End If');
  document.writeln('  End If');
  document.writeln('  End If');
  document.writeln('End Function');

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

// END APPLE CODE


/*******************************
  Flash Object Usage:
  
  <script type="text/javascript">
    var flash_obj = new Flash(file, width, height, [version, [no_flash_html, [query string]]]);
    flash_obj.displayFlash();
  </script>

*******************************/

var flashVersion = 0; // required

function Flash(_file, _width, _height, _version, _no_flash, _query) {
  this.file = _file;
  this.width = _width;
  this.height = _height;
  this.default_version = 6;
  this.default_query = '';
  this.required_version = (arguments.length > 3) ? arguments[3] : this.default_version;
  this.query = (arguments.length > 5) ? arguments[5] : this.default_query;
  this.latest_flash_version = 13;
  this.agent = navigator.userAgent.toLowerCase(); 
  this.flashVersion_DONTKNOW = -1;
  this.flash_detected = false;
  this.default_no_flash = '';
  this.default_no_flash += '<table border="0" align="left" cellpadding="0" cellspacing="0" style="width:'+this.width+'px; height:'+this.height+'px; text-align:center; vertical-align:middle;">'+"\n";
  this.default_no_flash += '  <tr>'+"\n";
  this.default_no_flash += '    <td>'+"\n";
  this.default_no_flash += '      <h2>The Flash Player '+this.required_version+' or higher <br />is needed to display this content.</h2>'+"\n";
  this.default_no_flash += '      <p><a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW" target="_blank">Download the Flash Player here.</a> <br />'+"\n";
  this.default_no_flash += '      It will only take a minute :)</p>'+"\n";
  this.default_no_flash += '    </td>'+"\n";
  this.default_no_flash += '  </tr>'+"\n";
  this.default_no_flash += '</table>'+"\n";
  this.flash_content = '';
  this.flash_content += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+this.width+'" height="'+this.height+'">'+"\n";
  this.flash_content += '  <param name="movie" value="'+this.file+this.query+'" />'+"\n";
  this.flash_content += '  <param name="quality" value="high" />'+"\n";
  this.flash_content += '  <param name="wmode" value="transparent" />'+"\n";
  this.flash_content += '  <embed wmode="transparent" src="'+this.file+this.query+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+this.width+'" height="'+this.height+'"></embed>'+"\n";
  this.flash_content += '</object>'+"\n";
  if (arguments.length > 4) {
    if (arguments[4] != "") {
      this.no_flash = arguments[4];
    } else {
      this.no_flash = this.default_no_flash;
    }
  }
  
  // Flash Version Detector  v1.2.1
  // documentation: http://www.dithered.com/javascript/flash_detect/index.html
  // license: http://creativecommons.org/licenses/by/1.0/
  // code by Chris Nott (chris[at]dithered[dot]com)
  // with VBScript code from Alastair Hamilton (now somewhat modified)
  this.getFlashVersion = function() {
    // NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
    if (navigator.plugins != null && navigator.plugins.length > 0) {
      var flashPlugin = navigator.plugins['Shockwave Flash'];
      if (typeof(flashPlugin) == 'object') { 
        for (var i = this.latest_flash_version; i >= 3; i--) {
          if (flashPlugin.description.indexOf(i + '.') != -1) {
            flashVersion = i;
            break;
          }
        }
      }
    } // IE4+ Win32:  attempt to create an ActiveX object using VBScript
    else if (this.agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && this.agent.indexOf("win")!=-1 && this.agent.indexOf("16bit")==-1) {
       var doc = '<scr' + 'ipt language="VBScript"\> \n';
        doc += 'On Error Resume Next \n';
        doc += 'Dim obFlash \n';
        doc += 'For i = ' + this.latest_flash_version + ' To 3 Step -1 \n';
        doc += '   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';
        doc += '   If IsObject(obFlash) Then \n';
        doc += '      flashVersion = i \n';
        doc += '      Exit For \n';
        doc += '   End If \n';
        doc += 'Next \n';
        doc += '</scr' + 'ipt\> \n';
        document.writeln(doc);
    }
    else if (this.agent.indexOf("webtv/2.5") != -1) flashVersion = 3;  // WebTV 2.5 supports flash 3
    else if (this.agent.indexOf("webtv") != -1) flashVersion = 2; // older WebTV supports flash 2
    else {
      flashVersion = this.flashVersion_DONTKNOW;  // Can't detect in all other cases
    }
    return flashVersion;
  }

  this.flashFound = function(_version, _required) {
    if (_version >= _required) {
      this.flash_detected = true;
      return true;
    } else {
      return false;
    }
  }

  this.displayFlash = function() { 
    if (this.flash_detected) {
      document.writeln( this.flash_content );
    } else {
      document.writeln( this.no_flash );
    }
  }
  
  this.flash_version = this.getFlashVersion();
  this.flash_detected = this.flashFound(this.flash_version, this.required_version);
  
} // end flash object

// Adobe Acrobat Detection  v1.0
// http://www.dithered.com/javascript/acrobat_detect/index.html
// code by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)


  var acrobatVersion = 0;
  function getAcrobatVersion() 
  {
    var agent = navigator.userAgent.toLowerCase(); 
    
    // NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Acrobat plugin in plugin array
    if (navigator.plugins != null && navigator.plugins.length > 0) 
    {
      for (i=0; i < navigator.plugins.length; i++ ) 
      {
         var plugin = navigator.plugins[i];
         if (plugin.name.indexOf("Adobe Acrobat") > -1) 
         {
           acrobatVersion = parseFloat(plugin.description.substring(30));                        
         }         
      }      
    }   
    // IE4+ Win32:  attempt to create an ActiveX object using VBScript
    else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) 
    {
        //document.write('<scr' + 'ipt language="VBScript"\> \n');                            
        //document.write('on error resume next \n');                     
        //document.write('dim obAcrobat \n');        
        //document.write('set obAcrobat = CreateObject("PDF.PdfCtrl.5") \n');            
        //document.write('if IsObject(obAcrobat) then \n');        
            //document.write('acrobatVersion = 5 \n');
        //document.write('else \n');
            //document.write('set obAcrobat = CreateObject("PDF.PdfCtrl.1") \n');        
            //document.write('if acrobatVersion < 5 and IsObject(obAcrobat) then \n');        
                //document.write('acrobatVersion = 4 \n');        
            //document.write('end if \n');                
        //document.write('end if \n');            
        //document.write('alert(acrobatVersion)\n');        
        //document.write('</scr' + 'ipt\> \n');
                
        //===========activex don't support pdf control 6 and above=================
        document.write('<scr' + 'ipt language="VBScript"\> \n');                            
        document.write('on error resume next \n');                     
        document.write('dim obAcrobat \n');
        document.write('set obAcrobat = CreateObject("AcroPDF.PDF.1") \n');
        document.write('if IsObject(obAcrobat) then \n');        
        document.write('acrobatVersion = 7 \n');                                
        document.write('else \n');
        document.write('set obAcrobat = CreateObject("PDF.PdfCtrl.6") \n');            
        document.write('if IsObject(obAcrobat) then \n');        
        document.write('acrobatVersion = 6 \n');            
        document.write('else \n');
        document.write('set obAcrobat = CreateObject("PDF.PdfCtrl.5") \n');            
        document.write('if IsObject(obAcrobat) then \n');        
        document.write('acrobatVersion = 5 \n');
        document.write('else \n');
        document.write('set obAcrobat = CreateObject("PDF.PdfCtrl.1") \n');        
        document.write('if acrobatVersion < 5 and IsObject(obAcrobat) then \n');        
        document.write('acrobatVersion = 4 \n');        
        document.write('end if \n');                
        document.write('end if \n');
        document.write('end if \n');
        document.write('end if \n');                    
        //document.write('alert(acrobatVersion)\n');        
        document.write('</scr' + 'ipt\> \n');
    }
    // Can't detect in all other cases
    else 
    {
      acrobatVersion = acrobatVersion_DONTKNOW;
    }
    //alert(acrobatVersion);
    return acrobatVersion;
  }

acrobatVersion_DONTKNOW = -1;
