var stat = new Array();
    var merk_group = '';
    var all_group = '';
    var add = '';
    var m_id = 0;
    
    function set_highlight (button) {
    if (document.getElementById(button+'_img')) {
      document.getElementById(button+'_img').style.backgroundImage = 'url('+stat[button]['img_sel']+')';
      document.getElementById(button+'_label').style.color = '#ffffff';
      document.getElementById(button+'_label').style.fontWeight = 'bold';
      if (button.length>=7) {
        document.getElementById(button+'_label').style.color = '#099d00';
        document.getElementById(button+'_label').style.fontWeight = 'bold';
      } 
      if (button.length==5) {
        document.getElementById(button+'_label').style.color = '#ffffff';
        document.getElementById(button+'_label').style.fontWeight = 'bold';
      }
      h='';
      t = button.split('_');
      for (i=0; i<t.length; i++) {
        h += t[i]+'_'; 
      }
      h = h.substr(0, h.length-1);
      for (i=0; i<t.length; i++) {
        h = h.substr(0, h.length-2);
        if (document.getElementById(h+'_img')) {
          document.getElementById(h+'_img').style.backgroundImage = 'url('+stat[h]['img_sel']+')';
        }
      }
    }
    }
    
    function set_active (c) {
      //document.getElementById('check').innerHTML = 'CHECK: ';
      c_list = c.split('|');
      for (i=0; i<c_list.length; i++) {
        if (document.getElementById(c_list[i])) {
          stat[c_list[i]]['status'] = true;
        }
      }
      hm = c_list[0].split('_');
      
      add = '';
      for (i=0;i<20;i++) {
      
        if (document.getElementById('0_'+hm[1]+'_'+i)) {
          
          //document.getElementById('check').innerHTML += hm[1]+'_'+i+' | ';
          stat['0_'+hm[1]+'_'+i]['status'] = true;
          add+='0_'+hm[1]+'_'+i+'|';
        }
      }
      for (j=0;j<20;j++) {
      //document.getElementById('check').innerHTML += '0_'+hm[1]+'_'+hm[2]+'_'+j+' | ';
        if (document.getElementById('0_'+hm[1]+'_'+hm[2]+'_'+j)) {
          stat['0_'+hm[1]+'_'+hm[2]+'_'+j]['status'] = true;
          add+='0_'+hm[1]+'_'+hm[2]+'_'+j+'|';
        }      
      }
      for (k=0;k<20;k++) {
      //document.getElementById('check').innerHTML += '0_'+hm[1]+'_'+hm[2]+'_'+j+' | ';
        if (document.getElementById('0_'+hm[1]+'_'+hm[2]+'_'+hm[3]+'_'+k)) {
          stat['0_'+hm[1]+'_'+hm[2]+'_'+hm[3]+'_'+k]['status'] = true;
          add+='0_'+hm[1]+'_'+hm[2]+'_'+hm[3]+'_'+k+'|';
        }      
      }
    }

    function open_submenu (c) {
      list = '';
      c_list = c.split('|');
      for (i=0; i<c_list.length; i++) {
        
        if (document.getElementById(c_list[i])) {
          if (stat[c_list[i]]['status']) { 
            document.getElementById(c_list[i]).style.height = stat[c_list[i]]['height']+'px';
            document.getElementById(c_list[i]+'_img').style.height = stat[c_list[i]]['height']+'px';
            document.getElementById(c_list[i]).style.fontSize = '12px';
            document.getElementById(c_list[i]+'_link').style.fontSize = '12px';
            document.getElementById(c_list[i]+'_link').style.visibility = 'visible';
            document.getElementById(c_list[i]).style.display = 'block';
            if (c_list[i].length>=5) {
              document.getElementById(c_list[i]+'_label').style.fontSize = '12px';
              document.getElementById(c_list[i]+'_label').style.visibility = 'visible';
            }
            
            if (c_list[i].length>=7) {
              document.getElementById(c_list[i]+'_label').style.fontSize = '10px';
              document.getElementById(c_list[i]+'_label').style.visibility = 'visible';
            }
            
            if (stat[c_list[i]]['target_group']) {
              merk_group += stat[c_list[i]]['target_group']+'|';
            }
          }
        }
      }
      list = merk_group;
      if (list != '') {
        merk_group = '';
        list = list.substr(0, list.length-1);
        open_submenu (list);
      }
      merk_group = '';
    }

    function close_submenu (c) {
      list = '';
      c_list = c.split('|');
      for (i=0; i<c_list.length; i++) {
        if (document.getElementById(c_list[i])) {
          document.getElementById(c_list[i]).style.height = '0px';
          document.getElementById(c_list[i]+'_img').style.height = '0px';
          document.getElementById(c_list[i]+'_img').style.backgroundImage = 'url('+stat[c_list[i]]['img_norm']+')';
          document.getElementById(c_list[i]).style.fontSize = '0px';
          document.getElementById(c_list[i]+'_link').style.fontSize = '0px';
          document.getElementById(c_list[i]+'_link').style.visibility = 'hidden';
          if (stat[c_list[i]]['target_group']) {
            merk_group += stat[c_list[i]]['target_group']+'|';
          }
        }
      }
      list = merk_group;
      if (list != '') {
        merk_group = '';
        list = list.substr(0, list.length-1);
        close_submenu (list);
      }
    }
    
    function close_all_subs (c,id) {
      list = '';
      c_list = c.split('|');
      for (i=0; i<c_list.length; i++) {
        if (document.getElementById(c_list[i])) {
          if (c_list[i].length>3) {
            document.getElementById(c_list[i]).style.height = '0px';
            document.getElementById(c_list[i]+'_img').style.height = '0px';
            
            if (c_list[i].split('_')[0]!=anav) {
              document.getElementById(c_list[i]+'_img').style.backgroundImage = 'url('+stat[c_list[i]]['img_norm']+')';
            }
            document.getElementById(c_list[i]).style.fontSize = '0px';
            document.getElementById(c_list[i]+'_link').style.fontSize = '0px';
            document.getElementById(c_list[i]+'_link').style.visibility = 'hidden';
            document.getElementById(c_list[i]+'_label').style.fontWeight = 'normal';
            document.getElementById(c_list[i]).style.display = 'none';
            if (c_list[i].length>=5) {
              document.getElementById(c_list[i]+'_label').style.fontSize = '0px';
              document.getElementById(c_list[i]+'_label').style.visibility = 'hidden';
            }
            
            if (c_list[i].length>=7) {
              document.getElementById(c_list[i]+'_label').style.fontSize = '0px';
              document.getElementById(c_list[i]+'_label').style.visibility = 'hidden';
            }
            
            if (c_list[i]!=id) {
              stat[c_list[i]]['status'] = false;
            }
          } else {
            document.getElementById(c_list[i]+'_img').style.backgroundImage = 'url('+stat[c_list[i]]['img_norm']+')';
          }
        }
      }
    }
    
    function check_status(id) {
   
      anav = '0_'+id.split('_')[1]; 
      //alert(anav);
      close_all_subs (all_group,id);
      //open_submenu (anav);
      
      set_highlight(anav);
      set_active(anav);
       //alert(id);
      if (id.length>=7) {
      
        set_highlight(anav+'_'+id.split('_')[2]);
        set_active(anav+'_'+id.split('_')[2]);
      }
      //alert(anav+'_'+id.split('_')[2]);
      if (stat[id]['status']) {
        stat[id]['status'] = false;
        document.getElementById(stat[id]['group']).style.backgroundImage = 'url('+stat[id]['img_sel']+')';
        
        open_submenu(stat[id]['target_group']);
        set_active(id+'|'+stat[id]['target_group']);
        open_submenu (id+'|'+stat[id]['target_group']+'|'+add);
        //set_highlight(id);
        
        set_active(id+'|'+stat[id]['target_group']);
        set_highlight(id);
        
      } 
    }
    
    function create_entry (container,title,action,link,has_child,status,group,img_norm,img_sel,w,h,direct) {
      all_group += group+'|'; stat[group] = new Array(); stat[group]['status'] = status; stat[group]['group'] = group+'_img';
      stat[group]['parent'] = container; stat[group]['img_norm'] = img_norm; stat[group]['img_sel'] = img_sel; stat[group]['height'] = h;
      stat[group]['target_group'] = action; hm = stat[group]['group'].split('_'); anav = hm[1];
      if (document.getElementById(container)) {
        if (status) {
          if (group.length==3) {
            if (direct) {
              document.getElementById(container).innerHTML += '<div id="'+group+'" style="height:'+h+'px; width:196px; font-size:12px;"><a id="'+group+'_link" href="'+link+'?mid='+group+'&akt_nav='+anav+'" onclick="" style="cursor:hand; font-size:12px; visibility:visible; text-decoration:none;"><div id="'+group+'_img" style="width:'+w+'px; height:'+h+'px; background-image:url('+img_norm+'); background-repeat:no-repeat;"><div id="'+group+'_label" style="position:relative; width:110px; background-color:red; cursor:hand; text-align:right; left:35px; top:25px; font-weight:bold; color:#333333;"><div style="text-align:right; width:110px; position:absolute; left:1px; top:1px; font-family:arial; font-size:15px; font-weight:bold; font-style:italic; color:#333333;">'+title+'</div><div style="text-align:right; width:110px; position:absolute; left:2px; top:2px; font-family:arial; font-size:15px; font-weight:bold; font-style:italic; color:#333333;">'+title+'</div><div style="text-align:right; width:110px; position:absolute; left:1px; top:0px; font-family:arial; font-size:15px; font-weight:bold; font-style:italic; color:#ffffff;">'+title+'</div></div></div></a></div>';
            } else {
              document.getElementById(container).innerHTML += '<div id="'+group+'" style="height:'+h+'px; width:196px; font-size:12px;"><a id="'+group+'_link" href="javascript:check_status(\''+group+'\');" onclick="" style="cursor:hand; font-size:12px; visibility:visible; text-decoration:none;"><div id="'+group+'_img" style="width:'+w+'px; height:'+h+'px; background-image:url('+img_norm+'); background-repeat:no-repeat;"><div id="'+group+'_label" style="position:relative; width:110px; background-color:red; cursor:hand; text-align:right; left:35px; top:25px; font-weight:bold; color:#333333;"><div style="text-align:right; width:110px; position:absolute; left:1px; top:1px; font-family:arial; font-size:15px; font-weight:bold; font-style:italic; color:#333333;">'+title+'</div><div style="text-align:right; width:110px; position:absolute; left:2px; top:2px; font-family:arial; font-size:15px; font-weight:bold; font-style:italic; color:#333333;">'+title+'</div><div style="text-align:right; width:110px; position:absolute; left:1px; top:0px; font-family:arial; font-size:15px; font-weight:bold; font-style:italic; color:#ffffff;">'+title+'</div></div></div></a></div>';
            }
          } else { //'+link+'?mid='+group+'&akt_nav='+anav+'
            document.getElementById(container).innerHTML += '<div id="'+group+'" style="height:'+h+'px; width:196px; font-size:12px;"><a id="'+group+'_link" href="javascript:check_status(\''+group+'\');" onclick="" style="cursor:hand; font-size:12px; visibility:visible; text-decoration:none;"><div id="'+group+'_img" style="width:'+w+'px; height:'+h+'px; background-image:url('+img_norm+'); background-repeat:no-repeat;"><div id="'+group+'_label" style="position:relative; cursor:hand; text-align:left; top:12px; color:#ffffff; font-weight:normal;">'+title+'</div></div></a></div>';
          }
        } else {
          
          if (group.length>=9) {
            document.getElementById(container).innerHTML += '<div class="link_off" id="'+group+'"><a id="'+group+'_link" href="'+link+'?mid='+group+'&akt_nav='+anav+'" onclick="" style="text-decoration:none;"><div id="'+group+'_img" style="width:'+w+'px; height:0px; background-image:url('+img_norm+'); background-repeat:no-repeat;"><div id="'+group+'_label" style="position:relative; cursor:hand; text-align:left; left:5px; top:15px; color:#099d00; font-size:0px; visibility:hidden;">'+title+'</div></div></a></div>';
          }
          if (group.length>=7) {
            if (direct) {
              document.getElementById(container).innerHTML += '<div class="link_off" id="'+group+'"><a id="'+group+'_link" href="'+link+'?mid='+group+'&akt_nav='+anav+'" onclick="" style="text-decoration:none;"><div id="'+group+'_img" style="width:'+w+'px; height:0px; background-image:url('+img_norm+'); background-repeat:no-repeat;"><div id="'+group+'_label" style="position:relative; cursor:hand; text-align:left; left:5px; top:15px; color:#099d00; font-size:0px; visibility:hidden;">'+title+'</div></div></a></div>';
            } else {
              document.getElementById(container).innerHTML += '<div class="link_off" id="'+group+'"><a id="'+group+'_link" href="javascript:check_status(\''+group+'\');" onclick="" style="text-decoration:none;"><div id="'+group+'_img" style="width:'+w+'px; height:0px; background-image:url('+img_norm+'); background-repeat:no-repeat;"><div id="'+group+'_label" style="position:relative; cursor:hand; text-align:left; left:5px; top:15px; color:#099d00; font-size:0px; visibility:hidden;">'+title+'</div></div></a></div>';
            }
          }
          if (group.length>=5) {
            if (direct) {
              document.getElementById(container).innerHTML += '<div class="link_off" id="'+group+'"><a id="'+group+'_link" href="'+link+'?mid='+group+'&akt_nav='+anav+'" onclick="" style="text-decoration:none;"><div id="'+group+'_img" style="width:'+w+'px; height:0px; background-image:url('+img_norm+'); background-repeat:no-repeat;"><div id="'+group+'_label" style="position:relative; cursor:hand; text-align:left; left:5px; top:15px; color:#ffffff; font-size:0px; visibility:hidden;">'+title+'</div></div></a></div>';
            } else {
              document.getElementById(container).innerHTML += '<div class="link_off" id="'+group+'"><a id="'+group+'_link" href="javascript:check_status(\''+group+'\');" onclick="" style="text-decoration:none;"><div id="'+group+'_img" style="width:'+w+'px; height:0px; background-image:url('+img_norm+'); background-repeat:no-repeat;"><div id="'+group+'_label" style="position:relative; cursor:hand; text-align:left; left:5px; top:15px; color:#ffffff; font-size:0px; visibility:hidden;">'+title+'</div></div></a></div>';
            }
          }

          
        }
        if (has_child) {
          tab_s = '<div><div><div id="'+title+'_'+group+'" cellspacing="0" cellpadding="0" border="0">';
          tab_e = '</div></div></div>';
          document.getElementById(container).innerHTML += tab_s+tab_e;
        }
      }
    }
    
    function create_menu (id,container) {
      tab_s = '<div id="'+container+'_tabmenu'+id+'" cellspacing="0" cellpadding="0" border="0" style="margin-bottom:10px;">';
      tab_e = '</div>';
      if (document.getElementById(container)) {
        document.getElementById(container).innerHTML += tab_s+tab_e;
      }
    }
    
    function init_jsmenu(mid) {
      //document.getElementById('check').innerHTML = '';
      if (mid!="0") {
        all_group = all_group.substr(0, all_group.length-1);
        //document.getElementById('check').innerHTML = all_group;
        open_submenu (all_group);
        close_all_subs (all_group);
        /*
        set_active(mid+'|'+stat[mid]['target_group']);
        open_submenu (mid+'|'+stat[mid]['target_group']+'|'+add);
        //set_highlight(mid);
        set_highlight(mid);
        set_active(mid);
        anav = mid.split('_')[0]+'_0'; 
        set_highlight(anav);
        set_active(anav);
        
        set_highlight(anav+'_'+mid.split('_')[2]);
        set_active(anav+'_'+mid.split('_')[2]);
        */
      } else {
        all_group = all_group.substr(0, all_group.length-1);
        //document.getElementById('check').innerHTML = all_group;
        open_submenu (all_group);
        close_all_subs (all_group);
        //document.getElementById('check').innerHTML ='';
        //open_submenu (mid+'|'+stat[mid]['target_group']+'|'+add);
      }
    }