/*
* treeapp.js
* Tree related functions.
*/

var actree = new NlsTree("actree");

// tree costum onClick event - add the corresponding module:
function acTreeClick(evt) {
  /* The following is for compatability: */
  /* Moz populates the target property of the event object, IE populates the srcElement property */
  evt = (evt) ? evt : ((window.event) ? window.event : "");
  var eTarget = evt.target || evt.srcElement;
  //alert ("Captured Event (target="+ eTarget + "id=" + eTarget.id);
  // id is of form "cstl_TTID" where TT is the treename ("t12") and ID is our node id:
  var id = eTarget.id.substr(11,eTarget.id.length);
  //alert (id);
  if (!(actree.hasChild(id))) {
    var node = actree.getNodeById(id);
    n_xtra = node.xtra;
    strFound=n_xtra.indexOf("tag:");
    //if ((node.xtra == "mod") || (node.xtra == "mod.E")) {
    if ((strFound != -1) || (node.xtra == "mod") || (node.xtra == "mod.E")) {
      var module = new Module(node.capt, node.orgId);
      module.content = 'Cargando ...'
      module.defaultExpand = true;
      if (node.xtra == "mod.E") {
        module.canEdit = true;
        module.startEdit();
      }
      MM.addModule (module);
    }
  }
}

//Searching into the javascript tree
function treeSearch () {
  if (document.query_form.s.value.length > 0) {
    var frm;
    //check if supportted:
    if (document.frames) { 
      // IE/OPERA:
      frm = document.frames["comFrame2"].document.all.comForm2;
    } 
    else { 
      // NETSCAPE/MOZILLA/FF:
      var ifrm = NlsGetElementById("comFrame2");
      var frm = (ifrm.contentDocument ? ifrm.contentDocument.forms.comForm2:ifrm.contentWindow.document.forms.comForm2);
    }
    frm.txtTreeSearch.value=document.query_form.s.value;
    //alert (frm.txtTreeSearch.value);
    frm.lang.value='<?php echo $LANG; ?>';
    frm.submit();
  }
  else alert ("<?php PMSG('treesearch_noquery') ?>");
}

//Manage the use of the tree expand
function acTreeExpand(id){
  //alert("Bo q pacha: "+id);
  var expNode = actree.getNodeById(id);
  //alert(expNode);
  if (expNode.xtra=="Load") {
    //alert("in load");
    //expNode.xtra="Loaded";
    var frm;
    //check if supported:
    if (document.frames) { 
      // IE/OPERA:
      //alert("IE");
      frm = document.frames["comFrame"].document.all.comForm;
    } 
    else { 
      // NETSCAPE/MOZILLA/FF:
      //alert("NETSCAPE");
      var ifrm = NlsGetElementById("comFrame");
      var frm = (ifrm.contentDocument ? ifrm.contentDocument.forms.comForm:ifrm.contentWindow.document.forms.comForm);
    }
    frm.txtTreeId.value=id;
    //alert(frm.txtTreeId.value);
    frm.lang.value='<?php echo $LANG; ?>';
    frm.submit();
  }
}

//Manage the use of the tree expand
function acTreeExpandTree(actree,id){
  alert("Bo q pacha: "+id);
  var expNode = actree.getNodeById(id);
  alert(expNode);
  if (expNode.xtra=="Load") {
    //alert("in load");
    //expNode.xtra="Loaded";
    var frm;
    //check if supported:
    if (document.frames) { 
      // IE/OPERA:
      //alert("IE");
      frm = document.frames["comFrame"].document.all.comForm;
    } 
    else { 
      // NETSCAPE/MOZILLA/FF:
      //alert("NETSCAPE");
      var ifrm = NlsGetElementById("comFrame");
      var frm = (ifrm.contentDocument ? ifrm.contentDocument.forms.comForm:ifrm.contentWindow.document.forms.comForm);
    }
    frm.txtTreeId.value=id;
    //alert(frm.txtTreeId.value);
    frm.lang.value='<?php echo $LANG; ?>';
    frm.submit();
  }
  if (!(actree.hasChild(id))) {
    var node = actree.getNodeById(id);
    n_xtra = node.xtra;
    strFound=n_xtra.indexOf("tag:");
    //if ((node.xtra == "mod") || (node.xtra == "mod.E")) {
    if ((strFound != -1) || (node.xtra == "mod") || (node.xtra == "mod.E")) {
      var module = new Module(node.capt, node.orgId);
      module.content = 'Cargando ...'
      module.defaultExpand = true;
      if (node.xtra == "mod.E") {
        module.canEdit = true;
        module.startEdit();
      }
      MM.addModule (module);
    }
  }
}

// Creates the initial content tree:
function initACtree() {
  //document.query_form.s.value = "";
  acTreeInitNodes();
  actree.ico = new StdIco ("img/actree/");
  actree.opt.sort="no";
  actree.opt.icon = true;
  actree.opt.check = false;
  actree.opt.oneExp = true;
  actree.treeOnClick = acTreeClick;
  actree.treeOnExpand = acTreeExpand;
  /*actree.add('1', '0', "Contidos dispoñibles:", "", "img/actree/mydoc.gif", true, false, "Load");
  actree.add('1LL', '1' , "Cargando...", "", "", true, false);

  actree.add('nl', 'n', 'By Locality', "", null, false);
  actree.add('nl.lugo', 'nl', 'Lugo', "", null, false, false, "mod");
  actree.add('nl.ferrol', 'nl', "Ferrol", "", null, false, false, "mod");
  actree.add('nl.acoruna', 'nl', "A Coru&ntilde;a", "", null, false, false, "mod");
  actree.add('nl.orense', 'nl', "Orense", "", null, false, false, "mod");
  actree.add('nl.santiago', 'nl', "Santiago", "", null, false, false, "mod");
  actree.add('nl.vigo', 'nl', 'Vigo', "", null, false, false, "mod");
 
  actree.add('ns.LaVozDeGalicia', 'n', 'La Voz de Galicia', "", "", true);
  actree.add('ns.LaVozDeGalicia.Portada', 'ns.LaVozDeGalicia', "Portada", "", null, false, false, "mod");
  actree.add('ns.LaVozDeGalicia.Galicia', 'ns.LaVozDeGalicia', "Galicia", "", null, false, false, "mod");
  actree.add('ns.LaVozDeGalicia.Espana', 'ns.LaVozDeGalicia', "Espa&ntilde;a", "", null, false, false, "mod");
  
  actree.add('ns.Paxinas', 'n', "Paxinas.com", "","",true);
  actree.add('ns.Paxinas.Galicia', 'ns.Paxinas', "Galicia", "", null, false, false, "mod");
  actree.add('ns.Paxinas.Cultura', 'ns.Paxinas', "Cultura", "", null, false, false, "mod");
  actree.add('ns.Paxinas.Economia', 'ns.Paxinas', "Econom&iacute;a", "", null, false, false, "mod");
  actree.add('ns.Paxinas.Sociedade', 'ns.Paxinas', "Sociedade", "", null, false, false, "mod");
  actree.add('ns.Paxinas.Tecnoloxia', 'ns.Paxinas', "Tecnolox&iacute;a", "", null, false, false, "mod");
  actree.add('ns.Paxinas.Deportes', 'ns.Paxinas', "Deportes", "", null, false, false, "mod");
  actree.add('ns.Paxinas.Internacional', 'ns.Paxinas', "Internacional", "", null, false, false, "mod");
  actree.add('ns.Paxinas.Espana', 'ns.Paxinas', "Espa&ntilde;a", "", null, false, false, "mod");


  actree.add('ns.DiarioDeFerrol', 'n', "Diario de Ferrol", "", null, false, false, "mod");
  actree.add('ns.CNN', 'n', "CNN", "", null, false, false, "mod");

  actree.add('w.lugo', 'w', 'Lugo', "", null, false, false, "mod");
  actree.add('w.ferrol', 'w', "Ferrol", "", null, false, false, "mod");
  actree.add('w.acoruna', 'w', "A Coru&ntilde;a", "", null, false, false, "mod");
  actree.add('w.orense', 'w', "Orense", "", null, false, false, "mod");
  actree.add('w.santiago', 'w', "Santiago", "", null, false, false, "mod");
  actree.add('w.vigo', 'w', 'Vigo', "", null, false, false, "mod");
  
  actree.add('s.google', 's', "Google", "", null, false, false, "mod");
  actree.add('s.yahoo', 's', "Yahoo", "", null, false, false, "mod");

  actree.add('t.bm', 't', "Engadir a marcadores", "", null, false, false, "mod");
  actree.add('t.home', 't', "F&aacute;ganos a s&uacute;a p&aacute;xina de inicio", "", null, false, false, "mod");
  actree.add('t.time', 't', "What's the time ?", "",null, false, false, "mod");
  actree.add('t.take', 't', "Take this page to another computer", "", null, false, false, "mod");

  actree.add('a.about','a', "Que &eacute; Paxinas.com?", "", null, false, false, "mod");
  actree.add('a.who','a', "Sobre n&oacute;s", "", null, false, false, "mod");
  actree.add('a.contact','a', "Contacte connosco", "", null, false, false, "mod");
  actree.add('a.feedback','a', "Feedback", "", null, false, false, "mod");
  actree.add('a.usage','a', "Tips and Tricks", "", null, false, false, "mod");
  actree.add('a.usage.1','a.usage', "Click and Drag", "", null, false, false, "mod");

  actree.add('rss','-', "Add RSS", "", null, false, false, "mod.E");*/
  actree.render("actree");
  
}



