// alert("2320");

var msg    = ""; // lokal
var aufruf = 0;
showdevmsg = 0;  // global

dbxmenueNow   = "";
dbxmenueLeave = "";    
dbxmenuePath  = "";

function showChilds(paraDivid)
// ...............................................................
{
   devmsgx("showChilds::: " + paraDivid);
   // alert("sc:" + paraDivid);
   // suche akf ID /bsp d_1_1
   // zeige alle Kinder von d_1, d_1_1
   // ?? wie andere löschen?
   
   // alert("5");
   
   dbxmenueNow  = paraDivid;
   // dbxmenuePath = dbxmenuePath + "-" + paraDivid;
      
   var arrShowIDs = dbxmenueNow.split("_");
   var anzShowIDs = arrShowIDs.length; 
   var thisDepth  = arrShowIDs[0];
   // alertArray(arrShowIDs); 
   for(var ct=1;ct<anzShowIDs;ct++) 
   { 
   thisDepth  = thisDepth + "_" + arrShowIDs[ct];
   // alert("showChilds->allChilds : " +ct+ " " + thisDepth);
   allChilds(thisDepth,"block","first");   
   }     

   // showInfo();
}




function hideChilds(paraDivid) {
// ....................................
  devmsgx("hide: " + paraDivid);
  
  // alert(paraDivid);
  // next = document.getElementById(paraDivid).id; alert(next);

  if(paraDivid == dbxmenueNow) 
  {
  devmsgx("- delnow: " + dbxmenueNow + "/" + paraDivid);  
  dbxmenueNow = "";
  }

  dbxmenueLeave = paraDivid;

  // hideChilds2(paraDivid);showInfo();return;
  	 
  callFunktion = "hideChilds2(\""+ document.getElementById(paraDivid).id +"\")";
  // alert(callFunktion);
  window.setTimeout(callFunktion, 500);

  
}



function hideChilds2(paraDivid)
// ...............................................................
{
   devmsgx("hide2: " + paraDivid + "/" + dbxmenueNow);
   
   var arrShowIDs = dbxmenueNow.split("_");
   var anzShowIDs = arrShowIDs.length; 

   var arrHideIDs = paraDivid.split("_");
   var anzHideIDs = arrHideIDs.length;

   var ebnHideIDs = anzHideIDs - 1;
    if(ebnHideIDs < 1) ebnHideIDs = 1;
   
   var ebdHideIDs = anzHideIDs - 2;
    if(ebdHideIDs < 1) ebdHideIDs = 1;   

   var ebrHideIDs = 1;          
    if(ebrHideIDs < 1) ebrHideIDs = 1;   
   
   // alert(paraDivid +"|"+ ebnHideIDs +"|"+ ebdHideIDs +"|"+ ebrHideIDs);
   // alertArray(arrHideIDs);
   
   var thisDepth  = arrHideIDs[0];
   for(var ct=1;ct<anzHideIDs;ct++) 
   { 
   thisDepth  = thisDepth + "_" + arrHideIDs[ct];
   if(ct==ebdHideIDs) var thisDaddy = thisDepth;
   if(ct==ebrHideIDs) var thisRoot  = thisDepth;    
   }      

   devmsgx("<b>hide5</b> - akt: " + dbxmenueNow + 
   " / m?: " +  paraDivid + 
   " / d?: " + arrHideIDs[ebdHideIDs] +"="+ arrShowIDs[ebdHideIDs] + 
   " / r?: " + arrHideIDs[ebrHideIDs] +"="+ arrShowIDs[ebrHideIDs] );

   showInfo();
   
   if(arrShowIDs[ebrHideIDs] != arrHideIDs[ebrHideIDs]
   || dbxmenueNow == "")
   {
     devmsgx("- lösche ab root:" + arrShowIDs[ebrHideIDs] + "/" + arrHideIDs[ebrHideIDs]+"/");
     allChilds(thisRoot,"none","all");
	 return;
   }
   	 
   if(arrShowIDs[ebdHideIDs] != arrHideIDs[ebdHideIDs])
   {
     devmsgx("- lösche ab dad: " + arrShowIDs[ebdHideIDs] + "/" + arrHideIDs[ebdHideIDs]);
     allChilds(thisDaddy,"none","all");
     return;  
   }
   
   if(arrShowIDs[ebnHideIDs] != arrHideIDs[ebnHideIDs])
   {
     devmsgx("- lösche kinder: " + arrShowIDs[ebnHideIDs] + "/" + arrHideIDs[ebnHideIDs]);
     allChilds(paraDivid,"none","all");
     return;  
   }   
   
   return;

	
}








function allChilds(paraDivid,dbxdo,tiefe)
// id im Format dbxmenue_1 ... 
// dbxdo -> none oder block
// tiefe -> all(mit kinderkinder) / first
// ...............................................................
{
   // devmsg("allChilds: " + paraDivid + " D: " + dbxdo + " T: " + tiefe);
   // alert("allChilds: " + paraDivid + " D: " + dbxdo + " T: " + tiefe);
   
   devmsgx("allChilds::: " + paraDivid);
      
   arrDivid              = paraDivid.split("_");

   var arrThis               = new Array();
   arrThis["t"]          = tiefe;
   arrThis["divid"]      = paraDivid;
   arrThis["aktid"]      = paraDivid;
   arrThis["ebene"]      = arrDivid.length - 1;
   keyThisEbene          = arrThis["ebene"];
   arrThis["index_this"] = arrDivid[keyThisEbene];
   arrThis["index_next"] = (arrDivid[keyThisEbene]*1) + 1;         
   arrThis["base"]       =  arrDivid[0] + "_";
   
   for(ct=1;ct<=arrThis["ebene"];ct++) {arrThis["base"] = arrThis["base"] + arrDivid[ct] + "_"; }   
   arrThis["zaehler"]     = 0;

   // firstchild
   arrThis["fchildid"]   = arrThis["base"] + arrThis["zaehler"];
   arrThis["fchild"]     = (document.getElementById(arrThis["fchildid"])) ? "yes" : "no";

   if(arrThis["fchild"] == "no") { devmsg(paraDivid + " hat keine Kinder"); return; } //  
   
   arrThis["aktchildid"] = arrThis["fchildid"];
      
   do
   // ....................................
   {
   arrThis["aktchildid"]      = arrThis["base"] + arrThis["zaehler"];     

   //grandchild
   arrThis["gchildid"]   = arrThis["base"] + ((arrThis["zaehler"]*1)) + "_1";
   arrThis["gchild"]     = (document.getElementById(arrThis["gchildid"])) ? "yes" : "no"; 

   // nextChild
   arrThis["nchildid"]  = arrThis["base"] + ((arrThis["zaehler"]*1)+1)
   arrThis["nchild"]    = (document.getElementById(arrThis["nchildid"])) ? "yes" : "no";   

   
   
   // return;
   // alert("allChilds::: child: " + arrThis["aktchildid"] + " : " + dbxdo);
   if(dbxdo=="none")
   { document.getElementById(arrThis["aktchildid"]).style.display = 'none'; }
   else
   { 
   devmsg("allChilds:zeige : " + arrThis["aktchildid"]);   
   document.getElementById(arrThis["aktchildid"]).style.display = 'block'; 
   }
   
        
   if(arrThis["gchild"] == "yes" && tiefe=="all")
   {
     // msg = msg + "<br> - " + thisAufruf + " aufruf allChilds: " + arrThis["childid"];
     thisID = arrThis["aktchildid"];
     starteSchleife = thisID;
	 tiefeP1 = (tiefe*1)+1
	   
	   allChilds(thisID,dbxdo,tiefeP1);
     
	 // alert("zurück aus schleife: " + starteSchleife + " t: " + tiefe);
   }

   arrThis["zaehler"]++;
   if(arrThis["zaehler"] > 12) { alert("break"); break; }

   } while (arrThis["nchild"] == "yes")
   
   // document.getElementById("divInfo").innerHTML = msg;

   return true;
}


function devmsg(msg)
{
  return;
  msg = msg + "<br>" + document.getElementById("divmsg").innerHTML;
  document.getElementById("divmsg").innerHTML = msg;
  return;
  
  if(showdevmsg==1)
  { alert(msg); }
  return;
}

function devmsgx(msg)
{
   devmsg(msg);
}

function showInfo(msg)
{

}