
   var FirstBt = null;
   var nameRefNS=new String("NS_");
   var nameRefIE=new String("IE_");
   var blocked = false;
   
   if (navigator.appName == "Netscape") {
        var nav_version = navigator.appVersion[0];
        if (nav_version >= '5') {
           var browser = "NS5";
           var layerRef=new String("");
           var styleRef=new String(".style");
           var colorRef=new String(".bgColor");
           var nameRef = new String(nameRefNS);
        } else {
           var browser = "NS";
           var layerRef=new String("document.layers");
           var styleRef=new String("");
           var colorRef=new String(".bgColor");
           var nameRef = new String(nameRefNS);
        }
   } else if (navigator.appName == "Microsoft Internet Explorer") {
        var browser = "IE";
        var layerRef=new String("document.all");
        var styleRef=new String(".style");
        var colorRef=new String(".backgroundColor");
	     var nameRef = new String(nameRefIE);
   } else { // any other browser assumed to comply with Netscape for now
        var browser = "NS";
        var layerRef=new String("document.layers");
        var styleRef=new String("");
        var colorRef=new String(".bgColor");
        var nameRef = new String(nameRefNS);
   }
     
   function NiceBt(name,label,height,width,groupId,offColor,onColor,hovColor,styleclass,action) {
   	   this.name = name;
   	   this.groupId = groupId;
   	   this.selected = false;
   	   this.label = label;
	   this.height = height;
   	   this.width = width;
   	   this.offColor = offColor;
   	   this.onColor = onColor;
   	   this.hovColor = hovColor;
   	   this.styleclass = styleclass;
   	   this.action = action;
   	   this.next = null; 
   }
   
   function TurnOff(bt) {
       ColorThis(bt.name,bt.offColor);
       bt.selected = false;   
   }
   
   function TurnOn(bt) {
       ColorThis(bt.name,bt.onColor);
       bt.selected = true;   
   }
   function StartHover(name) {
        blocked = false;
   	var bt = GetButton(name);
	if (bt != null) {
          ColorThis(bt.name,bt.hovColor);
       }    
   }
   
   function StopHover(name) {
        blocked = false;
   	var bt = GetButton(name);

	if (bt != null) {
		if ((bt.selected) && (bt.groupId > 0)) {
             		ColorThis(bt.name,bt.onColor);
        	} else {
             		ColorThis(bt.name,bt.offColor);
		}
	}    
   }
   function GetButton(name) {
   		var bt = FirstBt;
   		var thisBt = null;
   		while (bt != null) {
   			if (bt.name == name) {
   		   		thisBt = bt; 
   		   		break;
   		   	}
   		   	bt = bt.next;   
   		}
   		return (thisBt);
   }
   
   function TurnAllOff(groupId) {
   		var bt = FirstBt;
   		while (bt != null) { 
   			if ((bt.groupId == groupId) && bt.selected) {
   			   TurnOff(bt);
   			}
   			bt = bt.next;  		
   		}
   }
   
   function SelectButton(name) {
       if (name != null) {
		   var thisBt = GetButton(name);
		   if (thisBt != null) {
 		      if (thisBt.groupId > 1) {
		      	TurnAllOff(thisBt.groupId);
		      }
		      TurnOn(thisBt); 
		      if ((thisBt.action != null) && (blocked == false)){
			//blocked = true;
		        eval(thisBt.action); 
		      }
		   }
		}
        
   }

   function HilightButton(name) {
       //alert('highlight:'+name);
       if (name != null) {
		   var thisBt = GetButton(name);
		   if (thisBt != null) {
 		      if (thisBt.groupId > 1) {
		      	TurnAllOff(thisBt.groupId);
		      }
		      TurnOn(thisBt); 
		      
		   }
       }
        
   }

  function ToggleButton(name) {
	if (name != null) {
		var bt = GetButton(name);
                if (bt != null) {
                   var wasSelected = bt.selected;
		   var c = bt.onColor;
	           
		   if (wasSelected) {
 		      c = bt.offColor;
 		    
		   }
                   ColorThis(name,c);
		   bt.selected = !wasSelected;
		}
	}
   }

   function ColorThis(name,color) {
        if (browser == "NS5") {
           divel=document.getElementById(nameRef + name);
	   divel.style.backgroundColor=color;
	} else {
        
       	   window.eval(layerRef + '[\"' + nameRef + name + '\"]' + styleRef + colorRef+'=\"'+color+'\";');
	}
	
   }
   
   function AddButton(name,label,height,width,groupId,offColor,onColor,hovColor,styleclass,action) {
       var thisBt = new NiceBt(name,label,height,width,groupId,offColor,onColor,hovColor,styleclass,action);
		thisBt.next = FirstBt;
		FirstBt = thisBt;
       return (thisBt);
  }
  
   function MakeButton(name,label,height,width,groupId,offColor,onColor,hovColor,styleclass,action) {


		AddButton(name,label,height,width,groupId,offColor,onColor,hovColor,styleclass,action);
		if (browser == "IE") {
		   document.write("<td valign=MIDDLE height="+height+" width="+width+" ID="+nameRefIE+name+" align=center bgColor="+offColor+" ");
                } else if (browser == "NS5") {
		   document.write("<td valign=MIDDLE height="+height+" width="+width+" ID="+nameRef+name+" align=center bgColor="+offColor+" ");
		} else {
		   document.write("<td valign=MIDDLE width="+width+" name="+nameRefIE+name+" align=center ");
		}
		//document.write("onMouseOut=\"StopHover('"+name+"');\"");
		//document.write("onMouseDown=\"SelectButton('"+name+"');\"");
		//document.write("onMouseOver=\"StartHover('"+name+"');\"");
		document.write(">");
		document.write("<a class=\""+styleclass+"\" href=\"javascript:SelectButton('"+name+"');\"");
		document.write("onMouseOut=\"StopHover('"+name+"');\"");
		document.write("onMouseOver=\"StartHover('"+name+"');\">");
		if (browser == "NS") {
		   document.write("<DIV ID='"+ nameRefNS +name+"' width="+width+"  BGCOLOR="+offColor+">");
		}
		document.write(label);
		if (browser == "NS") {
		   document.write("</DIV>");
		}
		document.write("</a>");
		document.write("</td>");
		 
   } 


