var nodes = new Object();
function isset(varname){
  return (typeof(varname)!='undefined');
}
function switchNode(div_name, __parent){
  if(isset(nodes[__parent])){
    nodes[__parent]=true;
    switchObj('branch'+__parent);
  }else{
    nodes[__parent]=true;
    getBranch(div_name, __parent);
  }

}
function getBranch(div_name, __parent){
  someDiv = fetch_obj(div_name);
  temp=someDiv.innerHTML;  
  advAJAX.get({
    url: "php/branch.php",
    parameters : {
      "parent" : __parent
    },  
    onInitialization : function() {
        someDiv.innerHTML = someDiv.innerHTML+'<div style="font-size: 9px;">wczytywanie ...</div>';
    },
    onSuccess : function(obj) {
        someDiv.innerHTML = temp+obj.responseText;
    },
    onError : function(obj) {
        alert("Error: " + obj.status);
    },
    onFinalization : function() {
        /* Ponowne pokazanie warstwy po zakończeniu wszystkich operacji */
    }
  });
}
function switchIMG(obj, path, a, b){
    var ar = obj.src.split('/');
    curr = ar[ar.length-1];
    if(path.charAt(path.length-1) != '/') path += '/';
    obj.src = curr != a ? path + a : path + b;
    //divobj = fetch_obj ( divid );
    //obj.src = divobj.style.display != "block" ? path + a : path + b;
}
function switchObj ( objid ) {
    obj = fetch_obj ( objid );
    obj.style.display = obj.style.display != "block" ? "block" : "none";
}

var ed_node = new Object();
function ed_in_menu(obj){
  ed_node[obj.name]=obj.value;
  //alert(obj.value);
  //nodes[__parent]=true;
}
function ed_out_menu(obj, id){
  if(ed_node[obj.name]!=obj.value)
    if(confirm('Czy zapisać zmiany?'))
      obj.form.submit();

    obj.value=ed_node[obj.name];
    obj.style.display='none';
    o_item=fetch_obj('item'+id);
    o_item.style.display='inline';
  //alert(obj.value);
  //nodes[__parent]=true;
}
function item_edit(id){
  o_item=fetch_obj('item'+id);
  o_item.style.display='none';
  o_inpt=fetch_obj('input'+id);
  o_inpt.style.display='inline';
  o_inpt.select();
  o_inpt.focus();
}

function get_item_editor(_mode, _id, _name, _type)
{
  // sprawdzanie czy edytor jest wyswietlony
  m_div = fetch_obj('item_editor');
  if (m_div.style.display == "block"){
    m_div.style.display = "none";
    return;
  }

  // tryb: dodawanie lub edytowanie
  m_mode = fetch_obj('node_mode');
  if (m_mode == null) return;
  m_mode.value = 'insert';  

  // ustawienie danych do edycji
  switch (_mode){
    case 'insert':
      m_mode.value = _mode;
      m_form = fetch_obj('item_form');
      with (m_form){
        node_name.value = '';
        node_parent.value = _id;
        unCheckAll(node_type);
      }
      break;
    case 'update':
      m_mode.value = _mode;  
      m_form = fetch_obj('item_form');
      with (m_form){
        node_name.value = _name;
        node_parent.value = _id;
        setCheckedValue(node_type, _type);
      }
      break;
  }

  // ustawienie id dla operowanej reguly 
  node_parent = fetch_obj('node_parent');
  node_parent.value = _id;
  
  //alert(node_parent.value);
  
  // wyswietlenie edytora
  button_name = 'node' + _id;
  button_pos = getAnchorPosition(button_name)
  with(m_div.style){
  	top = button_pos.y + 15 + 'px';
  	left = button_pos.x + 'px';
  	display = "block";
  }
}

/*function del_rule(_id)
{
 
  // tryb: dodawanie lub edytowanie
  rule_mode = fetch_obj('rule_mode');
  if(rule_mode == null) return;
  rule_mode.value = 'delete';  

  // ustawienie id reguly
  priv_parent = fetch_obj('priv_parent');
  priv_parent.value = _id;
  
  // przeslanie formularza
  rule_form = fetch_obj('rule_form');
  rule_form.submit();
  
  return true;
}*/

function close_popup_editor(editor_id)
{
  m_div = fetch_obj(editor_id);
  m_div.style.display = "none";
}
