
/**
 * See master page for definitions of rootUrl() and rootLevel().
 * Function rootUrl() gives the root url, and rootLevel() gives
 * the number of levels of hierarchy to ignore when forming
 * the directory hierarchy (which could be 0).
 */


/**
 * Display breadcrumb trail.  List is formed as follows:
 *   (1) Link to home page through string "SCFHP"
 *   (2 through n-1) If page is nested in directory hierarchy,
 *   for each level of the hierarchy, the directory name (capitalized)
 *   is used for the name of the link. The link itself is to
 *   file "default.aspx" within the directory.
 *   (n) The final entry is not a link, but a simple string,
 *   that of the title of the page being looked at.
 */
function breadcrumbs() {
  sURL = new String;
  bits = new Object;
  var x = 0;
  var stop = 0;
  var output = "<div id=\"breadcrumb\"><a href=\"" + rootUrl() + "/default.aspx\">SCFHP</a> &raquo; ";
  var dirLevel = 0;
  var numLevelsToIgnore = rootLevel();

  sURL = location.href;
  var endCharPos = sURL.indexOf('?');
  if (endCharPos == -1) { endCharPos = sURL.length; }
  sURL = sURL.slice(9, endCharPos);
  chunkStart = sURL.indexOf("/");
  sURL = sURL.slice(chunkStart+1,sURL.length)

  while(!stop) {
    chunkStart = sURL.indexOf("/");
    if (chunkStart != -1) {
      if (dirLevel > numLevelsToIgnore) {
        bits[x] = sURL.slice(0,chunkStart)
      }  
      sURL = sURL.slice(chunkStart+1,sURL.length);
    } else {
      stop = 1;
    }
    if (dirLevel > numLevelsToIgnore)
      x++;
    dirLevel++;
  }

  for (var i in bits) {
    output += "<a href=\"";
    for (y=1; y<x-i; y++) {
      output += "../";
    }
    output += bits[i] + "/default.aspx\">" + 
              bits[i].substring(0,1).toUpperCase() + bits[i].substring(1,bits[i].length) +
              "</a> &raquo; ";
    
  }

  document.write(output + "<span style=\"color: #fff;\">" + document.title + "</span>");
  document.write("</div>");
}

/**
 * Force the breadcrumb to one level: root link and location title.
 * If location_title is empty, reverts to just root link.
 *
 * This function is used for situations like the search results page,
 * where we use the existing page to present results.
 */
function force_breadcrumb(location_title) {
  // alert("(dbg) Adjusting breadcrumb to [" + location_title + "]");
  var breadcrumb_div = document.getElementById('breadcrumb');
  if (breadcrumb_div) {
    var new_breadcrumb = "<div id=\"breadcrumb\"><a href=\"" + rootUrl() + "\">SCFHP</a>";
    if (location_title.length > 0) {
      new_breadcrumb += " &raquo; <span style=\"color: #fff;\">" + location_title + "</span>";
    }
    breadcrumb_div.innerHTML = new_breadcrumb + "</div>";
  }
}

