state_NOT_INITIALIZED = 0;
state_INITIALIZED = 1;
state_PATCHING = 2;
state_PATCH_COMPLETE = 3;
state_LAUNCHING = 4;
state_LAUNCH_COMPLETE = 5;
state_RUNNING = 6;
state_RUN_COMPLETE = 7;
state_ERROR_ABORT = 8;

function pluginGetLaunchStatus(doc) {
 var theLaunchPlugin = doc.getElementById('launchplugin');
 if (theLaunchPlugin == null) {
    return state_NOT_INITIALIZED;
 }

 var launchStatus = theLaunchPlugin.getLaunchStatus();
 return launchStatus;
}

function toFront(doc) {
 var theLaunchPlugin = doc.getElementById('launchplugin');
 if (theLaunchPlugin != null) {
    theLaunchPlugin.bringGameToFront();
 }
}

function pluginGetPatchPercentDone(doc) {
 var theLaunchPlugin = doc.getElementById('launchplugin');
 var percentDone = theLaunchPlugin.getPatchPercentDone();
 return percentDone;
}
function pluginAbortGame(doc) {
 var theLaunchPlugin = doc.getElementById('launchplugin');
 if ( theLaunchPlugin != null) {
    theLaunchPlugin.abortGame();
 }
}
function writePluginParams(downloadHost, mission, hostName, playerId, version) {
 document.write('<param name="game" value="gunfight"/>');
 document.write('<param name="Mission" value="'+mission+'">');
 document.write('<param name="downloadURL" value="http://'+downloadHost+'/downloads/">');
 document.write('<param name="server" value="'+hostName+'">');
 document.write('<param name="key" value="'+playerId+'">');
 document.write('<param name="version" value="'+version+'">');
}
function writePlugin(downloadHost, mission, hostName, playerId, version) {
 document.write('<object id="launchplugin" width="0" height="0" ');
 if (window.ActiveXObject) { // browser supports ActiveX
  document.write('classid="CLSID:601543EE-C08C-11DC-8EA0-848C56D89593" >');
 } else { // browser must support Netscape Plugin API
  document.write('type="application/x-tfg-launch" >');
 }
 writePluginParams(downloadHost, mission, hostName, playerId, version);
 document.write('<\/object>');
}