
var menustack=new Array();
var menuprefix=new Array();

function menulink(prefix,href) {
    this.location=href;
}

function menucollapse(prefix,m,id) {   

    for (var l=0;l<m.item.length;l++) {
        if (m.item[l].id==id) continue;
        if (m.item[l].item==undefined) continue;
        el=document.getElementById(prefix+m.item[l].id);
        if (el==undefined) continue;
        el.style.visibility="hidden";   
	menucollapse(prefix,m.item[l],id);
    }
}    

function menutoggle(prefix,parent,id) {
    if (id !=undefined) {
      el=document.getElementById(prefix+id);
      el.style.visibility="visible";          
    }    
    for (var l=0;l<menustack.length;l++) {
        if ((parent !=undefined) && (menustack[l].id !=parent)) continue;
        menucollapse(prefix,menustack[l],id);
    }
}

function menuclose() {
    for (var i=0;i<menuprefix.length;i++) {
      menutoggle(menuprefix[i]); 
    } 
}

function makemenu(prefix,m,d,p) {
    
    menustack.push(m);

    state=m.state;
    if (state==undefined) state=d.state;
 
    style=m.style;
    if (style==undefined) style=d.style;

    click=m.click;
    if (click==undefined) click=d.click;
    
    width="auto";
    if (d.width !=undefined) width=d.width; 
    if (m.width !=undefined) width=m.width;

    document.writeln("<div style=\"position:relative; left:"+d.left+"; top:"+d.top+";\">");    
    document.writeln("<div id=\""+prefix+m.id+"\" ");
    document.writeln("style=\"position:absolute; z-index:+1;  visibility:hidden;\">");   
    document.writeln("<table class=\""+style+"\" style=\"border-collapse:collapse; width:"+width+";\">");
    for (var l=0;l<m.item.length;l++) {
        
        if (m.item[l].item !=undefined) {
            document.writeln(
              "<tr onmouseover=\"menutoggle('"+prefix+"','"+
               m.id+"','"+m.item[l].id+"');"+state+
              "(this,true);\" onmouseout=\""+state+
              "(this,false);\" style=\"vertical-align:top;\">");
            document.writeln("<td class=\""+style+"\">");
	    document.writeln(m.item[l].name);
            document.writeln("</td>");
            document.writeln("<td style=\"text-align:right;\" class=\""+style+"\">");
            document.writeln("&gt;</td><td>");

            makemenu(prefix,m.item[l],d,p);
            document.writeln("</td></tr>");
	} else if (m.item[l].href !=undefined) { 
            document.write("<tr ");
            document.write("onmouseover=\"menutoggle('"+prefix+"','"+m.id+"'); "+
                            state+"(this,true)\" ");
            document.write("onmouseout=\""+state+"(this,false)\" ");
            document.writeln("onclick=\""+state+
			     "(this,false);"+
                             click+"('"+prefix+"','"+m.item[l].href+"');\">");
            
	    document.writeln("<td colspan=\"3\" class=\""+style+"\">"+m.item[l].name);
             
            document.writeln("</td></tr>");
        } else if (m.item[l].click !=undefined) {
            document.write("<tr ");
            document.write("onmouseover=\"menutoggle('"+prefix+"','"+
                            m.id+"'); "+
                            state+"(this,true)\" ");
            document.write("onmouseout=\""+state+"(this,false)\" ");
            document.writeln("onclick=\""+state+
			     "(this,false);"+
                             m.item[l].click+";\">");
            
	    document.writeln("<td colspan=\"3\" class=\""+style+"\">"+m.item[l].name);
             
            document.writeln("</td></tr>");

	} else {
           document.writeln("<tr>");
	   document.write("<td colspan=\"3\">");
           document.writeln(m.item[l].text+"</td></tr>"); 
	}
    }
    document.writeln("</table>");
}   document.writeln("</div></div>");


function makemenubar(prefix,b,d,bstyle) {

    if (d.trigger !=undefined) tcall=d.trigger;
    else tcall="";
    document.writeln("<div><table class=\""+bstyle+"\" style=\"border-collapse:collapse;\">");
    document.writeln("<tr>");
    menuprefix.push(prefix);
    menustack.push(b);
    for (var l=0;l<b.item.length;l++) {
	document.writeln("<td onmouseover=\"menutoggle('"+prefix+"','"+b.id+"','"+
                                           b.item[l].id+"');"+tcall+";\" class=\""+bstyle+"\">");
	document.writeln(b.item[l].name);
	document.writeln("</td>");
        	
    }
    document.writeln("</tr>");
    document.writeln("<tr>");
    for (var l=0;l<b.item.length;l++) {
        document.writeln("<td>");
	makemenu(prefix,b.item[l],d,b.id);
	document.writeln("</div></td>"); 
    }
    document.writeln("</tr>");
    document.writeln("</table></div>");
}

function showpopup(id) {
  el=document.getElementById(id);
  el.style.visibility="visible";
}


function hidepopup(id) {
  el=document.getElementById(id);
  el.style.visibility="hidden";
}

function makepopup(id,style,xoff,yoff,width,height,title,text,chandler) {
  document.writeln("<div id=\""+id+
           "\" style=\"position:absolute;left:"+xoff+";top:"+yoff+
           ";width:"+width+";height:"+height+";visibility:hidden;\" class=\""+style+"\">");
  document.writeln("<table class=\""+style+"\">");
  document.writeln("<tr><td class=\""+style+"\" width=\"100%\">"+title+
                   "</td><td class=\""+style+"\"><a class=\""+style+"\" href=\"javascript:"+chandler+"('"+id+"');\">x</a></td></tr>");
  document.writeln("<tr><td class=\""+style+"\" colspan=\"2%\">"+text+
                   "</td></tr>");
  document.writeln("</table>");
  document.writeln("</div>");
}



