var uiApp;
var stk;
var open;
  
function LoadPage() {
//Set only Load STK button visible
  document.getElementById("btnLoadSTK").disabled = false;
  document.getElementById("btnUnloadSTK").disabled = true;
  open = false;
  } // end function LoadPage

function Execute(command) {
  try {
    stk.ExecuteCommand(command);
    return true; }
  catch(error) {
    window.alert('Error: ' + command);
    return false; }
  } // end function Execute

function LoadSTK() {
  document.getElementById("btnLoadSTK").disabled = true;
	uiApp = new ActiveXObject("STK9.Application");
  uiApp.visible = true;
  stk = uiApp.personality;
  Execute('New / Scenario Collision');  
 	Execute('OpenHtmlViewer / http://celestrak.com/events/collision/collision.html');
 	open = true;
  document.getElementById("btnUnloadSTK").disabled = false;	
  } // end function LoadSTK

function UnloadSTK() {
  if (open) { uiApp.Quit(); open = false; }
  uiApp = null;
  stk = null;
  document.getElementById("btnLoadSTK").disabled = false;
  document.getElementById("btnUnloadSTK").disabled = true;
  } // end function UnloadSTK
  
function UnloadPage() {
  uiApp = null;
  stk = null;
  } // end function UnloadPage

