var detect = navigator.userAgent.toLowerCase();
var javawsInstalled    = 0;
var javaws142Installed = 0;
var javaws150Installed = 0;
var javaws160Installed = 0;

isIE = "false";

if (navigator.mimeTypes && navigator.mimeTypes.length) {
  x = navigator.mimeTypes['application/x-java-jnlp-file'];
  if (x) {
    javawsInstalled    = 1;
    javaws142Installed = 1;
    javaws150Installed = 1;
    javaws160Installed = 1;
  }
} else {
  isIE = "true";
}

function openGame(args) {
  if (javaws150Installed || javaws160Installed || (navigator.userAgent.indexOf("Gecko") !=-1)) {
    window.location.href='https://www.jecasino.com/casino_game.jnlp'+ (args ? '?'+args : '');
  } else {
    window.open('http://java.sun.com/PluginBrowserCheck', 'downloadjava');
  }
}

/*

<script type="text/vbscript">
<!--
//<![CDATA[
on error resume next
If isIE = "true" Then
  If (Not(IsObject(CreateObject("JavaWebStart.isInstalled"))) And
      Not(IsObject(CreateObject("JavaWebStart.isInstalled.1.4.2.0"))) And
      Not(IsObject(CreateObject("JavaWebStart.isInstalled.1.5.0.0"))) And
      Not(IsObject(CreateObject("JavaWebStart.isInstalled.1.6.0.0")))) Then
    javawsInstalled = 0
  Else
    javawsInstalled = 1
  End If
End If
//]]>
//-->
</script>

if (navigator.mimeTypes && navigator.mimeTypes.length) {
  if (webstartVersionCheck("1.2")) {
    javawsInstalled=1;
  }
  else {
    if (checkPlatform("gecko") || checkPlatform("opera"))  {
      javawsInstalled=1;
    }
    else {
      javawsInstalled=0;
    }
  }
}
else {
  isIE = "true";
}


function webstartVersionCheck(versionString) {
  // Mozilla may not recognize new plugins without this refresh
  if(checkPlatform("win")) {
    if (checkPlatform("gecko")) {
      navigator.plugins.refresh(false);
    }
    else {
      navigator.plugins.refresh(true);
    }
  }

  // First, determine if Web Start is available
  if (navigator.mimeTypes['application/x-java-jnlp-file']) {
    // Next, check for appropriate version family
    for (var i = 0; i < navigator.mimeTypes.length; ++i) {
      pluginType = navigator.mimeTypes[i].type;

      if (pluginType == "application/x-java-applet;version=" + versionString) {
        return true;
      }
    }
  }
}

function checkPlatform(string) {
   return detect.indexOf(string) + 1;
}


function openGame(mode) {
  jnlpArgs = '';

  if(mode == 'demo')
     jnlpArgs = '?mode=demo';

  if (javawsInstalled == 1) 
     window.location.href='https://'+window.location.host+'/casino_game.jnlp' + jnlpArgs;
  else
     window.open('http://java.sun.com/PluginBrowserCheck', 'downloadjava');
     //window.location.href='http://'+window.location.host+'/download_java.html' + jnlpArgs;
}
*/

