var delim = '|';
var trailLength = 6;
var chunks;
var DAY = 24 * 60 * 60 * 1000;
var ssarrowurl = 'http://ittmlsites.sssecure.com/ittml/rule/images/yellow_arrow.gif';

function doCrumbs(){
  if(cookieTest('xxx')){
    crumbList = new CrumbList();
    if(getCookie('trailLinks')){
      var staleLinkCrumbs = getCookie('trailLinks').split(delim);
      var staleTextCrumbs = getCookie('trailText').split(delim);
      var startPos=
        (staleTextCrumbs.length<trailLength ||
        document.location==staleLinkCrumbs[staleLinkCrumbs.length-1])
        ?0:1;
      for(i=startPos;i<staleLinkCrumbs.length;i++)
	  {
		  var thisTitle=staleTextCrumbs[i]
		  thisTitle=thisTitle.replace(/ > Support Centre > Danforth - ITT/,"")
		  thisTitle=thisTitle.replace(/ > Support Centre > Rule - ITT/,"")
		  thisTitle=thisTitle.replace(/ > Support Centre > Sudbury - ITT/,"")
		  thisTitle=thisTitle.replace(/ > Support Centre > Hydroair - ITT/,"")
		  thisTitle=thisTitle.replace(/ > Support Centre > LVM - ITT/,"")
		  thisTitle=thisTitle.replace(/ > Support Centre > Jabsco - ITT/,"")
		  thisTitle=thisTitle.replace(/ > Support Centre > Flojet - ITT/,"")
		  thisTitle=thisTitle.replace(/ > Support Centre > Jabsco DE - ITT/,"")
		  
		  thisTitle=thisTitle.replace(/Support Centre > Danforth - ITT/,"")
		  thisTitle=thisTitle.replace(/Support Centre > Rule - ITT/,"")
		  thisTitle=thisTitle.replace(/Support Centre > Sudbury - ITT/,"")
		  thisTitle=thisTitle.replace(/Support Centre > Hydroair - ITT/,"")
		  thisTitle=thisTitle.replace(/Support Centre > LVM - ITT/,"")
		  thisTitle=thisTitle.replace(/Support Centre > Jabsco - ITT/,"")
		  thisTitle=thisTitle.replace(/Support Centre > Flojet - ITT/,"")
		  thisTitle=thisTitle.replace(/Support Centre > Jabsco DE - ITT/,"")
          crumbList.add(staleLinkCrumbs[i],thisTitle);
      }
    }
    if(document.location!=crumbList.links[crumbList.links.length-1]){
	  var thisTitle=document.title
	  thisTitle=thisTitle.replace(/ > Support Centre > Danforth - ITT/,"")
	  thisTitle=thisTitle.replace(/ > Support Centre > Rule - ITT/,"")
	  thisTitle=thisTitle.replace(/ > Support Centre > Sudbury - ITT/,"")
	  thisTitle=thisTitle.replace(/ > Support Centre > Hydroair - ITT/,"")
	  thisTitle=thisTitle.replace(/ > Support Centre > LVM - ITT/,"")
	  thisTitle=thisTitle.replace(/ > Support Centre > Jabsco - ITT/,"")
	  thisTitle=thisTitle.replace(/ > Support Centre > Flojet - ITT/,"")
	  thisTitle=thisTitle.replace(/ > Support Centre > Jabsco DE - ITT/,"")

      thisTitle=thisTitle.replace(/Support Centre > Danforth - ITT/,"")
	  thisTitle=thisTitle.replace(/Support Centre > Rule - ITT/,"")
	  thisTitle=thisTitle.replace(/Support Centre > Sudbury - ITT/,"")
	  thisTitle=thisTitle.replace(/Support Centre > Hydroair - ITT/,"")
	  thisTitle=thisTitle.replace(/Support Centre > LVM - ITT/,"")
	  thisTitle=thisTitle.replace(/Support Centre > Jabsco - ITT/,"")
	  thisTitle=thisTitle.replace(/Support Centre > Flojet - ITT/,"")
	  thisTitle=thisTitle.replace(/Support Centre > Jabsco DE - ITT/,"")
	  
      crumbList.add(document.location,thisTitle);
    }
    setCookie('trailLinks',crumbList.links.join(delim),1);
    setCookie('trailText',crumbList.text.join(delim),1);
    crumbList.output();
  }
  else
  {
	document.write("<small><b>Step tracker:</b> Apologies - we couldn't save a cookie in your browser for this feature.  Try your brower's <a href=javascript:history.go(-1)><b>Back</b></a> button instead.</small>");
  }
}


function CrumbList(){
  this.links=new Array();
  this.text=new Array();
  this.add = crumbListAdd;
  this.output = crumbListShow;
}
  function crumbListAdd(href,text){
    this.links[this.links.length]=href;
    this.text[this.text.length]=text;
  }

function crumbListShow()
{
	if (this.links.length <= 1)
	{
	document.write('<b>As you progress through the wizard, links to the previous steps will appear here.</b><br>');
	}
	else if (this.links.length == 6)
	{
	document.write('Previous 5 steps visited:<br>');
	}
	else
	{
	document.write('Previous steps visited '+(this.links.length-1)+':<br>');
	}
	for(var i in this.links)
	{
	  if(i==this.links.length-1)
	  {
		//document.write( ((i==0)?"":"" );
	  }
	  else
	  {
		document.write(
		  ((i==-1)?"":(" <img src=" + ssarrowurl + " width=9 height=12>&nbsp;"))
		  +"<a href='" + this.links[i] + "'>"
		  + this.text[i] + "</a><br>"
		);
	  }
	}
}

function cookieTest(name){
  try{
    setCookie(name,'true',1);
    chunks = document.cookie.split("; ");
    return (getCookie(name)=='true');
  }catch(e){
    return false;
  }
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


function getCookieOld(name) {
  var returnVal = null;
  for (var i in chunks) {
    var chunk = chunks[i].split("=");
    returnVal = (chunk[0] == name)
      ?unescape(chunk[1])
      :returnVal;
  }
  return returnVal;
}

function setCookie(name, value, days) {
  if (value != null && value != "" && days > 0)
  {
    //var expiry=new Date(new Date().getTime() + days * DAY);
    //document.cookie= name +"="+ escape(value) +"; expires=" + expiry.toGMTString();
    document.cookie= name +"="+ escape(value);
    chunks = document.cookie.split("; ");
  }
}

function clearBreadcrumbs()
{
    setCookie("trailLinks","",1);
    setCookie("trailText","",1);
}