function menu(destDiv,varname,destTd){
       
      //---------------------variables----------------------------------------
         var myajax=new ajaxObject("","includes/ajax_db_ops.php",varname+".returFunction");  
         var that=this;
         this.destDiv=document.getElementById(destDiv);
         
         this.splitter="";
         
         var subpad=document.createElement("div");
         subpad.style.position="absolute";
         subpad.style.top="0px";
         this.destDiv.appendChild(subpad);
         
         document.getElementById("contenttd").onmouseover=function(){
            subpad.style.visibility="hidden";
         }
         document.getElementById("lefttd").onmouseover=function(){
            subpad.style.visibility="hidden";
         }
         
         var currenty=0;
         this.categsdiv=document.createElement("div");
         this.backdiv=document.createElement("div");
         
         this.destDiv.appendChild(this.backdiv);
         this.destDiv.appendChild(this.categsdiv);
         
         
         this.backdiv.style.zIndex=2;
         this.categsdiv.style.zIndex=3;
         
         this.destDiv.style.position="absolute";
         this.destDiv.style.zIndex=100;
         
         
         this.backdiv.style.position="absolute";
         this.categsdiv.style.position="absolute";
        
         
         
         var branch=new Array();
         var lastsubover=null;
         
         
          
        
         
      //----------------------------------------------------------------------
      //--------------------------ajax functions------------------------------
      this.returFunction=function(what,whatop){
        
        switch(whatop){
          case 1: // in caz ca am cerut nivel 1 si 2
            var curparent="";
            var totaly=0;;
            var tmphead=document.createElement("img");
            tmphead.src="imgs/menu/header.png";
            tmphead.style.position=="absolute";
            this.backdiv.appendChild(tmphead);
            tmphead.style.top="0px";
            
            tmpback=document.createElement("img"); // desenez si asez backgorund-ul
            tmpback.src="imgs/menu/menuback.png";
            tmpback.style.position="absolute";
            tmpback.style.top="31px";
            tmpback.style.left="0px";
            this.backdiv.appendChild(tmpback); 
            
            
           
            /*this.categsdiv.onmouseover=function(){
              subpad.style.visibility="hidden";
            }*/
            
            var curparent="";  // o sa-i folosesc ca sa refac ierarhia
            var curparentid=0;
            
            var broken=what.split(this.splitter);
            var cnt=0;
            var levels=new Array();
            var contors=new Array();
            var curlvl=0;
            while(cnt<broken.length-1){
               var nrchildren=broken[cnt];
               cnt++;
               var childid=broken[cnt];
               cnt++;
               var childname=broken[cnt];
               cnt++;
               var nextchildren=broken[cnt];
               
               if(nrchildren>0){
                 curlvl++;
                 levels[curlvl-1]=nrchildren;
                 contors[curlvl-1]=0;  
               }
               while(contors[curlvl-1]>=levels[curlvl-1] && curlvl>0){
                   curlvl--;
               }  
               contors[curlvl-1]++;
              
               switch(curlvl){
               
                  case 1:
                     curparent=childname;
                     var newchild=this.generateCateg(childname);
                     this.categsdiv.appendChild(newchild);
                     newchild.style.position="absolute";
                     newchild.style.top=totaly+"px";
                     totaly+=34;
                  break;
                  case 2:
                  var newchild=null;
                   if(nextchildren==0){
                     newchild=this.generateBut(childname,true,childid,totaly,curparent);
                     this.categsdiv.appendChild(newchild);
                   }else{
                     newchild=this.generateBut(childname,false,childid,totaly,curparent);
                     this.categsdiv.appendChild(newchild);
                      
                   }
                   newchild.style.position="absolute";
                   newchild.style.top=(totaly)+"px";
                   totaly+=22;
                  break;  
               }
             }
          
            // aranjez background-ul
            
             
            
             tmpback.style.height=(totaly)+"px";
             tmpback.style.width=(230)+"px";
             
          
              tmpfoot=document.createElement("img");
              tmpfoot.src="imgs/menu/footer.png";
              tmpfoot.style.position="absolute";
              tmpfoot.style.top=(31+totaly)+"px";
              tmpfoot.style.left="0px";
              this.backdiv.appendChild(tmpfoot);
              
              // desenez subpadul
              this.generatesubpad(subpad);
                
                //subpad.style.visibility="hidden";
                
               
               
                this.categsdiv.style.top=(31)+"px";
                subpad.style.top=(-2*this.categsdiv.offsetHeight)+"px";
                
                this.backdiv.style.height=(18+31+totaly)+"px";
                this.destDiv.style.width=230+"px";
               
                this.destTd=document.getElementById(destTd);
                
               // alert(this.backdiv.offsetHeight);
                this.destDiv.style.height=(18+31+totaly)+"px";
                this.destTd.style.background="#FFFFFF";
                this.destTd.style.height=(18+31+totaly)+"px";
                //this.destTd.style.background="#FF0000";
                //this.destDiv.style.position="reliative";
             //this.destDiv.style.visibility="hidden";
             
             document.getElementById("contenttable").style.height=document.getElementById("contenttd").offsetHeight+"px";
         
             var contenttd=document.getElementById("contenttd");
             var menudiv=document.getElementById("mainmenudiv");
             var filterstd=document.getElementById("filterstd");
             var filtersdiv=document.getElementById("filtersdiv");
             var refultd=document.getElementById("filltd");
             //alert(menudiv.offsetHeight);
             //alert(contenttd.offsetHeight);
             //alert(filterstd.offsetHeight);
             //filterstd.style.height=(contenttd.offsetHeight-menudiv.offsetHeight)+"px";
             refultd.style.height=(contenttd.offsetHeight-menudiv.offsetHeight-filtersdiv.offsetHeight)+"px";
          break;
          case 2:  // in caz ca cer nivel 3
            this.fillsubpad(what,currenty);
          
          break;
          
          case 3: // requested splitter
           this.splitter=what;
           backtmp.src="imgs/menu/menuback.png";
          break;
        }
     }
     
        
      //----------------------------------------------------------------------
      this.fillsubpad=function(what,whaty){  // desenez padul separat cu subcategorii de nivel 3
        var backdiv=subpad.getElementsByTagName("div")[0];
        backdiv.onmouseout=function(){
          //alert(that.mouseX+","+that.mouseY);
         // alert(backdiv.offsetLeft);
        
        }
        var filldiv=subpad.getElementsByTagName("div")[1];
        filldiv.innerHTML="";
        
        var broken=what.split(this.splitter);
        var cnt=0;
        var pos=10;
        while(cnt<broken.length-1){
            var tmpchildren=broken[cnt];
            cnt++;
            var tmpid=broken[cnt];
            cnt++;
            var tmpname=broken[cnt];
            cnt++;
                    
               
           var tmpdiv=document.createElement("div");
           /*var tmplink=document.createElement("font");
           tmplink.href="?cmd=list&id="+tmpid;
           tmplink.innerHTML=tmpname;
           tmplink.style.textDecoration="none";*/
           
           
           tmpdiv.style.width="180px";
           tmpdiv.style.position="absolute";
           tmpdiv.style.top=(pos)+"px";
          
           var tmpfont=document.createElement("font");
           
           tmpfont.innerHTML="<a href=\"?cmd=list&id="+tmpid+"\" style=\"text-decoration:none;color:#385098\">"+tmpname+"</a>";
           
           tmpfont.style.color="#385098";
           tmpfont.style.position="relative";
           tmpfont.style.fontFamily="Arial";
           tmpfont.style.fontSize="14px";
           tmpfont.style.top="8px";
           tmpfont.style.left="29px";
           
           tmpdiv.onmouseover=function(){
            
             var fnt=this.getElementsByTagName("font")[0].getElementsByTagName("a")[0];
             fnt.style.color="#000000";   
            
           }
           
           tmpdiv.onmouseout=function(){// nu e bine
            
          
             
            var fnt=this.getElementsByTagName("font")[0].getElementsByTagName("a")[0];
             fnt.style.color="#385098";   
           
           }
          
          
            tmpdiv.appendChild(tmpfont);
            filldiv.appendChild(tmpdiv); 
          
        
          
          pos+=tmpdiv.offsetHeight+19; 
          if(cnt<broken.length-3){ 
           var tmpimg=document.createElement("img");
           tmpimg.src="imgs/menu/subpadline.png";
           tmpimg.style.position="absolute";
           tmpimg.style.top=(pos)+"px";
           filldiv.appendChild(tmpimg);
          }
          
          
          
        }
        
      
       var underdiv=subpad.getElementsByTagName("div")[0];
        var backimg=underdiv.getElementsByTagName("img")[1];
        var actwidth=222;//backimg.width;
        //alert(actwidth);
        backimg.style.height=(pos-15)+"px";
        backimg.style.width=actwidth+"px";
        
        subpad.style.top=(whaty+15)+"px";
        subpad.style.left=(230)+"px";
        subpad.style.visibility="";
      
      }
      
      
      this.generatesubpad=function(whatdiv){  // generez padul cu subcategorii de nivel 3
         var maindiv=whatdiv;
        
         var underdiv=document.createElement("div");
         var overdiv=document.createElement("div");
         maindiv.appendChild(underdiv);
         maindiv.appendChild(overdiv);
         
         
         
         underdiv.style.position="absolute";
         overdiv.style.position="absolute";
         underdiv.style.zIndex=11;
         overdiv.style.zIndex=12;
         
         underdiv.innerHTML="<img src=\"imgs/menu/subpadheader.png\">";
         underdiv.innerHTML+="<img src=\"imgs/menu/subpadmiddle.png\">";
         underdiv.innerHTML+="<img src=\"imgs/menu/subpadfooter.png\">";
         maindiv.style.position="absolute";
         maindiv.style.zIndex=10;
         maindiv.style.height="0px";
         maindiv.style.visibility="hidden";
                 
      }
      
      
      this.generateCateg=function(titletxt){  // generez o categorie (antetul)
        var tmpdiv=document.createElement("div");
         tmpdiv.style.position="absolute";
         tmpdiv.style.width="230px";
         tmpdiv.style.height="34px";
         
         tmpdiv.style.background="url('imgs/menu/maincateg.png')";
         
         
         var tmpfont=document.createElement("font");
         tmpfont.innerHTML=titletxt.toUpperCase();
         tmpfont.align="left";
         
         
         tmpfont.style.position="relative";
         tmpfont.style.top="8px";
         tmpfont.style.left="29px";
         
         tmpfont.style.color="#FFFFFF";
         tmpfont.style.fontFamily="Arial";
         tmpfont.style.fontSize="14px";
         tmpfont.style.fontWeight="Bold";
         tmpfont.style.textShadow="#385098 1px 1px";
         tmpdiv.appendChild(tmpfont);
        
         return (tmpdiv);      
      }
      
      this.generateBut=function(titletxt,hasplus,whatid,whaty,parenttxt){ // generez un buton cu plus (o subcategorie)
                    
           var tmpdiv=document.createElement("div");
           tmpdiv.style.width="230px";
           tmpdiv.style.height="22px";
           
           
          
           var tmpfont=document.createElement("font");
           tmpfont.innerHTML=titletxt;
           tmpfont.style.color="#FFFFFF";
           tmpfont.style.position="relative";
           tmpfont.style.fontFamily="Arial";
           tmpfont.style.fontSize="14px";
           tmpfont.style.textShadow="#385098 1px 1px";
         
           
           
          if(hasplus){ 
           var tmpimg=document.createElement("img");
           tmpimg.src="imgs/menu/plus.png";
           tmpdiv.appendChild(tmpimg);
              tmpfont.style.top="-5px";
              tmpfont.style.left="1px";
           
           }else{
              tmpfont.style.top="4px";
              tmpfont.style.left="29px";
           }
           
           
           tmpdiv.appendChild(tmpfont);
           
           if(!hasplus){
              tmpdiv.onclick=function(){
                  location.href="?cmd=list&id="+whatid;
              }
           }
          
           
           tmpdiv.onmouseover=function(){
              // alcatuiesc traseul in categorii
              if(lastsubover!=null){
                 lastsubover.style.background="transparent";
                 var tmpf=lastsubover.getElementsByTagName("font")[0];
               //  tmpf.style.color="#FFFFFF";
              
              }
              lastsubover=this; 
              branch[0]=parenttxt;
              branch[1]=titletxt;
              branch.length=2;

             this.style.background="url(imgs/menu/subcategover.png)";
             if(hasplus){
                 myajax.setRequest("op=get_categs&parent="+whatid+"&levels=1",2);
                 currenty=whaty;
             }else{
                subpad.style.visibility="hidden";
                tmpdiv.style.overflow="hidden";
             }
             var tmpf=this.getElementsByTagName("font")[0];
             //tmpf.style.fontWeight="BOLD";
             //tmpf.style.color="#385098";
             this.style.cursor="pointer";
           }
           
         
          
           return (tmpdiv);
      }
   
   
   
   var backtmp=document.createElement("img");
   backtmp.onload=function(){
      myajax.setRequest("op=get_categs&parent=0&levels=2",1);
   }
   
    myajax.setRequest("op=getsplitter",3);
   
}

