// Folding Lists
// Amnon Silverstein Feb 2004
// 


function FoldingList(label,body,action,status)
{ // Constructor for FoldingLists
   this.label=label;
   this.body=body;
   this.action=action;
   this.status=status;
   this.contents=new Array();
}

new FoldingList();

FoldingList.prototype.additem = AddListItem;
FoldingList.prototype.print = PrintFoldingList;
FoldingList.prototype.toggle =ToggleStatus;
//FoldingList.prototype.initialize = InitializeFoldingList;
//FoldingList.prototype.makebutton = MakeButton;

function AddListItem(parent,label,body){
   if (this.label==parent){
       var max=this.contents.length;
       this.contents[max]=new FoldingList(label,body,'',1);

   }else{
       var i;
       for (i=0; i<this.contents.length; i++)
          this.contents[i].additem(parent,label,body);
   }
}

function ToggleStatus(target){
   if (this.label==target){
       this.status=1-this.status;
   }else{
       var i;
       for (i=0; i<this.contents.length; i++)
          this.contents[i].toggle(target);
   }

}

function PrintFoldingList(level) {
 var i;
 var el;
    if (arguments.length==0)
      level=0;
    document.write('<table border="0" width="100%"><tr>');
    document.write('<td align="right" width='+(level*20+20)+'>');
    if (this.contents.length>0)
        document.write(MakeButton(this.label)+"<B>&nbsp");
    else
        document.write(MakeBlank()+"&nbsp");
    document.write('</B></td>\n<td>');    
    document.write(this.body+'</td>\n</tr></table>\n');

    if (this.contents.length>0){
      document.write("<div style='display:none' id='ITEM_"+this.label+"'>");
      for (i=0; i<this.contents.length; i++)
        this.contents[i].print(level+1);   
      document.write("</div>");
    } 
}


function ToggleFoldingList(sItem) { 
	var oButton = document.getElementById("BTN_"+sItem);
	var oItem = document.getElementById("ITEM_"+sItem);

	if ((oItem.style.display == "") || (oItem.style.display == "none")) {
		oItem.style.display = "block";
		oButton.src = eval("minus.src");
	} else {
		oItem.style.display = "none";
		oButton.src = eval("plus.src");
	}

	return false;
}

function MakeButton(sItem){
        button="<img src='plus.gif' align='center' height='9' width='9'";
 	button=button+"border=0 id='BTN_"+sItem;
	button=button+"' vspace=3 style='cursor:hand;' onclick="+'"';
	button=button+"return ToggleFoldingList('";
	button=button+sItem+"');"+'"'+">";
        return button;
}
function MakeBlank(){
	return "<img src='spacer.gif' height='9' width='9'>";
}
function InitializeFoldingList(){
        
	plus = new Image();
	plus.src = "plus.gif";

	minus = new Image();
	minus.src = "minus.gif";
}
InitializeFoldingList();


function Demo(){
flFruits=new FoldingList('fruits','Fruit List','',1);
flFruits.additem('fruits','apple','Apples');
flFruits.additem('fruits','grape','Grapes');
flFruits.additem('fruits','pineapple','Pineapples');
flFruits.additem('apple','green','Granny Smith');
flFruits.additem('apple','red','<A href="http://www.bestapples.com/">Washington</A>');
flFruits.print();
}

