/////////////////////////////////////////////
//CONFIG INFO
/////////////////////////////////////////////
var TopLevelPageName="default.aspx";
var CrumbSeparator = ">>";


/////////////////////////////////////////////
//DO NOT MODIFY BELOW THIS LINE
/////////////////////////////////////////////

//get current pagename
var url = document.location.href;
//if (url.indexOf('?')>0)
//	url = url.substring(0,url.indexOf('?'));


var s = url.split("/");
var pagename = s[s.length-1];

var pagetitle = pagename.substring(0,pagename.indexOf('.'));

if (pagetitle.toLowerCase()=="default" || pagetitle.toLowerCase()=="dispform" || pagetitle.toLowerCase()=="searchresults" || pagetitle.toLowerCase()== "overview" || pagetitle.toLowerCase()== "newform" || pagetitle.toLowerCase()== "summary" || pagetitle.toLowerCase()== "allitems")
	pagetitle = document.title;

//replace _ in title with space
pagetitle = pagetitle.replace(/_/g," ") 

pagetitle = pagetitle.replace(/%20/g," ") 

var trail="";
var trailHTML="<span class='cookiecrumb'>";

if (pagename.toLowerCase()==TopLevelPageName && s.length<=4)
{
	//clear cookie
	DeleteCookie("navTrail");
	trail="Home|/}";
	setCookie("navTrail",trail,null,"/");
}
else if (pagename.toLowerCase()==TopLevelPageName && s.length>4)
{
	//clear cookie
	DeleteCookie("navTrail");
	trail="Home|/}" + pagetitle + "|" + url + "}";
	setCookie("navTrail",trail,null,"/");
}
else
{
	//get cookie
	var navCookie=""
	navCookie = getCookie("navTrail");
	if (navCookie==undefined)
	{
		navCookie=pagetitle+"|" + url + "}";
		setCookie("navTrail",navCookie,null,"/");
	}
	


	//split cookie into sections	
	s = navCookie.split("}");

	//scan cookie.  
	var pageAlreadyExists=false;
	for (var x=0; x<s.length-1; x++)
	{

		//Does current page exist in cookie list?
		var w = s[x].split("|");

		trail+=w[0]+"|"+w[1]+"}";	
		if (w[1]==url && w[0]==pagetitle)
		{
			pageAlreadyExists=true;
			break;
		}
		

	}

	if (pageAlreadyExists==false)
	{
		//no - add to end of list
		trail+=pagetitle+"|"+url+"}";
	}
	
	setCookie("navTrail",trail,null,"/");
}

//write out trail
s = trail.split("}");
for (var x=0; x<s.length-2; x++)
{
	w = s[x].split("|");
	trailHTML+="<a class='cookiecrumb' href='" + w[1] + "'>" + w[0] + "</a> " + CrumbSeparator + " "; 

}
w = s[s.length-2].split("|");
trailHTML+= w[0] + "</span>"; 

document.writeln(trailHTML);


// 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" : "");
  document.cookie = curCookie;
}


function getCookie(Name) {
   var search = Name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search)
      if (offset != -1) { // if cookie exists
         offset += search.length
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset)
         // set index of end of cookie value
         if (end == -1)
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      }
   }
}


function DeleteCookie (name) {
      var exp = new Date();
      exp.setTime (exp.getTime() - 1);  // This cookie is history
      var cval = GetCookie (name);
      document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
