  function setMMbreadCrumbCookie(name, value) { // use: setCookie("name", value);
    if (value != null && value != "")
      document.cookie=name + "=" + escape(value) + "; path=/; domain=.campusretail.com; ";
	  //add domain=.campusretail.com;;
    crcbreadCrumbCookie= document.cookie; // update crcbreadCrumbCookie
  }
	
// Get Cookie
  var crcbreadCrumbCookie = document.cookie;
   
  function getMMbreadCrumbCookie(name) { // use: getCookie("name");
    var index = crcbreadCrumbCookie.indexOf(name + "=");
    if (index == -1) return null;
    index = crcbreadCrumbCookie.indexOf("=", index) + 1;
    var endstr = crcbreadCrumbCookie.indexOf(";", index);
    if (endstr == -1) endstr = crcbreadCrumbCookie.length;
    return unescape(crcbreadCrumbCookie.substring(index, endstr));
  }

  function searchCookieForSection(value){
  var tempLabelArray;
  if (value != null && value != ""){
	  	if (value.indexOf("~~~")>-1){
		  var tmp = value.split("~~~")
		  for(i=0;i<tmp.length;i++){
			  if(tmp[i].indexOf("||")>-1){
			    tempLabelArray = tmp[i].split("||");
			  	if (tempLabelArray[0]==MMcookiesection) return (i);
			  }	
		  }
		  return -1;
		}else{
		   if(value.indexOf("||") >-1){
		   		 tempLabelArray = value.split("||");
			  	if (tempLabelArray[0]==MMcookiesection) return 0;
				else return -1;
		   }else{ 
		   		return -1;
		   }
		} 
	}else return -1
  }
  
  function setMMMyLocation(){
  	var tmp = searchCookieForSection(getMMbreadCrumbCookie("crcbreadCrumbs"));

	if(tmp==-1){
		anotherTmp = getMMbreadCrumbCookie("crcbreadCrumbs");
		if ((returnMaxCookieLabelSize(anotherTmp) + MMcookiesection.length) <= 500){
			if(anotherTmp ==null)anotherTmp = "";
			if (anotherTmp!="")anotherTmp = anotherTmp + "~~~"
			setMMbreadCrumbCookie("crcbreadCrumbs",anotherTmp+MMcookiesection+"||"+breadcrumbURL );
		}
	}else { 
		truncateCookie(getMMbreadCrumbCookie("crcbreadCrumbs"),tmp);
	}
  }
  
  function truncateCookie(value,index){
	  var newCookie = "";
	  if(index >-1){
			if (value.indexOf("~~~")>-1){
		     var tmp = value.split("~~~")
		     for(i=0;i<tmp.length;i++){
				 if (i <= index ){
				 	if (newCookie !="") newCookie = newCookie + "~~~"
				 	newCookie = newCookie + tmp[i];
				}
			 }
			}
			setMMbreadCrumbCookie("crcbreadCrumbs", newCookie);
	  }
  }
  
  function drawMMBreadCrumbs(){
  var value = getMMbreadCrumbCookie("crcbreadCrumbs")
   if (value != null && value != ""){
	  if (value.indexOf("~~~")>-1){
	  	var tmp = value.split("~~~");
		for(i=0;i<tmp.length;i++)outputMMline(tmp[i]);
		document.writeln('');
	  }else{
	  	outputMMline(value)
	  }
  	}
  }
  
  function outputMMline(value){
  	if(value.indexOf("||")>-1){
  		tmp = value.split("||");
		if(tmp[1]==breadcrumbURL)document.write('<span class="breadcrumb">'+tmp[0]+' > </span>');
  		else document.write('<span class="breadcrumb"><a href="'+tmp[1]+'">'+tmp[0]+'</a> > </span>');
  	}
  }
  
  function returnMaxCookieLabelSize(value){
  	var total = 0
	if(value!="" && value!=null){
	  	if (value.indexOf("~~~")>-1){
		  	var tmp = value.split("~~~");
			for(i=0;i<tmp.length;i++) total = total + returnCookieLabelSize(tmp[i]);
			return total;
		  }else{
		  	return 0;
		  }
	 }else{
	  	return 0;
	 }
  }
  
  function returnCookieLabelSize(value){
  	if(value.indexOf("||")>-1){
  		tmp = value.split("||");
  		return tmp[1].length;
  	}else{
		return 0;
	}
  }

  if(set_breadcrumb_label)setMMMyLocation();
  if(draw_automatic_breadcrumb)drawMMBreadCrumbs();
