
/* =================================================================
   getDocumentPath
   ================================================================= */

function getDocumentPath(docobj)
{

  var doc = !docobj ? document : docobj;

  // Get the index (position) of the domain
  // in the full document URL.  The URL property
  // returns the complete URL (including parameters)
  // of the current page.

  var index = doc.URL.indexOf(doc.domain);

  // Get the requested page (including parameters)

  var request = doc.URL.substr(index + doc.domain.length);

  // Get the index of the first question mark, if any.
  // The question mark indicates the beginning of the
  // parameter section of the URL.  JavaScript returns -1
  // if the text was not found.

  var paramindex = request.indexOf("?");

  if(paramindex == -1)
    return(request)
  else
    return(request.substr(0, paramindex));
}

/* =================================================================
   getPathLinks
   -----------------------------------------------------------------
   Returns an array containing a link to each folder of a path.
   ================================================================= */

function getPathLinks(path, RootName, RootHREF)
{

  var snake = "";
  
  // Initialize an array to hold the links
  // generated by the function.  The size of the
  // array is not known at this time.
  
  var result = new Array();

  // Parse out the individual folder names.  Currently
  // the function does not recognize backslashes (e.g.,
  // MS-DOS based file paths or UNCs).

  var folders = path.split("/");

  if(folders.length == 1)
  {

    // The string did not contain any slash characters.
    // Simply return the text without a hyperlink.  This
    // is probably an error condition.

    result[0] = path;
   
  }

  else
  {

    // The path contained at least one slash.

    for(var i=0; i < folders.length - 1; i++)
    {

    // Each link is the cumulative list of folders
    // from previous positions in the array.

    snake += folders[i] + "/";
    
    if(i==0)
      result[0] = RootName.link(RootHREF);
    else
      result[i] = folders[i].link(snake);
          
    }

  }
  
  // Return the results to the caller
  
  return(result);
  
}


/* =================================================================
   isHomePage
   ================================================================= */

function isHomePage()
{

  // Get the current path of the document (minus the
  // protocol, domain, and any parameters).

  var path = getDocumentPath();

  return(path == "/" || path == "/default.asp" || path == "/Default.asp");

}


/* =================================================================
   readCookie
   ================================================================= */

function readCookie(cookieName) {

  // document.cookie returns all of the
  // cookies as a single string.  Grab
  // the string and return the index of
  // the specified cookie.

  var docCookies = document.cookie;
  var startIndex = docCookies.indexOf(cookieName);
  if (startIndex == -1) return false;
  startIndex += cookieName.length + 1;

  // Figure out where our cookie's value ends
  // by looking for the start of the next one

  var endIndex = docCookies.indexOf(";",startIndex);
  if (endIndex == -1) endIndex = docCookies.length;

  // Return the value

  var cookieValue = docCookies.substring(startIndex, endIndex);
  return unescape(cookieValue);

}



/* =================================================================
   setCookie
   -----------------------------------------------------------------
   Sets a cookie; TODO: the expiration date is currently set to the
   future to ensure it persists on the client computer.  Use a 
   dynamic date instead of an absolute data; this will avoid the
   necessity of modifying this function every few years.
   ================================================================= */

function setCookie(name,value)
{

  document.cookie = 
    name + "=" + value + "; path=/;expires=Wed, 31 Dec 2005 23:59:59 GMT;";

}


/* =================================================================
   toggleDisplay
   ================================================================= */

function toggleDisplay(obj)
{
  if(obj.style.display=="none")
    obj.style.display=""
  else
    obj.style.display="none";
}


/* =================================================================
   transformXML
   ================================================================= */

function transformXML(element, xml, xslt)
{

  var oXML = new ActiveXObject("Microsoft.XMLDOM");
  var oXSL = new ActiveXObject("Microsoft.XMLDOM");

  oXML.async = false;
  oXML.load(xml);
    
  oXSL.async = false;
  oXSL.load(xslt);
  
  element.innerHTML = oXML.transformNode(oXSL);

}


/* ==================================================================
   writeCookieTrail
   ================================================================== */

function writeCookieTrail()
{

  var build = "";
  
  // Grab the path of the page.  The getDocumentPath
  // function returns the path of the current page,
  // minus the domain and any query strings.
  
  var path = getDocumentPath(document);

  // Now build an array of links to each folder in the path.
  
  var links = getPathLinks(path, "Home", "/");
  
  for(var i=0; i<links.length; i++)
  {
    build += links[i];

    if(i<links.length-1)
      build += "&nbsp;<span class='Faded'>&gt;</span>&nbsp;"  
  }
  
  document.write(build);
  
}


