////////////////////
///
///  copyright 2006 Lang Baker
///  labaker@teleport.com
///  fei@bakers-legal-pages.com
///
////////////////////

var	clickedImg;

function hideAll (t, cookieName) {
	var divList = document.getElementsByTagName ('DIV');
	var imgList = document.getElementsByTagName ('IMG');
	var tmpClass;
	var i;

	for (i = divList.length - 1; i >= 0; i--)
	{	tmpClass = divList[i].className;
		if (tmpClass.charAt (tmpClass.length - 1) == 's')
		{	tmpClass = tmpClass.slice (0, tmpClass.length - 1) + 'h';
			divList[i].className = tmpClass;
	}	}
	for (i = imgList.length - 1; i >= 2; i--)
	{	tmpClass = imgList[i].className;
		imgList[i].src = '../e.jpg';
		imgList[i].alt = 'show';
		if (tmpClass.charAt (tmpClass.length - 1) == 's')
		{	tmpClass = tmpClass.slice (0, tmpClass.length - 1) + 'h';
			imgList[i].className = tmpClass;
	}	}
        makeCookie (cookieName);
	t.blur();
}

function showOutline (t, cookieName) {
	var t1 = document.getElementById('topList');
	var divList = document.getElementsByTagName ('DIV');
	var imgList = document.getElementsByTagName ('IMG');
	var tmpClass;
	var i;
	var j;

	for (i = divList.length - 1; i >= 0; i--)
	{	tmpClass = divList[i].className;
		tmpClass = tmpClass.slice (0, tmpClass.length - 2);
		if (tmpClass.localeCompare ("branch") == 0)
		{	tmpClass = divList[i].className;
			tmpClass = tmpClass.slice (0, tmpClass.length - 1) + 's';
			divList[i].className = tmpClass;
		}
		else
		{	tmpClass = divList[i].className;
			if (tmpClass.charAt (tmpClass.length - 1) == 's')
			{	tmpClass = tmpClass.slice (0, tmpClass.length - 1) + 'h';
				divList[i].className = tmpClass;
	}	}	}

	for (i = imgList.length - 1; i >= 2; i--)
	{	tmpClass = imgList[i].className;
		imgList[i].src = '../c.jpg';
		imgList[i].alt = 'hide';
		if (tmpClass.charAt (tmpClass.length - 1) == 'h')
		{	tmpClass = tmpClass.slice (0, tmpClass.length - 1) + 's';
			imgList[i].className = tmpClass;
	}	}
        makeCookie (cookieName);
	t.blur();
}


function toggleShowLeaf(t, cookieName) {
	var divList = document.getElementsByTagName ('DIV');
	var thisDiv;
	var oldClass;
	var tmpChar;
	var newClass;
	var t1;
	var i;

	clickedImg = t;
	thisDiv = t.nextSibling.nextSibling;
	oldClass = thisDiv.className;
	tmpChar = oldClass.charAt (oldClass.length -1);
	if (tmpChar != 'h')
		hideNodes (t.parentNode);
	else
	{
		t.src = "../c.jpg";
		t.alt = "hide";
		newClass = oldClass.slice (0, oldClass.length - 1) + 's';
		while (thisDiv.nextSibling)
		{	thisDiv.className = newClass;
			if (	thisDiv.firstChild && 
				thisDiv.firstChild.nodeName == 'IMG' &&
				thisDiv.firstChild.className == 'img0h')
					thisDiv.firstChild.className = "img0s";
			thisDiv = thisDiv.nextSibling;
		}
		thisDiv.className = newClass;
		if (	thisDiv.firstChild && 
			thisDiv.firstChild.nodeName == 'IMG' &&
			thisDiv.firstChild.className == 'img0h')
				thisDiv.firstChild.className = "img0s";
	}
        makeCookie (cookieName);
}

function hideNodes (parent) {
	var j = parent.lastChild;
	var newClass;

	while (true) {
		if (j.hasChildNodes() )	hideNodes (j);
		if (j.nodeName == 'DIV' && j.className)
			if (j.className.charAt (j.className.length - 1) == 's') {
				newClass = j.className.slice (0, j.className.length - 1) + 'h';
				j.className = newClass;

		}
		if (j.nodeName == 'IMG') {
			j.src = "../e.jpg";
			j.alt = "show";
			if (j == clickedImg && j.className != 'img0')
				j.className = "img0s";
			else if (j.className != 'img0')
				j.className = "img0h";
		}
		if (j.previousSibling)
			j = j.previousSibling;
		else
			return;
}	}


function makeCookie(cName){
	var i;
	var tmpClass;

    if (navigator.cookieEnabled){
	var divList = document.getElementsByTagName ('DIV');
	var cValue = '';
	for (i = divList.length - 1; i >= 0; i--)
	{	tmpClass = divList[i].className;
		if (tmpClass.slice (0,6) == 'branch')
		{	if (tmpClass.charAt (tmpClass.length - 1) == 'h')
			{	cValue = cValue + "0"; }
			else {	cValue = cValue + "1"; }
		}
	}
	document.cookie=escape(cName)+"="+escape(cValue);
    }
}


function getCookie(cookieName){
    var len = cookieName.length;
    len = len + 1;
    var position=document.cookie.indexOf(cookieName+"=");

    if (navigator.cookieEnabled){
      if ( position != -1){
        var begin = position + len;
        var end=document.cookie.indexOf(";", begin);
        if(end == -1){ end=document.cookie.length;}
        cur_val = unescape(document.cookie.substring(begin, end));
        useCookie (cur_val);
      }
//      else {alert("No cookies today");}
    }
}


function useCookie (cValue){
	var tmpClass;
	var i;

	var divList = document.getElementsByTagName ('DIV');
	var j = 0;
	for (i = divList.length - 1; i >= 0; i--)
	{	tmpClass = divList[i].className;
		if (tmpClass.slice (0,6) != 'branch')	{ continue; }
		if (tmpClass.length == 7)		{ i = i; }
		else if (cValue.charAt (j) == '1')
		{	tmpClass = tmpClass.slice (0, tmpClass.length - 1) + 's';
			divList[i].className = tmpClass;
		}
		else
		{	tmpClass = tmpClass.slice (0, tmpClass.length - 1) + 'h';
			divList[i].className = tmpClass;
		}
		j++;
	}
	fixImages();
}


function fixImages () {
	var imgList = document.getElementsByTagName ('IMG');
	var i;
	var this_state = 'x';
	var next_state = 'y';

	for (i = imgList.length - 1; i >= 2; i--)
	{
		if (this_state = imgList[i].parentNode)
		  if (this_state = this_state.className)
		    this_state = this_state.charAt (this_state.length - 1);

		if (next_state = imgList[i].nextSibling)
		  if (next_state = next_state.nextSibling)
		    if (next_state = next_state.className)
		      next_state = next_state.charAt (next_state.length - 1);

		if ((this_state == '0') || (this_state == 's'))
		{	if (this_state == '0')
				imgList[i].className = 'img0';
			else // this state is show
				imgList[i].className = 'img0s';
			if (next_state == 'h')
			{	imgList[i].src = '../e.jpg';
				imgList[i].alt = 'show';
			}
			else if (next_state == 's')
			{	imgList[i].src = '../c.jpg';
				imgList[i].alt = 'hide';
			}
			else // what went wrong?
				alert ('next state error in fixImages')
		}
		else if (this_state == 'h')
			imgList[i].className = 'img0h';
	}
}

