// Title: Tigra Tree
// Description: See the demo at url
// URL: http://www.softcomplex.com/products/tigra_menu_tree/
// Version: 1.1
// Date: 11-12-2002 (mm-dd-yyyy)
// Notes: This script is free. Visit official site for further details.

function tree (a_items, a_template, o_div ) {
  this.a_tpl      = a_template;
  this.a_config   = a_items;
  this.o_root     = this;
  this.a_index    = [];
  this.o_selected = null;
  this.n_depth    = -1;
  this.b_children = false;

  this.o_root.ajax = createXmlHttpRequestObject();
  
  var o_icone = new Image(),
      o_iconl = new Image();
  o_icone.src = a_template['icon_e'];
  o_iconl.src = a_template['icon_l'];
  a_template['im_e'] = o_icone;
  a_template['im_l'] = o_iconl;
  for (var i = 0; i < 64; i++)
    if (a_template['icon_' + i]) {
      var o_icon = new Image();
      a_template['im_' + i] = o_icon;
      o_icon.src = a_template['icon_' + i];
    }

  this.toggle = function (n_id) {  var o_item = this.a_index[n_id]; o_item.open(o_item.b_opened) };
  this.select = function (n_id) { return this.a_index[n_id].select(); };
  this.mout   = function (n_id) { this.a_index[n_id].upstatus(true) };
  this.mover  = function (n_id) { this.a_index[n_id].upstatus() };
  this.expand = function (path) { this.a_children[0].expand(path) };

  this.a_children = [];
  for (var i = 0; i < a_items.length; i++)
    new tree_item(this, i);

  this.b_children  = (this.a_children.length > 0);

  this.n_id = trees.length;
  trees[this.n_id] = this;

  if( o_div ){
      var html = '';
      for (var i = 0; i < this.a_children.length; i++) {
         html += this.a_children[i].init_once( false );
      }

      o_div.innerHTML = html;
  }else{
      for (var i = 0; i < this.a_children.length; i++) {
         this.a_children[i].init_once( true );
      }
  }
  

  if( this.o_selected )
     this.o_selected.select();
}

function tree_item (o_parent, n_order) {

  this.n_depth  = o_parent.n_depth + 1;
  this.a_config = o_parent.a_config[n_order + (this.n_depth ? 4 : 0)];

  if (!this.a_config) return;

  this.o_root    = o_parent.o_root;
  this.o_parent  = o_parent;
  this.n_order   = n_order;
  this.b_opened  = this.a_config[2];
  this.b_selected = this.a_config[3];
  this.b_children = false;
  
  if( this.b_selected  ){
      this.o_root.o_selected = this;
  }

  this.n_id = this.o_root.a_index.length;
  this.o_root.a_index[this.n_id] = this;
  o_parent.a_children[n_order] = this;

  this.a_children = [];
  
  if( typeof( this.a_config[4] ) == 'boolean' ){
      this.b_children = this.a_config[4];
  }else if( this.a_config.length - 4 > 0 ) {
      this.b_children = true;
      for (var i = 0; i < this.a_config.length - 4; i++)
          new tree_item(this, i);
          
  }


  this.get_icon = item_get_icon;
  this.open     = item_open;
  this.select   = item_select;
  this.init_once= item_init_once;
  this.init     = item_init;
  this.handle_response = item_handle_response;
  this.find_id  = item_find_id;
  this.expand   = item_expand;
  

  this.upstatus = item_upstatus;
  this.is_last  = function () { return this.n_order == this.o_parent.a_children.length - 1 };

}

function item_open (b_close) {
  var o_idiv = get_element('i_div' + this.o_root.n_id + '_' + this.n_id);
  if (!o_idiv) return;

  var o_self = this;
  //alert('innerHTML=' + o_idiv.innerHTML + ',\nouterHTML=' + o_idiv.outerHTML + ',');
  
  if ( !o_idiv.innerHTML ) {
    if( this.b_children &&  this.a_children.length == 0 ){
        //jesli ma dzieci, ale tablica jest pusta to trzeba pobrać z serwera

        server_connect( this.o_root.ajax, this.o_root.a_tpl['url'] + this.find_id(), function( xml, txt ){ o_self.handle_response( xml, txt ) });
    }else{
        var a_children = [];
        for (var i = 0; i < this.a_children.length; i++)
          a_children[i]= this.a_children[i].init();

        o_idiv.innerHTML = a_children.join('');
    }
  }
  o_idiv.style.display = (b_close ? 'none' : 'block');
  this.b_opened = !b_close;

  //o_idiv.style.display = (this.b_opened ?'block' : 'none'  );
  //this.b_opened = !this.b_opened;
  var o_jicon = document.images['j_img' + this.o_root.n_id + '_' + this.n_id],
      o_iicon = document.images['i_img' + this.o_root.n_id + '_' + this.n_id];
  if (o_jicon) o_jicon.src = this.get_icon(true);
  if (o_iicon) o_iicon.src = this.get_icon();
  this.upstatus();
}

function item_select (b_deselect) {
  if ( !b_deselect ) {
    var o_olditem = this.o_root.o_selected;
    this.o_root.o_selected = this;
    if (o_olditem) o_olditem.select(true);
  }

  //var o_iicon = document.images['i_img' + this.o_root.n_id + '_' + this.n_id];
  //if (o_iicon) o_iicon.src = this.get_icon();

  var el = get_element('i_txt' + this.o_root.n_id + '_' + this.n_id);
  if( b_deselect ){
      el.className = 't' + this.o_root.n_id + 'i';
  }else{
      el.className = 't' + this.o_root.n_id + 'i_selected';
  }

  get_element('i_txt' + this.o_root.n_id + '_' + this.n_id).style.fontWeight = b_deselect ? 'normal' : 'bold'

  

  //get_element('i_txt' + this.o_root.n_id + '_' + this.n_id).style.border = b_deselect ? '' : 'solid 1px blue;';
  //get_element('i_td' + this.o_root.n_id + '_' + this.n_id).style.background = b_deselect ? '' : '#efefef';

  this.upstatus();
  return Boolean(this.a_config[1]);
}

function item_upstatus (b_clear) {
  //alert(this.a_config[1].replace(/"/g,'\\"'));
  window.setTimeout('window.status="' + (b_clear ? '' : this.a_config[0].replace(/"/g,'\\"') + (this.a_config[1] ? ' ('+ this.a_config[1].replace(/"/g, '\\"') + ')' : '')) + '"', 10);
}

function item_init(){
  var a_offset = [],
  o_current_item = this.o_parent;
  for (var i = this.n_depth; i > 1; i--) {
    a_offset[i] = '<img src="' + this.o_root.a_tpl[o_current_item.is_last() ? 'icon_e' : 'icon_l'] + '" border="0" align="absbottom">';
    o_current_item = o_current_item.o_parent;
  }

  var a_found = [];
  var img = '';
  if( a_found = this.a_config[0].match(/<img[^>]+> /) ){
      this.a_config[0] = this.a_config[0].replace(/<img[^>]+> /, '')
      var img = a_found[0];
  }else{
      img = ' ';
  }
  
  if( this.n_depth == 0 ){
        if( this.a_config[0].length > 20 ){
            pos = 0; pos1 = this.a_config[0].indexOf(' ');
              while( pos1 != -1 && pos1 < 16 ){
                pos = pos1;  pos1 = this.a_config[0].indexOf(' ', pos+1);
              }

              if(pos == 0){ pos = 16; }

            return '<table cellpadding="0" cellspacing="0" border="0" class=tree_tab><tr><td nowrap id="i_td'+ this.o_root.n_id + '_' + this.n_id+'" >' + (this.n_depth ? a_offset.join('') + (this.b_children
                     ? '<a href="javascript: trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')"><img src="' + this.get_icon(true) + '" border="0" align="absbottom" name="j_img' + this.o_root.n_id + '_' + this.n_id + '"></a>'
                     : '<img src="' + this.get_icon(true) + '" border="0" align="absbottom">') : '')
                     + '<a href="' + this.a_config[1] + '" target="' + this.o_root.a_tpl['target'] + '" onclick="return trees[' + this.o_root.n_id + '].select(' + this.n_id + ')" ondblclick="trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="overlib(\'' + this.config[0] + '\')trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')" class="t' + this.o_root.n_id + 'i" id="i_txt' + this.o_root.n_id + '_' + this.n_id + '"><img src="' + this.get_icon() + '" border="0" align="absbottom" name="i_img' + this.o_root.n_id + '_' + this.n_id + '" class="t' + this.o_root.n_id + 'im">' +img+ this.a_config[0].substr(0,pos) + ' ...</a></td></tr></table>' + (this.b_children ? '<div id="i_div' + this.o_root.n_id + '_' + this.n_id + '" style="display:none"></div>' : '');

        }else{
            return '<table cellpadding="0" cellspacing="0" border="0" class=tree_tab><tr><td nowrap id="i_td'+ this.o_root.n_id + '_' + this.n_id+'" >' + (this.n_depth ? a_offset.join('') + (this.b_children
                     ? '<a href="javascript: trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')"><img src="' + this.get_icon(true) + '" border="0" align="absbottom" name="j_img' + this.o_root.n_id + '_' + this.n_id + '"></a>'
                     : '<img src="' + this.get_icon(true) + '" border="0" align="absbottom">') : '')
                     + '<a href="' + this.a_config[1] + '" target="' + this.o_root.a_tpl['target'] + '" onclick="return trees[' + this.o_root.n_id + '].select(' + this.n_id + ')" ondblclick="trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')" class="t' + this.o_root.n_id + 'i" id="i_txt' + this.o_root.n_id + '_' + this.n_id + '"><img src="' + this.get_icon() + '" border="0" align="absbottom" name="i_img' + this.o_root.n_id + '_' + this.n_id + '" class="t' + this.o_root.n_id + 'im">' +img+ this.a_config[0] + '</a></td></tr></table>' + (this.b_children ? '<div id="i_div' + this.o_root.n_id + '_' + this.n_id + '" style="display:none"></div>' : '');
        }
    }else{
        if( this.a_config[0].length > 20 ){
            pos = 0; pos1 = this.a_config[0].indexOf(' ');
              while( pos1 != -1 && pos1 < 16 ){
                pos = pos1;  pos1 = this.a_config[0].indexOf(' ', pos+1);
              }

              if(pos == 0){ pos = 16; }

              return '<table cellpadding="0" cellspacing="0" border="0" class=tree_tab><tr><td nowrap id="i_td'+ this.o_root.n_id + '_' + this.n_id+'" >' + (this.n_depth ? a_offset.join('') + (this.b_children
                    ? '<a href="javascript: trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')"><img src="' + this.get_icon(true) + '" border="0" align="absbottom" name="j_img' + this.o_root.n_id + '_' + this.n_id + '"></a>'
                    : '<img src="' + this.get_icon(true) + '" border="0" align="absbottom">') : '')
                    + '<a href="' + this.a_config[1] + '" target="' + this.o_root.a_tpl['target'] + '" onclick="return trees[' + this.o_root.n_id + '].select(' + this.n_id + ')" ondblclick="trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="overlib(\'' + this.a_config[0] + '\');trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="nd();trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')" class="t' + this.o_root.n_id + 'i" id="i_txt' + this.o_root.n_id + '_' + this.n_id + '">'+img + this.a_config[0].substr(0,pos) + ' ...</a></td></tr></table>' + (this.b_children ? '<div id="i_div' + this.o_root.n_id + '_' + this.n_id + '" style="display:none"></div>' : '');

        }else{
              return '<table cellpadding="0" cellspacing="0" border="0" class=tree_tab><tr><td nowrap id="i_td'+ this.o_root.n_id + '_' + this.n_id+'" >' + (this.n_depth ? a_offset.join('') + (this.b_children
                    ? '<a href="javascript: trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')"><img src="' + this.get_icon(true) + '" border="0" align="absbottom" name="j_img' + this.o_root.n_id + '_' + this.n_id + '"></a>'
                    : '<img src="' + this.get_icon(true) + '" border="0" align="absbottom">') : '')
                    + '<a href="' + this.a_config[1] + '" target="' + this.o_root.a_tpl['target'] + '" onclick="return trees[' + this.o_root.n_id + '].select(' + this.n_id + ')" ondblclick="trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')" class="t' + this.o_root.n_id + 'i" id="i_txt' + this.o_root.n_id + '_' + this.n_id + '">' + img + this.a_config[0] + '</a></td></tr></table>' + (this.b_children ? '<div id="i_div' + this.o_root.n_id + '_' + this.n_id + '" style="display:none"></div>' : '');
        }
    }


}


function item_init_once ( print ) {

  
  var a_offset = [],
  o_current_item = this.o_parent;

  for (var i = this.n_depth; i > 1; i--) {
      a_offset[i] = '<img src="' + this.o_root.a_tpl[o_current_item.is_last() ? 'icon_e' : 'icon_l'] + '" border="0" align="absbottom">';
      o_current_item = o_current_item.o_parent;
  }

  var a_found = [];
  var img = '';

  if( a_found = this.a_config[0].match(/<img[^>]+> /) ){
      this.a_config[0] = this.a_config[0].replace(/<img[^>]+> /, '')
      img = a_found[0];
  }else{
      img = ' ';
  }

  var html = '';
  
  if(this.n_depth == 0){
     if( this.a_config[0].length > 20 ){
          pos = 0; pos1 = this.a_config[0].indexOf(' ');
          
          while( pos1 != -1 && pos1 < 16 ){
            pos = pos1; pos1 = this.a_config[0].indexOf(' ',pos+1);
          }

          if(pos == 0){ pos = 16; }

          html = '<table cellpadding="0" cellspacing="0" border="0" class=tree_tab><tr><td nowrap id="i_td'+ this.o_root.n_id + '_' + this.n_id+'" >' + (this.n_depth ? a_offset.join('') + (this.b_children
                     ? '<a href="javascript: trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')"><img src="' + this.get_icon(true) + '" border="0" align="absbottom" name="j_img' + this.o_root.n_id + '_' + this.n_id + '"></a>'
                     : '<img src="' + this.get_icon(true) + '" border="0" align="absbottom">') : '')
                     + '<a href="' + this.a_config[1] + '" target="' + this.o_root.a_tpl['target'] + '" onclick="return trees[' + this.o_root.n_id + '].select(' + this.n_id + ')" ondblclick="trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="overlib(\''+ this.a_config[0] +'\');trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="nd(); trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')" class="t' + this.o_root.n_id + 'i" id="i_txt' + this.o_root.n_id + '_' + this.n_id + '"><img src="' + this.get_icon() + '" border="0" align="absbottom" name="i_img' + this.o_root.n_id + '_' + this.n_id + '" class="t' + this.o_root.n_id + 'im">' +img + this.a_config[0].substr(0,pos) + ' ...</a></td></tr></table>' ;

       }else{
           html = '<table cellpadding="0" cellspacing="0" border="0" class=tree_tab><tr><td nowrap id="i_td'+ this.o_root.n_id + '_' + this.n_id+'" >' + (this.n_depth ? a_offset.join('') + (this.b_children
                     ? '<a href="javascript: trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')"><img src="' + this.get_icon(true) + '" border="0" align="absbottom" name="j_img' + this.o_root.n_id + '_' + this.n_id + '"></a>'
                     : '<img src="' + this.get_icon(true) + '" border="0" align="absbottom">') : '')
                     + '<a href="' + this.a_config[1] + '" target="' + this.o_root.a_tpl['target'] + '" onclick="return trees[' + this.o_root.n_id + '].select(' + this.n_id + ')" ondblclick="trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')" class="t' + this.o_root.n_id + 'i" id="i_txt' + this.o_root.n_id + '_' + this.n_id + '"><img src="' + this.get_icon() + '" border="0" align="absbottom" name="i_img' + this.o_root.n_id + '_' + this.n_id + '" class="t' + this.o_root.n_id + 'im">' + img + this.a_config[0] + '</a></td></tr></table>' ;
       }

    }else{
     if( this.a_config[0].length > 20 ){
        pos = 0; pos1 = this.a_config[0].indexOf(' ');
          while( pos1 != -1 && pos1 < 16 ){
            pos = pos1;  pos1 = this.a_config[0].indexOf(' ',pos+1);
          }
          if(pos == 0){ pos = 16; }

            html = '<table cellpadding="0" cellspacing="0" border="0" class=tree_tab><tr><td nowrap id="i_td'+ this.o_root.n_id + '_' + this.n_id+'" >' + (this.n_depth ? a_offset.join('') + (this.b_children
                     ? '<a href="javascript: trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')"><img src="' + this.get_icon(true) + '" border="0" align="absbottom" name="j_img' + this.o_root.n_id + '_' + this.n_id + '"></a>'
                     : '<img src="' + this.get_icon(true) + '" border="0" align="absbottom">') : '')
                     + '<a href="' + this.a_config[1] + '" target="' + this.o_root.a_tpl['target'] + '" onclick="return trees[' + this.o_root.n_id + '].select(' + this.n_id + ')" ondblclick="trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="overlib(\'' + this.a_config[0] + '\');trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="nd();trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')" class="t' + this.o_root.n_id + 'i" id="i_txt' + this.o_root.n_id + '_' + this.n_id + '">' + img + this.a_config[0].substr(0,pos) + ' ...</a></td></tr></table>' ;
       }else{
            html = '<table cellpadding="0" cellspacing="0" border="0" class=tree_tab><tr><td nowrap id="i_td'+ this.o_root.n_id + '_' + this.n_id+'" >' + (this.n_depth ? a_offset.join('') + (this.b_children
                     ? '<a href="javascript: trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')"><img src="' + this.get_icon(true) + '" border="0" align="absbottom" name="j_img' + this.o_root.n_id + '_' + this.n_id + '"></a>'
                     : '<img src="' + this.get_icon(true) + '" border="0" align="absbottom">') : '')
                     + '<a href="' + this.a_config[1] + '" target="' + this.o_root.a_tpl['target'] + '" onclick="return trees[' + this.o_root.n_id + '].select(' + this.n_id + ')" ondblclick="trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')" class="t' + this.o_root.n_id + 'i" id="i_txt' + this.o_root.n_id + '_' + this.n_id + '">' + img + this.a_config[0] + '</a></td></tr></table>' ;
       }

    }

    if( this.b_children  ){
        if( this.b_opened ){
            html += '<div id="i_div' + this.o_root.n_id + '_' + this.n_id + '" style="display:block;">';
            for (var i = 0; i < this.a_children.length; i++) {
                 html += this.a_children[i].init_once( false );
                 //this.a_children[i].open();
            }
            html += '</div>';
         }else{
            html += '<div id="i_div' + this.o_root.n_id + '_' + this.n_id + '" style="display: none;"></div>';
         }
    }

    if( print )
        document.write( html );
    
    return html;
    
}

function item_get_icon (b_junction) {
  return this.o_root.a_tpl['icon_' + ((this.n_depth ? 0 : 32) + (this.b_children ? 16 : 0) + (this.b_children && this.b_opened ? 8 : 0) + (!b_junction && this.o_root.o_selected == this ? 4 : 0) + (b_junction ? 2 : 0) + (b_junction && this.is_last() ? 1 : 0))];
}

function item_find_id(){
    if( this.ID && this.ID > 0 ){
        return this.ID;
    }else{
        var gid_reg_expr = null; 
        //console.log(this.o_root.a_tpl['gid_reg_expr']);
        if ( typeof(this.o_root.a_tpl['gid_reg_expr']) == 'string' && this.o_root.a_tpl['gid_reg_expr'] != '' ){
            gid_reg_expr = new RegExp ( this.o_root.a_tpl['gid_reg_expr'] );
        }else{
            gid_reg_expr = /([0-9]+)/;
        }
        
        var znaleziono =  this.a_config[1].match( gid_reg_expr );
        //console.log('Szukam w : ' + this.a_config[1] + ' wedlug regexpr: ' + this.o_root.a_tpl['gid_reg_expr'] );
        //console.log(znaleziono);
        
        if( znaleziono && znaleziono.length > 0 ){
            if ( znaleziono.length == 1 ){
                this.ID = znaleziono[0];
            }else{
                this.ID = znaleziono[1];
            }
            
            return this.ID;
        }else{
            alert('Nie znaleziono identyfikatora grupy :(');
        }
    }
    
    return -1;
}

function item_get_childrens(){

}

function item_handle_response( xmlRoot, txtRoot, onload ){
    var o_grupy_xml = xmlRoot.getElementsByTagName('grupa');

    if( o_grupy_xml.length == 0 ){
        //jesli pomimo tego ze były grupy
        this.b_children = false;
    }
    
    var o_grupa = new Object();
    var a_grupa_config = new Array();
    var podgrupy = false;
    var s = (this.n_depth ? 4 : 0);
    
    //alert(o_grupy_xml.length);
    for( var i = 0; i < o_grupy_xml.length; i++){
        o_grupa = o_grupy_xml.item(i);

        id        = o_grupa.getAttribute( 'ID' );
        nazwa     = o_grupa.getAttribute( 'NAZWA' );
        nazwa     = nazwa.replace("'", "&apos;").replace('"', '&quot;');
        podgrupy  = o_grupa.getAttribute( 'PODGRUPY' );

        a_grupa_config = [nazwa, sprintf(this.o_root.a_tpl['href'], id, nazwa ), false, false, (podgrupy > 0) ];
        
        this.a_config[s + i] = a_grupa_config;
        
        new tree_item(this, i);
    }
    


    this.open(this.b_close);
    
    if( (arguments.length > 2) && ( arguments[2] == 'expand' ) ){
        this.expand( arguments[3] );
    }
}

function sprintf(){
      if (!arguments || arguments.length < 1 || !RegExp)
      {
        return;
      }
      var str = arguments[0];
      var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
      var a = b = [], numSubstitutions = 0, numMatches = 0;
      while (a = re.exec(str))
      {
        var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
        var pPrecision = a[5], pType = a[6], rightPart = a[7];

        //alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);

        numMatches++;
        if (pType == '%')
        {
          subst = '%';
        }
        else
        {
          numSubstitutions++;
          if (numSubstitutions >= arguments.length)
          {
            alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
          }
          var param = arguments[numSubstitutions];
          var pad = '';
                 if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
            else if (pPad) pad = pPad;
          var justifyRight = true;
                 if (pJustify && pJustify === "-") justifyRight = false;
          var minLength = -1;
                 if (pMinLength) minLength = parseInt(pMinLength);
          var precision = -1;
                 if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
          var subst = param;
                 if (pType == 'b') subst = parseInt(param).toString(2);
            else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
            else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
            else if (pType == 'u') subst = Math.abs(param);
            else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
            else if (pType == 'o') subst = parseInt(param).toString(8);
            else if (pType == 's') subst = param;
            else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
            else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
        }
        str = leftpart + subst + rightPart;
      }
      return str;
}

function item_expand( path ){
    var i = 0;
    
    if( path[0] == 0 ){
        i++;
    }else if( this.find_id() != path[0] ){
        return;
    }
    var id = 0;
    
    var a_items = this.a_children;
    for( ; i < path.length; i++ ){
        for( j = 0; j < a_items.length; j++ ){
            if( (id = a_items[j].find_id()) == path[i] ){
                if( a_items[j].b_children &&  a_items[j].a_children.length == 0 ){
                    var o_self = a_items[j];
                    var new_path = path.splice(i, path.length - i);
                    
                    server_connect( this.o_root.ajax, this.o_root.a_tpl['url'] + id, function( xml, txt ){ o_self.handle_response( xml, txt, 'expand', new_path ) });
                }else if( a_items[j].b_children ){
                    a_items = a_items[j].a_children;
                    a_items[j].open(a_items[j].b_close);
                    
                    break;
                }else{
                    this.o_root.select( a_items[j].n_id );

                    if( a_items[j].a_config[1].substring(0, 11) == 'javascript:' ){
                        eval(a_items[j].a_config[1].substring(11));
                    }

                    return;
                }
            }
        }
    }
}

function tree_collapse( ){

}

var trees = [];

get_element = document.all ?
  function (s_id) { return document.all[s_id] } :
  function (s_id) { return document.getElementById(s_id) };



var tree_obj = null;
function tree_init( obj, url ){
  tree_obj = obj;

  server_connect(null, url, tree_init_response );

}

function tree_init_response( js ){

    eval(js);
    
    new tree(TREE_ITEMS, TREE_TPL, tree_obj.parentNode );

    tree_obj = null;
}

