// this debugger is based on the JavaScript Debug Utility described in http://www.isocra.com/articles/jsdebug.php

// Show the debug window
function TLSshowDebug() {
  //alert('TLSShowDebug'); 
  window.top.debugWindow =
      window.open("",
                  "Debug",
                  "left=0,top=0,width=300,height=700,scrollbars=yes,"
                  +"status=yes,resizable=yes");
  window.top.debugWindow.opener = self;
  // open the document for writing
  window.top.debugWindow.name = "TLS Debug";
  window.top.debugWindow.document.open();
  window.top.debugWindow.document.write(
      "<HTML><HEAD><TITLE>Debug Window</TITLE></HEAD><BODY><PRE>\n");
}

// If the debug window exists, then write to it
function TLSdebug(text) {
 //alert('TLSdebug'); 
  if (! window.top.debugWindow) {
  	TLSshowDebug();
  }
  //if (window.top.debugWindow && ! window.top.debugWindow.closed) {
   if (! window.top.debugWindow.closed) {
   window.top.debugWindow.document.write(text+"\n");
  }
}

// If the debug window exists, then close it
function TLShideDebug() {
  if (window.top.debugWindow && ! window.top.debugWindow.closed) {
    window.top.debugWindow.close();
    window.top.debugWindow = null;
  }
}

function TLStoggleDebug() {
  if (document.getElementById("debugOn").checked) {
    TLSshowDebug();
    debug("Check box checked, switched on debug");
    document.getElementById("checkboxLabel").innerHTML = "The debug window is <b>on</b>";
  } else {
    debug("Check box unchecked, switching off debug");
    TLShideDebug();
    document.getElementById("checkboxLabel").innerHTML = "The debug window is <b>off</b>";
  }
}
