/*
 * Java version detector -- deprecated by deployJava.js
 */

var supports14 = false;
var javawsInstalled = 0;  
var javaws142Installed=0;
var javaws150Installed=0;
var m_hostname = "";
var m_version = "";
checkJava();

function checkJava() {
  // Firefox
  if ( navigator.plugins && navigator.plugins.length > 0 ) {
    nps = navigator.plugins;
    for ( i = 0; i < nps.length; i++ ) {
      for ( j = 0; j < nps[i].length; j++ ) {
        mtype = nps[i][j];
        if ( mtype.type.indexOf("application/x-java-applet") >= 0 ) {
          idx = mtype.type.indexOf("version=");
          if ( idx > 0 ) {
            version = mtype.type.substr( idx + 8, 3 );
            if ( version == "1.4" ) { supports14 = true; break; }
          }
        }
      }
    }
  } 
}

function showIEHelp(){
 if ( document.getElementById("IEJavaHelp") ) {
   document.getElementById("IEJavaHelp").style.display = "block";
 }
}
function showQCIEHelp() {
  if ( document.getElementById("QCJavaHelp-IE") ) {
    document.getElementById("QCJavaHelp-IE").style.display = "block";
 }
 hideHTMLQC();
}
function hideHTMLQC(){
   if ( document.getElementById("qcInputBox") )
   document.getElementById("qcInputBox").style.display="none";
}
var installDone;
function silentInstall(){
  document.getElementById("tgt").innerHTML = '<object ' +
'  classid="CLSID:CAFEEFAC-FFFF-FFFF-FFFF-ABCDEFFEDCBA" ' +
'  width="0" height="0"'+ 
'  codebase="/enexdljava.exe"'+
'></object>'
  installDone = setInterval( pollForInstall, 1000 );
}

function qcActiveX(host,key) {
var formatver = m_version;
formatver = m_version.replace(".", ",");
formatver = formatver.replace("RC", ",");
document.getElementById("tgt").innerHTML = '<object ' +
'ID="RunSc" CLASSID="CLSID:5D4CBE94-C365-4cbe-ABF7-B44A7094BDE3" ' +
'CODEBASE="ActivexLauncher.cab#Version=' + formatver + '" WIDTH="0" HEIGHT="0"></OBJECT>';
}

function installQC(host,key){
  qcActiveX(host,key);
  installDone = setInterval( function(){pollForActiveX(key)}, 1500 );
}
function showWinDownload(){
  document.getElementById("winLauncher").style.display="block";
  hideHTMLQC();
}
function linkToDownload(key){
  if(navigator.platform.toLowerCase().indexOf('win')==-1){return;}
  var newLoc = window.location.href;
  if ( newLoc.indexOf("key=") == -1 ) newLoc += "?key=" + encodeURIComponent( key );
  newLoc += ( deployJava.getBrowser() == "MSIE" ) ? "&go=1&activex=1#activex" : "&go=1&dl=1#dl";
  $("a", "#winDownloadLink").attr("href", newLoc );
  $("#winDownloadLink").fadeIn('slow');
}
function appletLauncher(key) {
document.getElementById("tgt").innerHTML = '<applet code="AppletLauncher.class" ' +
'ID="RunSc" archive="AppletLauncher.jar"	width="1" height="1">'+
'<param name="Key" value="'+key+'" />'+
'<param name="host" value="'+m_hostname+'" />'+
'<param name="ver" value="'+m_version+'" />'+
'</applet>';
 setTimeout( function(){linkToDownload(key)}, 4000); // failsafe
}
function disableFormTemp(){
  $("#qcForm input").attr("disabled",true);
  $("#qcForm").attr("disabled",true);
  setTimeout( function(){$('#qcForm input').removeAttr("disabled")}, 5000 );
  setTimeout( function(){$('#qcForm').removeAttr("disabled")}, 5000 );
}
function checkForJava(host, ver, key){
  m_hostname = host;
  m_version = ver;
  var theForm = document.getElementById("qcForm");
  if(navigator.platform.toLowerCase().indexOf('win')==-1){return;}
  var hasTags = ( document.location.href.indexOf("#dl") != -1 || document.location.href.indexOf("&dl=1") != -1  )
  if ( !hasTags ) { hasTags = ( document.location.href.indexOf("#activex") != -1 || document.location.href.indexOf("&activex=1") != -1  ); }
  if ( deployJava.versionCheck('1.4+') && !hasTags ) {
    theForm.onsubmit = function() { if( isValidKey( this.elements["key"].value )) {disableFormTemp();}quickSubmitAppletWindows( this ); } 
    if ( typeof key != "undefined" && key.length > 9 ) {
      disableFormTemp();
      appletLauncher(key);
    }
  } else {
    if ( deployJava.getBrowser() == 'MSIE') {
      if ( document.location.href.indexOf("#activex") != -1 || document.location.href.indexOf("&activex=1") != -1 ) {
        disableFormTemp();
        showQCIEHelp();installQC(host, key);
      }
      theForm.onsubmit = function() {
        if ( !isValidKey( this.elements["key"].value ) ) { markInvalidKey(this.elements["key"]);return false; }
        markValidKey( ff.elements["key"] );
        var newLoc = window.location.href;
        if ( newLoc.indexOf("key=") == -1 ) newLoc += "?key=" + encodeURIComponent( ff.elements["key"].value );
        window.location = newLoc + "&go=1&activex=1#activex";
        return false;
      }
    }
    else {
      if ( document.location.href.indexOf("#dl") != -1 || document.location.href.indexOf("&dl=1") != -1 ) {
        disableFormTemp();
        showWinDownload();
      }
      theForm.onsubmit = function() {
        if ( !isValidKey( this.elements["key"].value ) ) { markInvalidKey(this.elements["key"]);return false; }
        markValidKey( ff.elements["key"] );
        var newLoc = window.location.href;
        if ( newLoc.indexOf("key=") == -1 ) newLoc += "?key=" + encodeURIComponent( ff.elements["key"].value );
        window.location = newLoc + "&go=1&dl=1#dl";
        return false;
      }
    }
  }
}
function pollForActiveX(key) {
  try {
      RunSc.Test();
      clearInterval( installDone );
      if ( document.all ) {
        document.all.RunSc.Run( m_hostname, m_version, key );
      } else {
        document.getElementById("RunSc").Run( m_hostname, m_version, key );
      }
  } catch (NoSuchMethodYet){ }
}
function pollForInstall() {
  if ( deployJava.versionCheck('1.4+') ) {
    clearInterval( installDone );
    showCongrats();
  }
}
function showCongrats() {
  if ( !document.getElementById("IECongrats" ) ) return;
  if ( document.getElementById("IEJavaHelp") ) document.getElementById("IEJavaHelp").style.display = "none";
  document.getElementById("IECongrats").style.display="block";
  setTimeout( function(){if(document.location.href.indexOf("javaDone")<0){document.location.href = document.location.href+"#javaDone";}},1400);
}

