/*
 * sysInfo[] for web site
 */

if (!window.sysInfo) {
  var sysInfo = new Array();
}

// We can only set a limited amount of sysInfo information at
// compile time (mainly for release tooltip)

sysInfo["NST_ISO_VERSION"] = "2.11.0";
sysInfo["NST_ISO_DEV_VERSION"] = "2.11.0";

sysInfo["NST_HTML_VERSION"] = "2.11.0";
sysInfo["NST_HTML_BUILD_DATE"] = "Mon Oct 19 15:53:38 UTC 2009";
sysInfo["NST_HTML_BUILD_DATE_SHORT"] = "2009-Oct-19";
sysInfo["NST_HTML_BUILD_DATE_LONG"] = "2009-Oct-19 11:53:38 EDT";

/* NstHtml
 *
 * 
 *
 * Remove/add "ifnew" parameter to next macro definition to disable/enable
 * diagnostic output.
 *
 * 
 *
 *    Class to manage NST HTML specific page related activites such as:
 *
 *    - Building the top/bottom nav bar.
 *    - Transferring values to/from radio buttons.
 *    - Association of a "source file" with the current page.
 *
 * IMPORTANT: You should create at most 1 instance per page.
 *
 * IMPORTANT: The NstHtml.initialize() function must be invoked during
 * the initial processing of the page in order to activate the
 * features which are run after the page is loaded ("onload" features
 * such as the top/bottom nav bars).
 *
 * Example (will most likely be dated):
 *
 * <p id="addToolTip">This paragraph will have a tooltip!</p>
 *
 * <script type="text/javascript">
 * function afterPageLoad() {
 *   // Clear and echo text to console output area
 *   NstConsole.echo("afterPageLoad", true);
 * }
 *
 * function runMeToo() {
 *   // Append to existing debug log
 *   NstConsole.echo("runMeToo");
 * }
 * 
 * NstHtml.initialize();
 * NstDom.registerOnloadHandler(afterPageLoad);
 * NstDom.registerOnloadHandler(runMeToo);
 *
 * NstDom.addToolTip("addToolTip","Here is the "
 *                   + NstDom.ttEmphasis("tooltip", true)
 *                   + " for the paragraph.");
 * </script>
 */

var NstHtml = new function NstHtml() {

  // Indicate that singleton is not yet initialized
  this._Initialized = false;

  // Assume we don't need to add top/bottom nav bars to the document
  this._AddTopNavBar = false;
  this._AddBotNavBar = false;

  // No knowledge of the current source file
  this._SourceFile = false;
}

/* NstHtml.navBars(TOP,BOT)
 *
 *   Call this function to enable/disable the addition of the top and/or
 *   bottom standard AJAX based NST nav bars when the document is loaded.
 *
 *   NstHtml.navBars(true, true); // example of enabling both */

NstHtml.navBars = function(enableTop, enableBot) {
  NstHtml._AddTopNavBar = (enableTop == true);
  NstHtml._AddBotNavBar = (enableBot == true);
}

NstHtml.createValidXmlIcon = function() {
  var url = "/nst/welcome.html";
  var pname = "NST Welcome";
  if (NstDom.isProbeBuild()) {
    url = "/";
    pname = "NST Start";
  }

  // Create default, then tweak for banner area
  var img = document.createElement("img");
  img.src = "/nst/images/valid-xhtml10-blue.png";
  img.style.height = "31px";
  img.style.width = "88px";
  img.className = "w3cIcon";

  // Probe build - disable click to validate page

  if (NstDom.isProbeBuild()) {
    img.onmouseover = function(event) {
      var tt = "This Page Is " + NstDom.ttAction("Valid") + " "
        + NstDom.ttNav("XHTML 1.0 Transitional", true) ;
      domTT_activate(this, event, 'content', tt, 'width', 300);
    }
    return img;
  }

  // On-line variant follows (user can click to validate page)

  img.onmouseover = function(event) {
    var tt = NstDom.ttAction("Validate") + " This Page Using The "
      + NstDom.ttNav("W3C Validatior",true);
    domTT_activate(this, event, 'content', tt, 'width', 300);
  }

  // Make a link so user can right click
  var a = document.createElement("a");
  a.appendChild(img);
  a.href = "http://validator.w3.org/check?uri=referer";
  a.style.height = img.style.height;
  a.style.width = img.style.width;
  
  return a;
}

/* NstHtml.initialize()
 *
 *   Currently, we require one to initialize the NstHtml singleton.
 *   This is due to the fact that this code is included by MANY different
 *   pages which may not be compatible with the NstHtml framework.
 *   NOTE: It does not hurt to invoke this method multiple times (all
 *   subsequent invocations are ignored).
 *
 *   NOTE: This method will call NstDom.activate() for you (and will
 *   take over some of the event handlers - like onload and
 *   onunload). */

NstHtml.initialize = function() {
  if (NstHtml._Initialized) {
     return NstHtml;
  }
  NstHtml._Initialized = true;
  NstDom.activate();

  // Add onmouseover for registered tooltips
  NstDom.registerOnloadHandler(NstHtml.insertNavBars);

  return NstHtml;
}

/* NstHtml.setSourceFile(fname)
 *
 *   Set the fully qualified path to the source file to associate
 *   with the current WUI page being rendered. */

NstHtml.setSourceFile = function(fname) {
  NstHtml._SourceFile = fname;
}

/* NstHtml.getSourceFile()
 *
 *   Get the fully qualified path to the source file to associate
 *   with the current WUI page being rendered (or 'false' if never set). */

NstHtml.getSourceFile = function() {
  return NstHtml._SourceFile;
}

/*
 * ===== BEGIN PRIVATE NstHtml METHODS - YOU SHOULD NOT USE! =====
 */

/* NstHtml.insertNavBars()
 *
 *   Builds the necessary nav bars and inserts them into the documents (the
 *   nav bars created/inserted are controlled by invoking NstHtml.navBars()
 *   PRIOR to the loading of the document. */

NstHtml.insertNavBars = function() {
  var body = document.body;

  // Create and insert new top nav bar if necessary
  if (NstHtml._AddTopNavBar) {
    var tnb = NstHtml.createTopNavBar();
    body.insertBefore(tnb, body.firstChild);

    // If DOM menu available
    if (window.domMenu_data && (window.domMenu_data.size() > 0)) {
      var menuId = 'domMenu_nav';

      // Enable menu bar
      document.onmouseup = function() {
        domMenu_deactivate(menuId);
      }

      var node = document.getElementById(menuId);
      if (node) {
        try {
          domMenu_activate(menuId);
          node.style.display = 'block';
        } catch (e) { }
      }
    }
  }

  // Create and insert new top nav bar if necessary
  if (NstHtml._AddBotNavBar) {
    var bnb = NstHtml.createBottomNavBar();
    body.appendChild(bnb);
  }

  /*
   * Customize NstConsole button area.
   */

  if (window.NstConsole) {
    NstConsole.createFooterArea = function() {

      // Create a <div> for our "footer" addition
      var idiv = document.createElement("div");
      idiv.className = "consoleFooter";
      idiv.id = "customConsoleFooterButtons";
      NstDom.registerSection(idiv.id);

      // Center icons using HTML 4.0 <center>
      var center = document.createElement("center");
      idiv.appendChild(center);

      // Add some standard icons
      center.appendChild(NstDom.createConsoleIconBanner());
      center.appendChild(NstDom.createHomeIconBanner());
      center.appendChild(NstDom.createTopOfPageIconBanner());
      center.appendChild(NstDom.createPrevSectIconBanner());
    
      // Add our new div to the parent node
      return idiv;
    }

    //
    // Add separator between NST WUI and NST JS Console...
    NstConsole.createHeaderArea = function() {
      // This method is called when the console is first shown,
      // lets enable the console to track window resize events
      window.onresize = NstConsole.resizeAndScrollTo;

      // Create a <div> for our "header" addition
      var div = document.createElement("div");
      div.className = "consoleSeparator";

      // Add our new div to the parent node
      return div;
    }

  }
}

/* NstHtml.createTopNavBar()
 *
 *   Builds the top nav bar DOM object (which can then be inserted into
 *   the document). NOTE: This object should only be inserted once as it
 *   sets many unique ID's. Typically, one does not call this directly,
 *   but uses the NstHtml.navBars(true, true) to enable it at page load. */

NstHtml.createTopNavBar = function() {
  var top = document.createElement("div");
  top.id = "top";

  var nb = document.createElement("table");
  top.appendChild(nb);
  nb.cellSpacing = 2;
  nb.cellPadding = 0;
  nb.border = 0;
  nb.width = "100%";
  nb.className = "hstyle";
  /*
  var cg = document.createElement("colgroup");
  nb.appendChild(cg);
  var col = document.createElement("col");
  col.align = "left";
  cg.appendChild(col);
  var col = document.createElement("col");
  col.align = "center";
  cg.appendChild(col);
  var col = document.createElement("col");
  col.align = "right";
  cg.appendChild(col);
  */
  var tbody = document.createElement("tbody");
  nb.appendChild(tbody);

  var tr = document.createElement("tr");
  tbody.appendChild(tr);

  /*
   * Begin left Column of top banner
   * <table>
   *   <tbody>
   *     <tr>
   *       <td>Icons</td>
   *       [<td>SF Icon</td>]
   *       <td>W3C Icon</td>
   *     </tr>
   *   </tbody>
   * </table>
   */

  var td = document.createElement("td");
  td.align = "left";
  td.style.width = "40%";
  tr.appendChild(td);

  // Create a table to align text version and icons
  var ltable = document.createElement("table");
  ltable.cellSpacing = 0;
  ltable.cellPadding = 0;
  ltable.border = 0;
  td.appendChild(ltable);
  var ltbody = document.createElement("tbody");
  ltable.appendChild(ltbody);
  var ltr = document.createElement("tr");
  ltbody.appendChild(ltr);

  /*
   * Nav icons
   */

  var td = document.createElement("td");
  ltr.appendChild(td);
  td.align = "left";
  td.appendChild(NstDom.createEnableFramesIconBanner());
  td.appendChild(NstDom.createDisableFramesIconBanner());
  td.appendChild(NstDom.createHomeIconBanner());

  var validPadding = "4px";

  if (parent.frames.length == 0) {
    var td = document.createElement("td");
    td.align = "left";
    td.style.paddingLeft = "4px";
    validPadding = "6px";
    ltr.appendChild(td);
    var sfIcon = NstDom.createSourceForgeIconBanner();
    sfIcon.className = "footerIcon";
    td.appendChild(sfIcon);
  }

  // Append W3C Validation Icon
  var td = document.createElement("td");
  td.align = "left";
  td.style.paddingLeft = validPadding;
  ltr.appendChild(td);
  var icon = NstHtml.createValidXmlIcon();
  td.appendChild(icon);

  /*
   * Center column of top banner
   */

  var td = document.createElement("td");
  td.style.width = "20%";
  tr.appendChild(td);
  td.className = "sstyle";
  td.align = "center";

  // Create server time area
  var clientTimeStamp = document.createElement("div");
  td.appendChild(clientTimeStamp);
  clientTimeStamp.onmouseover = function(event) {
    var tstamp = new Date(startTime);
    var maxlen = 0;
    var tt = "<div class='line1px'><span style='color: #00ccff;'>"
      + "Time"
      + "</span> Of "
      + "&#39;<span style='color: #33ff00;'>"
      + "Page Creation"
      + "</span>&#39;</div><table>";

    var s = tstamp.toGMTString();
    if (s.length > maxlen) maxlen = s.length;
    tt += buildInfoTableRow("GMT", s);

    s = tstamp.toLocaleString();
    if (s.length > maxlen) maxlen = s.length;
    tt += buildInfoTableRow("Locale", s);

    s = tstamp.toString();
    if (s.length > maxlen) maxlen = s.length;
    tt += buildInfoTableRow("JavaScript", s);

    tt += "</table>";
   
    domTT_activate(this, event, 'content', tt,
                   'width', calcDomTTLen(maxlen, 100),
                   'id', 'bannerHeaderTime');
  }

  // Add date and time values to time area
  var tstamp = new Date(startTime);

  var clientDate = document.createElement("div");
  clientTimeStamp.appendChild(clientDate);
  clientDate.appendChild(document.createTextNode(tstamp.toDateString()));

  var clientTime = document.createElement("div");
  clientTimeStamp.appendChild(clientTime);
  var tstr = tstamp.toLocaleTimeString();
  if (isChrome()) {
    // Chrome Beta release has a very long locale time format
    // use non-breaking characters to prevent wrapping
    tstr = tstr.replace(/ /g, "\u00a0")
    tstr = tstr.replace(/-/g, "\u2011")
  }
  clientTime.appendChild(document.createTextNode(tstr));

  /*
   * Right Column of top banner (big NST icon)
   */

  var td = document.createElement("td");
  td.style.width = "40%";
  td.align = "right";
  tr.appendChild(td);

  var spage = NstDom.createStartPageIconBanner();
  td.appendChild(spage);

  // Try to force cell's height to height of image icon
  // td.style.height = spage.style.height;

  /*
   * Append insertion point for menu (if DOM menus are availabe)
   */
  if (window.domMenu_data && (window.domMenu_data.size() > 0)) {
    var menuBar = document.createElement("div");
    menuBar.id = "domMenu_nav";
    top.appendChild(menuBar);
  }
  
  return top;
}

/* NstHtml.createBottomNavBar()
 *
 *   Builds the bottom nav bar DOM object (which can then be inserted into
 *   the document). NOTE: This object should only be inserted once as it
 *   sets many unique ID's. Typically, one does not call this directly,
 *   but uses the NstHtml.navBars(true, true) to enable it at page load. */

NstHtml.createBottomNavBar = function() {
  var nb = document.createElement("table");
  nb.id = "bottom";
  NstDom.registerSection(nb.id);
  nb.width = "100%";
  nb.border = 0;
  nb.summary = "NST Bottom Banner";
  nb.className = "fstyle";

  var cg = document.createElement("colgroup");
  nb.appendChild(cg);
  var col = document.createElement("col");
  col.style.width = "40%";
  cg.appendChild(col);
  var col = document.createElement("col");
  col.style.width = "20%";
  cg.appendChild(col);
  var col = document.createElement("col");
  col.style.width = "40%";
  cg.appendChild(col);

  var tbody = document.createElement("tbody");
  nb.appendChild(tbody);

  var tr = document.createElement("tr");
  tbody.appendChild(tr);

  /*
   * Left size of footer bar (copyright and domain link)
   */

  // Copyright symbol with link to license
  var td = document.createElement("td");
  tr.appendChild(td);
  td.align = "left";
  var a = document.createElement("a");
  a.className = "fstyle";
  a.href = "/nst/nstlicense.html";
  a.appendChild(document.createTextNode("\u00a9"));
  a.onmouseover = function(event) {
    domTT_activate(this, event, 'content', NstDom.ttNote("Display",false) 
                   + " The "
                   + NstDom.ttEmphasis("NST License",true)
                   + " Page.<br /><br />"
                   + NstDom.ttNote("Copyright")
                   + " &#169; "
                   + NstDom.ttEmphasis("2003",false) + " - "
                   + NstDom.ttEmphasis("2009",false) + " "
                   + NstDom.ttValue("Ronald W. Henderson",false)
                   + " and "
                   + NstDom.ttValue("Paul Blankenbaker",false),
                   'width', 460);
  }
  td.appendChild(a);
  td.appendChild(document.createTextNode("\u00a0"));

  // Copyright year span with tooltip
  var span = document.createElement("span");
  span.className = "fstyle";
  span.onmouseover = function(event) {
    domTT_activate(this, event, 'content', NstDom.ttEmphasis("NST",true) 
                   + " Development " + NstDom.ttNote("Life Cycle") 
                   + " For This Release: "
                   + NstDom.ttValue("2003",true)
                   + " - " + NstDom.ttValue("2009",true),
                   'width', 420);
  }
  span.appendChild(document.createTextNode("2003-2009"));
  td.appendChild(span);
  td.appendChild(document.createTextNode("\u00a0"));

  // Domain with link to main web site
  var a = document.createElement("a");
  td.appendChild(a);
  a.className = "icon";
  a.appendChild(document.createTextNode("networksecuritytoolkit.org"));
  a.className = "fstyle";
  a.href = "http://www.networksecuritytoolkit.org";
  a.target = "_top";
  a.onmouseover = function(event) {
    domTT_activate(this, event, 'content', NstDom.ttNote("Go",false) 
                   + " To The " + NstDom.ttEmphasis("NST Home Page",true) 
                   + " On The "
                   + NstDom.ttNote("Internet",false) + ".",
                   'width', 300);
  }
  

  /*
   * Center portion of footer (empty)
   */
  var td = document.createElement("td");
  tr.appendChild(td);
  td.align = "center";
  td.className = "fstyle";

  /*
   * Right side of footer (version and nav buttons)
   */

  var td = document.createElement("td");
  tr.appendChild(td);
  td.align = "right";
  td.className = "fstyle";

  // Create a table to align text version and icons
  var rtable = document.createElement("table");
  td.appendChild(rtable);
  var rtbody = document.createElement("tbody");
  rtable.appendChild(rtbody);
  var rtr = document.createElement("tr");
  rtbody.appendChild(rtr);
  
  // NST Version information (if sysInfo is available)
  if (window.sysInfo) {
    var vinfo = document.createElement("td");
    vinfo.className = "fstyle";
    vinfo.style.verticalAlign = "middle";
    vinfo.onmouseover = function(event) {
      domTT_activate(this, event, 'content', nstDistoReleaseTT(), 'width', 360,
                     'id', 'bannerFooterNSTRelease');
    }
    vline = "NST\u00a0v" + sysInfo['NST_ISO_VERSION']
      + "\u00a0(" + sysInfo['NST_HTML_BUILD_DATE_SHORT'] + ")";
    vinfo.appendChild(document.createTextNode(vline));
    rtr.appendChild(vinfo);
  }

  // Add some standard icons
  var toolbar = document.createElement("td");
  rtr.appendChild(toolbar);
  if (NstHtml._SourceFile) {

    // Assume under "html" directory unless path starts with '/'
    // determine full URL to SourceForge viewer and relative
    // path for tooltip
    var sfile = NstHtml._SourceFile;
    var surl = "http://nst.cvs.sourceforge.net/nst";
    if (sfile[0] == '/') {
      surl += sfile;
      var ttname = sfile.substring(1);
    } else {
      surl = surl + "/html/" + sfile;
      var ttname = "html/" + sfile;
    }
    surl += "?view=markup";

    toolbar.appendChild(NstDom.createSourceViewIconBanner(surl, ttname));
  }

  if (window.NstConsole) {
    toolbar.appendChild(NstDom.createConsoleIconBanner());
  }
  toolbar.appendChild(NstDom.createHomeIconBanner());
  toolbar.appendChild(NstDom.createTopOfPageIconBanner());
  toolbar.appendChild(NstDom.createPrevSectIconBanner());
  
  return nb;
}

/*
 * ===== END PRIVATE NstHtml METHODS - YOU SHOULD NOT USE! =====
 */

/*
 * NST Links section name array and init display state... */
NstHtml.nst_link_section_state = new Array();
NstHtml.nst_link_section_state['NST'] = 'none';
NstHtml.nst_link_section_state['Network'] = 'none';
NstHtml.nst_link_section_state['Security'] = 'none';
NstHtml.nst_link_section_state['WirelessTech'] = 'none';
NstHtml.nst_link_section_state['LDAPTech'] = 'none';
NstHtml.nst_link_section_state['SNMP'] = 'none';
NstHtml.nst_link_section_state['WebServices'] = 'none';
NstHtml.nst_link_section_state['GPS'] = 'none';
NstHtml.nst_link_section_state['Java'] = 'none';
NstHtml.nst_link_section_state['General'] = 'none';
NstHtml.nst_link_section_state['Developer'] = 'none';
NstHtml.nst_link_section_state['nstdevdocs'] = 'none';
NstHtml.nst_link_section_state['htmldocs'] = 'none';
NstHtml.nst_link_section_state['javascriptdocs'] = 'none';
NstHtml.nst_link_section_state['phpdocs'] = 'none';
NstHtml.nst_link_section_state['w3cdocs'] = 'none';


/*
 * NstHtml.collapseNLSections()
 *
 *  Collapse all NST link sections...
 */
NstHtml.collapseNLSections = function() {
  for (var nls in NstHtml.nst_link_section_state) {
  //
  // get access to section icon folder image node...
    var icon = document.getElementById(nls).icon;
    if (!icon) {
      continue;
    }
  //
  // get access to the section content area...
    var entity = document.getElementById(nls + '-area')
    if (!entity) {
      continue;
    }

  //
  // collapse section...
    icon.src = '/nst/images/folder.gif';
    entity.style.display = 'none';
  }
}

/*
 * NstHtml.expandNLSections()
 *
 *  Expand all NST link sections...
 */
NstHtml.expandNLSections = function() {
  for (var nls in NstHtml.nst_link_section_state) {
  //
  // get access to section icon folder image node...
    var icon = document.getElementById(nls).icon;
    if (!icon) {
      continue;
    }
  //
  // get access to the section content area...
    var entity = document.getElementById(nls + '-area')
    if (!entity) {
      continue;
    }

  //
  // expand section...
    icon.src = '/nst/images/folder.open.gif';
    entity.style.display = 'block';
  }
}

/*
 * NstHtml.setNLSectionOpen(nls)
 *
 * Set NST link section 'Hide/Show' state to open...
 *
 * nls - NST link section name to open 'block'... */
NstHtml.setNLSectionOpen = function(nls) {

  //
  // get access to icon folder...
  var icon = document.getElementById(nls).icon;
  if (!icon) {
    return null;
  }

  //
  // get access to the content area...
  var entity = document.getElementById(nls + '-area')
  if (!entity) {
    return null;
  }

  //
  // expand section...
  icon.src = '/nst/images/folder.open.gif';
  entity.style.display = 'block';

  //
  // chk to expand main developer section...
  if ((nls == 'nstdevdocs')     || (nls == 'htmldocs') ||
      (nls == 'javascriptdocs') || (nls == 'phpdocs')  ||
      (nls == 'w3cdocs')) {
    icon = document.getElementById('Developer').icon;
    entity = document.getElementById('Developer-area')
    icon.src = '/nst/images/folder.open.gif';
    entity.style.display = 'block';
  }
}
