// Original script: Copyright (c) 1996-1997 Tomer Shiran. All rights reserved.
// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
// Improvements: Copyright (c) 2008 Ralph Sickinger, WILLCOR, Inc.

var caution = false
var nodecnt = 0
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "")
  if (!caution || (name + "=" + escape(value)).length <= 4000)
    document.cookie = curCookie
  else
    if (confirm("Cookie exceeds 4KB and will be cut!"))
      document.cookie = curCookie
}
function getCookie(name) {
  var prefix = name + "="
  var cookieStartIndex = document.cookie.indexOf(prefix)
  if (cookieStartIndex == -1)
    return null
  var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
  if (cookieEndIndex == -1)
    cookieEndIndex = document.cookie.length
  return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT"
  }
}
function fixDate(date) {
  var base = new Date(0)
  var skew = base.getTime()
  if (skew > 0)
    date.setTime(date.getTime() - skew)
}
function item(parent, caption, file, id, depth) {
  if (parent) { nodecnt++ }

  this.parent = parent
  this.text = caption
  this.id = id
  this.file = file
  this.depth = depth
}
function makeArray(length) {
  this.length = length
}
function makeDatabase() {
  var ix = 0
  outline = new makeArray(34)

//        outline[0] = new item(false, "<i>Summary</i>","summary","",0)

        outline[ix] = new item(false, "Foreword","index","",0)
        ix++
        outline[ix] = new item(false, "Introduction","2","",0)
        ix++
        outline[ix] = new item(false, "1.0  Scope","3","",0)
        ix++
        outline[ix] = new item(false, "2.0  Referenced Documents","4","",0)
        ix++
        outline[ix] = new item(true, "3.0  Definitions","5","1",0)
        ix++
        outline[ix] = new item(false, "3.0 Definitions - (A-I)","51","",1)
        ix++
        outline[ix] = new item(false, "3.0 Definitions - (N-V)","52","",1)
        ix++
        outline[ix] = new item(true, "4.0  General Requirements","6","2",0)
        ix++
        outline[ix] = new item(false, "4.1  Software Development Management","61","",1)
        ix++
        outline[ix] = new item(false, "4.2  Software Engineering","62","",1)
        ix++
        outline[ix] = new item(false, "4.3  Formal Qualification Testing","63","",1)
        ix++
        outline[ix] = new item(false, "4.4  Software Product Evaluations","64","",1)
        ix++
        outline[ix] = new item(false, "4.5  Software Configuration Management","65","",1)
        ix++
        outline[ix] = new item(false, "4.6  Transitioning to Software Support","66","",1)
        ix++
        outline[ix] = new item(true, "5.0  Detailed Requirements","7","3",0)
        ix++
        outline[ix] = new item(false, "5.1  System Requirements Analysis Design","71","",1)
        ix++
        outline[ix] = new item(false, "5.2  Software Requirements Analysts","72","",1)
        ix++
        outline[ix] = new item(false, "5.3  Preliminary Design","73","",1)
        ix++
        outline[ix] = new item(false, "5.4  Detailed Design","74","",1)
        ix++
        outline[ix] = new item(false, "5.5  Coding and CSU Testing","75","",1)
        ix++
        outline[ix] = new item(false, "5.6  CSC Integration and Testing","76","",1)
        ix++
        outline[ix] = new item(false, "5.7  CSCI Testing","77","",1)
        ix++
        outline[ix] = new item(false, "5.8  System Integration and Testing","78","",1)
        ix++
        outline[ix] = new item(true, "6.0  Notes","8","4",0)
        ix++
        outline[ix] = new item(false, "6.1  Intended Use","81","",1)
        ix++
        outline[ix] = new item(false, "6.2  Data Requirements List and Cross Reference","82","",1)
        ix++
        outline[ix] = new item(false, "6.3  Cost / Schedule Reporting","83","",1)
        ix++
        outline[ix] = new item(false, "6.4  Subject Term  Key Word  Listing","84","",1)
        ix++
        outline[ix] = new item(false, "6.5  Changes From Previous Issue","85","",1)
        ix++
        outline[ix] = new item(true, "Appendixes","9","5",0)
        ix++
        outline[ix] = new item(false, "Appendix A   List of Acronyms and Abbreviations","91","",1)
        ix++
        outline[ix] = new item(false, "Appendix B   Requirements for Software Coding Standards","92","",1)
        ix++
        outline[ix] = new item(false, "Appendix C   Category   Priority Classifications for Problem Reporting","93","",1)
        ix++
        outline[ix] = new item(false, "Appendix D   Evaluation Criteria","94","",1)
        ix++

  setStates()
  setImages()
}

function resetStates() {
  setCookie("dod-std-2167a_outline", "-")
}

function setStates() {
  var storedValue = getCookie("dod-std-2167a_outline")
  var parentExpanded = true
  var lastExp = 0
  var text = ""
  var k = 0

  storedValue += "-"
  for (var i = 0; i < outline.length; ++i) {
    if (outline[i].parent) {
      text = "-" + outline[i].id + "-"
      if (storedValue.indexOf(text) != -1)
        outline[i].state = true
      else
        outline[i].state = false
    }
  }

  for (var i = 0; i < outline.length; ++i) {
    if (outline[i].parent) {
      if ((outline[i].depth == 0) || (outline[i].depth <= lastExp) || (parentExpanded)) {
        outline[i].visible = true
        if (outline[i].state)
          lastExp = outline[i].depth + 1
        else
          if (outline[i].depth < lastExp)
            lastExp = outline[i].depth
      } else
        outline[i].visible = false
      parentExpanded = (outline[i].state && outline[i].visible)
    } else {
      if (parentExpanded)
        outline[i].visible = true
      else
        outline[i].visible = false
    }
  }
}
function setImages() {
  for (var i = 0; i < outline.length; ++i) {
    if (outline[i].visible)
      if (outline[i].parent)
        if (((outline[i+1].parent) && (outline[i+1].depth <= outline[i].depth)))
          outline[i].pic = '<IMG SRC="../../minus.gif" BORDER=0>'
        else
          if (outline[i].state)
            outline[i].pic = '<A HREF="javascript:toggle(' + i + ')"><IMG SRC="../../minus.gif" BORDER=0></A>'
          else
            outline[i].pic = '<A HREF="javascript:toggle(' + i + ')"><IMG SRC="../../plus.gif" BORDER=0></A>'
      else
        outline[i].pic = '<IMG SRC="../../leaf.gif" BORDER=0>'
  }
}
function toggle(num) {
  outline[num].state = !outline[num].state

  setStorage()
  history.go(0)
}
function setStorage() {
  var text = "-"
  for (var i = 0; i < outline.length; ++i) {
    if ((outline[i].parent) && (outline[i].state)) {
      text += (outline[i].id)
      text += '-'
    }
  }

  setCookie("dod-std-2167a_outline", text)
}
function drawTree(myname) {
  document.write('<table>');
  for (var i = 0; i < outline.length; ++i) {
    if (outline[i].visible) {
      document.write('<tr><td align=right valign=top colspan=',(outline[i].depth + 1),'>')
      document.write(outline[i].pic, ' ')
      document.write('</td><td colspan=',(2-outline[i].depth))
      if (myname == outline[i].file)
        document.write(' class="boldredtxt"><b>', outline[i].text, '</b>')
      else
        document.write('><a href="',outline[i].file,'.html">', outline[i].text, '</a>')
      document.write('</td></tr>')
    } else {
      var previous = i
      for (var k = i + 1; k < outline.length && outline[k].depth >= outline[previous].depth; ++k) {
        ++i
      }
    }
  }
  document.write('<tr>');
  for (var j = 0; j < 12; ++j) { document.write('<td width=12>&nbsp;</td>') }
  document.write('</tr></table>');
}
makeDatabase()


