//
// Menusystem V1.0
// © 1999-2001 Kopka.Net Internet Services
//
//

// Find 'f' for 'A[f][O]=V' (f=-1 if not found)
function avf(A,O,V){var f=-1;while(++f<A.length){if(A[f][O]==V){return f}}return -1}


// Map ==> Create a 2 dimensional Map from Packed string, '^' seperates record, '|' seperates entry
function Map(MAP){var f=-1;MAP=MAP.split("^");while(++f<MAP.length){MAP[f]=MAP[f].split('|')}return MAP}


var MS=new Array('','','');
var debug=0;
var Menu
var gb="gfx/"; //the objects to draw the borders (change this if you want to print the page)
var gc="gfx/"; //the objects to draw the content (do not change for page print)

// MIT	is the MenuITem
// PID	is the current PageID
// PN	is a PageName ('index.html')

// return PID for given PN
function P(Page){return PageMap[avf(PageMap,1,Page)][0]}

/*
 Global Variables
*/

var W=700,Y=400
var MD=new Array('','','')
var a=' border="0" vspace="0" hspace="0"'


/*
Make a Menu bar
 PID is the currend PageID
 ==> MD
*/

function MakeMenu(PID) {
 if(document.all){W=window.document.body.clientWidth+(16*useframes)-16}else{W=window.innerWidth+(16*useframes)-16};
 if(document.all){Y=window.document.body.clientHeight-2}else{Y=window.innerHeight-12};
 if(W<=700){W=700};
 if (debug==1) alert('MakeMenu: '+PID);
 var F,M=new Array('','',''),P,S='0000',f=3,ff;
 MD=new Array('','','');
 while(--f>=0){
  P=PID.substr(0,f*2)+S.substr(f*2,99);F=avf(MenuMap,0,P);
  if(F>=0){for(ff=0;ff<3;++ff){tmp=MenuMap[F][ff+1];if(M[ff].length<1){M[ff]=tmp;}}}
 }
 f=-1;while(++f<3){
  M[f]=M[f].split('-')
  ff=-1;while(++ff<M[f].length){
   t=M[f][ff];
   if (debug==1) alert ('f: '+f+' ff: '+ff+' t: '+t+' NID: '+PID.substr(0,f*2)+t+S.substr(f*2,99))
   if (t==''){}else{MD[f]+=t+'|'+GfxMap[t-1]+'|'+PN(PID.substr(0,f*2)+t+S.substr(f*2,99))+'|'+(t==PID.substr(f*2,2)?1:0)+'^'}
  }
  MD[f]=MD[f].substr(0,MD[f].length-1);
 }
}

/*
 locate PN for given PID
 estimate if not directly found
*/
function PN(PID) {
 var x=-1,F,M=new Array('','','');
 while(++x<3){M[x]=PID.substr(x*2,2)}
 F=avf(PageMap,0,PID);
 if (F==-1) {F=(M[2]=='00')?avf(PageMap,0,M[0]+M[1]+'00'):avf(PageMap,0,M[0]+'00'+M[2])}
 if (F==-1) {F=avf(PageMap,0,M[0]+'0000')}
 return (PageMap[F][1]+".html")
}

/*
Draw a Menu bar
 I is the instance
 M is a Map of buttons: GID|width|PN|on,  empty PN creates seperator, fix width by setting it
 G is a Graphic set to use: left|top|right|bottom^left-on|top-on|right-on|bottom-on
 T is the Target frame
 W is the width of the whole bar
*/
function DrawMenu(I,M,G,T,W){
 var f=-1,g,h,i,o,s=0,S=0,Sz=0,w,x,y,z;
 if(debug==2){alert('DrawMenu')};
 M=Map(M);G=Map(G);
 while(++f<M.length){
  w=M[f][0]
  if (w==''){S++}else{s+=(parseInt(M[f][1])+12)}
 }
 S=(W-60-s)/S;
 if (S%1)
 {
	Sz=1
 }
 S+=-(S%1);
 x=Tab(W,48,'#000000')+'<tr>'+
   '<td rowspan="3" width="30" height="48" align="left" valign="top">'+
   '<img src="'+gb+'01.gif" width="30" height="46"'+a+'></td>'
 y='<td rowspan="3" width="30" height="48" align="left" valign="top">'+
   '<img src="'+gb+'02.gif" width="30" height="46"'+a+'></td></tr><tr>'
 z='</tr><tr>'
 f=-1;while(++f<M.length){
  w=M[f][1];
  if(M[f][0]==''){
   // seperator
   x+='<td rowspan="3" width="'+(S+Sz)+'">'+
      '<img src="'+gb+G[0][0]+'.gif" width="'+(S+Sz)+'" height="48"'+a+'></td>'
   if(Sz)
   {
    Sz=0;
   }
  }else{
   o=M[f][3];g=M[f][0];h=M[f][2];
   // button
   x+='<td rowspan="3" width="6" height="48">'+
      '<img src="'+gb+G[o][0]+'.gif" width="6" height="48"'+a+'></td>'+
      '<td width="'+w+'" height="11">'+
      '<img src="'+gb+G[o][1]+'.gif" width="'+w+'" height="11"'+a+'></td>'+
      '<td rowspan="3" width="6">'+
      '<img src="'+gb+G[o][2]+'.gif" width="6" height="48"'+a+'></td>'
   y+='<td height="26" width="'+w+'">'
   //if (x.length>1024){d.write(x);x=''}
   y+='<a href="'+h+'" target="'+T+'"'
   if(o==1){
    // on
    y+='><img src="'+gc+'S'+g+'.gif" height="26" width="'+w+'"'+a+'></a></td>'
   }else{
    // off
    y+=' onMouseOver="Swap(\''+I+f+'\',\'O'+g+'\')" onMouseOut="Swap(\''+I+f+'\',\'M'+g+'\')">'+
       '<img src="'+gc+'M'+g+'.gif" name="'+I+f+'" height="26" width="'+w+'"'+a+'></a></td>'
   }
   z+='<td><img src="'+gb+G[o][3]+'.gif" width="'+w+'" height="11"'+a+'></td>'
  }
 }
 if(debug==2){alert('DrawMenu-1');}
 d.writeln(x+y+z+'</tr></table>');
 if(debug==2){alert('DrawMenu-2');}
}

function DrawInfo(I,W){  /* display the table with the information about the current section */
 d.write(
  Tab(W,48,BGColor)+'<tr>'+
  Edge(20,22,"top")+'<td bgcolor="'+BGColor+'" rowspan="3" align="center" width="'+(W-60)+'" class="head"><font color="#000080">'+I+'</font></td>'+Edge(21,23,"top")+'</tr>'+
  '<tr><td background="'+gb+'22.gif" height="16" width="30" class="fill"><img src="'+gb+'22.gif" border="0"></td>'+
  Edge(23,23,"bottom")+'</tr><tr>'+Edge(24,24,"bottom")+Edge(25,23,"bottom")+'</tr></table>'
 )
}
function Edge(I,B,A){return ('<td width="30" height="16" valign="'+A+'" background="'+gb+B+'.gif"><img src="'+gb+I+'.gif" width="30" height="16"'+a+'></td>')}


function Tab(W,Y,C){return ('<table width="'+W+'" height="'+Y+'" bgcolor="'+C+'" cellspacing="0" cellpadding="0"'+a+'>')}

function Page_MenuInit(){  /* Prepare the Menu and write Script to swap the Images */
 d.writeln('<script language="JavaScript">function Swap(EID,PIC){document.images[EID].src="'+gc+'"+PIC+".gif"}</script>');
}
