 
//tell the links to trigger Javascript function "show"
 
 function linksToJavaScript()
  {
    if (!document.getElementsByTagName) {
      return null;
    }
    var anchors = document.getElementsByTagName("a");
    for(var i=0; i < anchors.length; i++)
    {
      var a = anchors[i];
      var href = a.href;
	  if (href.search("toggle") != -1) 
      {
        var index = href.indexOf("#") + 1;
        href = "javascript:show('" + href.substring(index) + "');";
        a.setAttribute("href",href);
      }
    }
  }
  
//link tells this function what "what" is - toggle1, toggle2, etc.; the function changes the className of that element from whatever it is (hidden or not) to the opposite


  function show(what)
  {
    if (!document.getElementById) {
      return null;
    }
	var onoff = "0";
    if ((what != "all") && (what != "none"))
	{
		showWhat = document.getElementById(what);
    	if (showWhat.className != "")  {
    		showWhat.className = "";
		    setCookie("show", what);
			onoff = "1";
	    }
    	else {
    		showWhat.className = "hidden";
		    setCookie("show", "");    	
			onoff = "0";
	    }
		hideSpans(what);
		hideLinks(what + onoff);
	} 
 	if ((what == "all") || (what == "none"))
	{
		showhideAllSpans(what);
		showhideAllLinks(what);	
	}
  }

//this function hides every span except the particular toggle span passed to it

  function hideSpans(hideexempt)
  {
	if (!document.getElementsByTagName) {
   		return null;
    }
    //if there's a trigger
	if (!hideexempt) hideexempt = "";
    //find and loop through spans
	var spans = document.getElementsByTagName("span");
    for(var i=0; i < spans.length; i++)
    {
    	var span = spans[i];
    	var id = span.id;
		//if the span has "toggle" in it
		if (id.search("toggle") != -1) 
		{
			if (id !=hideexempt)
   			{
       			span.className = "hidden";
			} 
		}
   	}
  }
  
  function showhideAllSpans(allnone)
  {
	if (!document.getElementsByTagName) {
   		return null;
    }
    //if there's a trigger
	if (!allnone) allnone = "";
    //find and loop through spans
	var spans = document.getElementsByTagName("span");
    for(var i=0; i < spans.length; i++)
    {
    	var span = spans[i];
    	var id = span.id;
		//if the span has "toggle" in it
		if (id.search("toggle") != -1) 
		{
			if (allnone == "none")
   			{
       			span.className = "hidden";
			} else
			{
				span.className = "";
			}
		}
   	}
  }

//this function changes all the more/less links to "more" except for the one associated with the particular toggle span passed to it

  function hideLinks(hideexempt0)
  {
	if (!document.getElementsByTagName) {
   		return null;
    }
    //if there's a trigger
	var hideexempt = hideexempt0.substring(0, hideexempt0.length-1);
	var onoff = hideexempt0.substring(hideexempt0.length-1,hideexempt0.length);
	if (!hideexempt) hideexempt = "";
    //find and loop through anchors
	var anchors = document.getElementsByTagName("a");
    for(var i=0; i < anchors.length; i++)
   	{
      	var a = anchors[i];
      	var href = a.href;
	  	var index = href.indexOf("toggle");
	  	//set "test" based on whether this is first loading the page or after clicking on a link
      	if (href.search("#") != -1) 
	  	{   
			var test = href.substring(index);
		} else 
		{
	  		var test = href.substring(index, (href.length - 3));	
	  	}
		//if the span has "toggle" in it
		if (href.search("toggle") != -1)
		{
		if (test != hideexempt)
   		{
       			a.className = "plus";
				a.innerHTML = "&nbsp;. . . ";
		} 
		if (test == hideexempt)		
		{
			if (onoff == "1")
			{
       			a.className = "minus";
				a.innerHTML = "&nbsp;&nbsp;<i>[show less]</i>";			
			} else
			{
       			a.className = "plus";
				a.innerHTML = "&nbsp;. . . ";				
			}
		}
		}
	}
  }  

  function showhideAllLinks(allnone)
  {
	if (!document.getElementsByTagName) {
   		return null;
    }
    //if there's a trigger
	if (!allnone) allnone = "";
    //find and loop through anchors
	var anchors = document.getElementsByTagName("a");
    for(var i=0; i < anchors.length; i++)
   	{
      	var a = anchors[i];
      	var href = a.href;
		if (href.search("toggle") != -1)
		{
			if (allnone == "none")
   			{
       			a.className = "plus";
				a.innerHTML = "&nbsp;. . . ";
			} else
			{
       			a.className = "minus";
				a.innerHTML = " ";			
			} 
		}
	}
  }  

  window.onload = function()
  {
    var str;
	str = getCookie("show");
	hideSpans(str);
	hideLinks(str + "1");	
    linksToJavaScript();
  } 
  
  var expDays = 1;	// set this value to however many days you want your cookies to last

  function setCookie(name, val) {
	var exp = new Date();
	var cookieTimeToLive = exp.getTime() + (expDays * 24 * 60 * 60 * 1000);
	exp.setTime(cookieTimeToLive);
	document.cookie = name + "=" + escape(val) + "; expires=" + exp.toGMTString();
	}

  function getCookie(name) {
	var cookieNameLen = name.length;
	var cLen = document.cookie.length;
	var i = 0;
	var cEnd;
	var myStringToReturn;
	var myStringToReturnLen;
	while (i < cLen) {
		var j = i + cookieNameLen;
		if (document.cookie.substring(i,j) == name) {
			cEnd = document.cookie.indexOf(";",j);
			if (cEnd == -1) {
			cEnd = document.cookie.length;
			}
		myStringToReturn = unescape(document.cookie.substring(j,cEnd));
		myStringToReturnLen = myStringToReturn.length;
		myStringToReturn = myStringToReturn.substring(1,myStringToReturnLen+1);
		return myStringToReturn;
		}
	i++;
	}
	return "";
   }
    

 
 
 
 