// This script is capable of doing both OTF and NOTF java detection.
// Note that NOTF detection can only be performed if NOTF is enabled.
// Feel free to change this script to fit your own needs.
//
// OTF_NOTF_detection v0.1


// GLOBAL JAVA VARIABLES
var JavaInstalled;                // Tells if java is installed or not
var JavaVersion;                  // Highest installed version
var minVersion = '1,5,0';         // minimum version of Java we are trying to detect
var JavaAllVersions;              // Array of all Java versions installed
var message = '';                 // output message printed to the screen - displays java detection results



// This statement causes Java plugin detection to occur using the jarFile 'getJavaInfo.jar'.
// The detection results are stored in memory for quick retrieval.
// Only the very first java PluginDetect command needs to have the jarFile input argument.
// All subsequent java PluginDetect commands will not need to have the jarFile input argument.
PluginDetect.onJavaDetectionDone(0, 'getJavaInfo.jar');



// Java is being detected using NOTF if isMinVersion == -0.5 or +0.5
//
// Note that PluginDetect interprets PluginDetect.isMinVersion('Java')
// as PluginDetect.isMinVersion('Java', '0')
if (PluginDetect.isMinVersion('Java') == -0.5 || PluginDetect.isMinVersion('Java') == 0.5){
   document.getElementById("result").innerHTML = "Prosze czekać... wykrywanie Javy...";
   message += "<br>"
}

// else Java is being detected using OTF
else{
   message += "<br>"
};



// This function sets the GLOBAL JAVA VARIABLES, and prints the results to the screen
function displayResults(){

  var JavaStatus;

  // -----------------------------------------------------------------------------------
  // Test whether Java is installed or not.


  // Note that PluginDetect.isMinVersion('Java') is equivalent to
  //    PluginDetect.isMinVersion('Java', '0').
  JavaStatus  = PluginDetect.isMinVersion('Java');

  JavaInstalled = JavaStatus >= 0 ? true : false;


  if (PluginDetect.isIE){

     // A Java applet can be put into a web page using the <applet> tag.
     // When you disable Java in the IE browser settings, you disable the
     // <applet> tag - but NOT the <object> tag.
     message += "Java (using &lt;applet&gt; tag) installed/enabled: " +
       (JavaInstalled && navigator.javaEnabled() ? 'true' : 'false') + '<br>';


     // For IE, you can also use the
     //  <object> tag with classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
     // to display a Java applet.
     message += "Java (using &lt;object&gt; tag with ActiveX control) installed/enabled: " +
       (JavaInstalled ? 'true' : 'false') + '<br>';

  }


  // For the non-IE browsers, you can also use <object>/<embed>/<applet> tags for your
  // Java applets.
  else{
    message += "Java installed/enabled: " + (JavaInstalled ? 'true' : 'false') + '<br>';
  };




  // -----------------------------------------------------------------------------------
  // Display the highest installed Java version.

  JavaVersion = PluginDetect.getVersion('Java');

  message += "Highest Installed Java Version: " + JavaVersion + '<br>';


  // ------------------------------------------------------------------------------------
  // Check if some minimum Java version is installed

  JavaStatus = PluginDetect.isMinVersion('Java', minVersion);

  if (JavaStatus == 1){
 
     //message += 'Java ' + minVersion + ' or higher is installed.';
	message = '<a href="http://ilf.if.pw.edu.pl/ilf/hermes/hermes.jnlp">Uruchom aplikację kliencką Hermes</a>';

     // For IE, when javaEnabled() is false, then the <applet> tag is disabled.
     // However, you can still use the <object> tag with classid to display Java, assuming
     // that ActiveX is enabled.
     if (PluginDetect.isIE && !navigator.javaEnabled()){
       message +=
         '<br><br>The &lt;applet&gt; tag is disabled in your browser settings,<br>' +
         'but the &lt;object&gt; tag with classid can still display your applet.'

     }

     message += '<br>'

  }

  else if (JavaStatus == 0){
	message += 'Java zainstalowana jednak nieznana jest jej wersja. Sugerujemy instalację <a href="http://www.java.com/pl/download/">Javy z tej strony</a><br>'     
//message += 'Java installed but version is unknown<br>'
  }


  // Note: JavaStatus is never -0.5 or +0.5 here because by the time that displayResults()
  // is executed, the Java detection will already be completed.
  // Hence there is no need to check for JavaStatus == -0.5 or +0.5


  else if (JavaStatus == -1){
//     message += 'Java version is < ' + minVersion + ' or not installed/enabled<br>'
	message = 'Java nie zainstalowana bądź nie spełnia wymaganej wersji. Sugerujemy instalację <a href="http://www.java.com/pl/download/">Javy z tej strony</a>.<br>'
  }

  else if (JavaStatus == -2){   // ActiveX is disabled
//     message += 'Please enable ActiveX in Internet Explorer so that we can detect your plugins<br>'
  };





  // -----------------------------------------------------------------------------------------
  // Check if more than one Java version is installed.
  // This check will only work if the Deployment Toolkit is installed.
  // This check should only be done AFTER PluginDetect.getVersion() has been called.

  JavaAllVersions = PluginDetect.java.allVersions;  // an array

  if (JavaAllVersions.length>1){
  //  message += 'Deployment Toolkit has detected multiple Java versions: ' + JavaAllVersions.join(" & ") + '<br>';

  };


  // -----------------------------------------------------------------------------------------
  // Print results to the screen.
  // We assume that there is a div element in the <body> such that:
  //         <div id="result">&nbsp;</div>
  document.getElementById("result").innerHTML = message;


};  // end of function displayResults()



// When Java detection has been completed, then run the displayResults() method.
// The onJavaDetectionDone() method can handle both OTF and NOTF.
//
// ON THE FLY (OTF):
//   If the java detection is being performed OTF, then the java detection results are
//   available on the fly and so displayResults() is executed right away.
//   [ie. PluginDetect.isMinVersion('Java') != -0.5 and != +0.5]
//
// NOT ON THE FLY (NOTF):
//   If the java detection is being performed NOTF, then the detection results are
//   not available on the fly, and so we wait until the results are available. 
//   In the meantime your javascript would continue executing
//   commands. And then when the java detection has finally completed (no later than
//   window.onload), the displayResults() function would be executed.
//  [While waiting for the java detection results, we have 
//     PluginDetect.isMinVersion('Java') == -0.5 or +0.5]
//  [After the java detection has completed, we have 
//     PluginDetect.isMinVersion('Java') != -0.5 and != +0.5]
//
// NOTF must be enabled inorder for NOT java detection to occur. If NOTF is disabled then all
// java detection is OTF.
PluginDetect.onJavaDetectionDone(displayResults);



// Execute some function after the window has loaded
PluginDetect.onWindowLoaded(
 function(){
   document.getElementById("result").innerHTML = 
     document.getElementById("result").innerHTML + ""
   }
);







