/* formatPathForDisplay(path)
 *
 * Takes a path element (directory name) and processes it
 * for "pretty" display in the breadcrumbs trail.
 * 
 * The directory names are words separated by underscores.
 * This function capitalizes the first character of each
 * word and replaces the underscores with spaces.
 */
function formatPathForDisplay(path)
{
   // separate the directory name into an array
   // split the string on underscore separators
   pathWords = path.split("_");

   // for each element of the name, uppercase the first
   // character unless the element matches a special word
   cWords = pathWords.length;
   for(i=0;i<cWords;++i)
   {
      word = pathWords[i];
      if(word == "whats") word = "what's";
      if(word != "and")
	  if(word == "edi") word = "Electronic Data Interchange";
	  if(word == "msp") word = "Medicare Secondary Payer";
	  if(word == "efr") word = "Electronic File Reports";
	  if(word == "rhhi") word = "HH + H";
	  if(word == "lcds") word = "Local Coverage Determinations";
	  if(word == "enroll_update_your_records") word = "Enrollment";
	 
      {
         word = word.slice(0,1).toUpperCase() + word.slice(1);
      }
      pathWords[i] = word;
   }

   // recombine the individual elements with into a single
   // string using the space character as a separator
   return pathWords.join(" ");
}

/* createBreadCrumbs()
 *
 * Uses the current href to generate a breadcrumbs trail
 * for navigation.
 *
 * WARNING: The assumption is that each directory in the URL
 *          path will have its own index.html.  If this is
 *          not the case then the breadcrumbs trail will fail.
 */
function createBreadCrumbs()
{
   // get current page location
   urlString = location.href;

   // split into an array on the "/" character.  We use the
   // slice to exclude the first element which should be the
   // protocol (i.e. "http:", "ftp:").  We also exclude the
   // last element which should be the page itself (htm, asp)
   urlArray = urlString.split("/").slice(1,-1);

   // because URLs contain multiple "/" characters following
   // the protocol the array created by splitting on the
   // separator characters.  For typical URLs, "http://" there
   // will be one empty element, but file URLs, "file:///" may
   // contain more than one.  This loop starts at the front of
   // the array and removes empty elements.
   while(urlArray[0] == "")
   {
      urlArray = urlArray.slice(1);
   }

   // after all empty elements are removed, we have to slice
   // off the hostname (i.e. www.cahabagba.com).
   urlArray = urlArray.slice(1);

   // this is used to determine how many "../" prefixes must
   // be added to an href to navigate up the directory tree
   cParentDirs = urlArray.length;

   output = "";
   for(var i in urlArray)
   {
      cParentDirs -= 1;
      output += "<a href=\"";
      for(y=cParentDirs; y>0; --y)
      {
         output += "../";

      }
      output += "index.htm\">" + formatPathForDisplay(urlArray[i]) + "</a>  &gt; ";
   }

   return output + document.title;
}

document.write(createBreadCrumbs());


