// jorgie's breadcrumb script

 

// main function

function LeaveCrumbs(title,sep,group,count,timeout) {

  var DOMAIN = '';

  var PATH = '/';

  var MAX_CRUMBS = 10;

  var result = new String('');

  var death = new Date();

  var links = new Array(MAX_CRUMBS); // we allways store max_crumbs

  var names = new Array(MAX_CRUMBS); // even if we only display 'count' of them

  

  if(count < 1) count = 5;   // force at least one crum

  if(count > MAX_CRUMBS) count = MAX_CRUMBS; // no more than MAX_CRUMBS crumbs

 

  if(title == '') title = document.title;

 

  sep = sep + ""; //force to string

  if(sep == 'undefined') sep = ' | ';

  if(sep == '') sep = ' | ';

    

  group = group + "";  //force to string

  if(group == 'undefined') group = 'mucrumbs';

  if(group == '') path = "mucrumbs";

  

  if(timeout < 1) timeout = 1;

  if(timeout > 60) timeout = 60;

  

  death.setTime(death.getTime() + timeout * 60 * 1000);

 

  for(var x=MAX_CRUMBS-1;x>=0;x--) {

    links[x] = getCookie(group + 'Link' + x);

    names[x] = getCookie(group + 'Name' + x);

    if(names[x] == null) continue;

    if(links[x] == null) continue;

    if(x >= count) continue; // only display 'count' crumbs

    if(result.length > 0) result += sep;

    if(names[x] == title)

      result += names[x];

    else

      result += '<a href="' + links[x] + '">' + names[x] + '</a>';

  }

  

  // only update cookies if we are not on the same page as the newest cookie  

  if(links[0] != document.location) {  

    var y;

    setCookie(group + 'Name0',title,death,'/','');

    setCookie(group + 'Link0',document.location,death,PATH,DOMAIN);  

    for(var x=0;x<MAX_CRUMBS-1;x++) {

      y=x+1;

      if((names[x] == null) || (links[x] == null)) {

        continue;

      }

      else {

        setCookie(group + 'Name' + y,names[x],death,PATH,DOMAIN);

        setCookie(group + 'Link' + y,links[x],death,PATH,DOMAIN);

      }

    }

  }

 

  if(names[0] != title) {

    if(result.length > 0) result += sep;

    result += title;

  }

 

  document.write(result);  

}

 

// *** Begin MS Cookie Functions ***

 

   var caution = false

 

   // name - name of the cookie

   // value - value of the cookie

   // [expires] - expiration date of the cookie

   // (defaults to end of current session)

   // [path] - path for which the cookie is valid

   // (defaults to path of calling document)

   // [domain] - domain for which the cookie is valid

   // (defaults to domain of calling document)

   // [secure] - Boolean value indicating if

   // the cookie transmission requires a secure transmission

   // * an argument defaults when it is assigned null as a placeholder

   // * a null placeholder is not required for trailing omitted arguments

   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

            

   }

 

   // name - name of the cookie

   // * return string containing value

   // of specified cookie or null if cookie

   // does not exist

   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))

   }

 

   // name - name of the cookie

   // [path] - path of the cookie

   // (must be same as path used to create cookie)

   // [domain] - domain of the cookie

   // (must be same as domain used to create cookie)

   // * path and domain default if assigned

   // null or omitted if no explicit argument proceeds

   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"

      }

   }

 

   // date - any instance of the Date object

   // * you should hand all instances of the

   // Date object to this function for "repairs"

   // * this function is taken from

   // Chapter 14, "Time and Date in JavaScript", in

   // "Learn Advanced JavaScript Programming"

   function fixDate(date) {

      var base = new Date(0)

      var skew = base.getTime()

      if (skew > 0)

         date.setTime(date.getTime() - skew)

   }

 

// *** End MS Cookie Functions ***

