/**
 * ARCHIVO DE ACCIONES PARA EL ARBOL
 * G.D.Ripoll
 */

arbolDo =
{
	debug : false,
	destacado : function(event,frame,id,nombre,pregenerado,titulo,codigo) //-------------------------------
	{
		//alert("arbolDo.Destacado (12)");
		if(this.debug) alert(event+" , "+frame+" , "+id+" , "+nombre+" , "+pregenerado+" , "+titulo+" , "+codigo);
		ob=this.getOpcionMenu(event); //crossbrowser event
		eval("if(typeof(MENU_"+ob.parentElement.parentElement.level+")!='undefined') MENU_"+ob.parentElement.parentElement.level+".select("+ob.parentElement.id.substr(4)+")"); //prendo la opcion en el menu
		onSkinChange(ob.parentElement.arbol_skin); //llamado al cambio de skin
		this.llamarSubMenu(ob.parentElement);

		if(pregenerado!="s")
		{
			if(this.debug) alert("arboldo:: No es pregenerado!");
			FWK.loadFrameInto("content",frame,"&FWK[id_nodo]="+id+"&FWK[nombre_nodo]="+nombre);
		}
		else
		{
			if(this.debug) alert("arboldo:: ES pregenerado!");
			FWK.loadAppInto("content","mngtapas|principal|principal|principal","&principal[accion]=html_pregen&principal[html]=mngtapas_pregen_"+id+".html&FWK[id_nodo]="+id+"&FWK[nombre_nodo]="+nombre);
		}
		if(typeof cambiarAnchor!="undefined")
			cambiarAnchor("tapa",codigo,nombre);

		this.setTopTitle(unescape(titulo));

		return(this.stopPropagation(event));
	},
	link : function(event,href,features) //--------------------------------------
	{
		//alert("arbolDo.Link");
		ob=this.getOpcionMenu(event); //crossbrowser event
		eval("if(typeof(MENU_"+ob.parentElement.parentElement.level+")!='undefined') MENU_"+ob.parentElement.parentElement.level+".select("+ob.parentElement.id.substr(4)+")"); //prendo la opcion en el menu
		onSkinChange(ob.parentElement.arbol_skin); //llamado al cambio de skin
		this.llamarSubMenu(ob.parentElement);
		window.open(href,null,features);
		return(this.stopPropagation(event));
	},
	html : function(event,nota,id,nombre,titulo)
	{
		//alert("arbolDo.Html");
		ob=this.getOpcionMenu(event); //crossbrowser event
		eval("if(typeof(MENU_"+ob.parentElement.parentElement.level+")!='undefined') MENU_"+ob.parentElement.parentElement.level+".select("+ob.parentElement.id.substr(4)+")"); //prendo la opcion en el menu
		onSkinChange(ob.parentElement.arbol_skin); //llamado al cambio de skin
		this.llamarSubMenu(ob.parentElement);
		FWK.loadAppInto('content','conthtml|principal|principal|principal','&principal[nodo_sesion]=true&principal[id_grupo]='+nota+"&FWK[id_nodo]="+id+"&FWK[nombre_nodo]="+nombre);
		this.setTopTitle(unescape(titulo));
		return(this.stopPropagation(event));
	},
	list : function(event,id,nombre,titulo,codigo)
	{
		//alert("arbolDo.List");
		ob=this.getOpcionMenu(event); //crossbrowser event
		eval("if(typeof(MENU_"+ob.parentElement.parentElement.level+")!='undefined') MENU_"+ob.parentElement.parentElement.level+".select("+ob.parentElement.id.substr(4)+")"); //prendo la opcion en el menu
		onSkinChange(ob.parentElement.arbol_skin); //llamado al cambio de skin
		this.llamarSubMenu(ob.parentElement);
		FWK.loadAppInto('content','listador|principal|principal|principal','&principal[pag]=1&principal[id_nodo]='+id+'&principal[nodo_sesion]=true&FWK[id_nodo]='+id+'&FWK[nombre_nodo]='+nombre);
		this.setTopTitle(unescape(titulo));
		if(typeof cambiarAnchor!="undefined") cambiarAnchor("tapa",codigo,nombre);
		return(this.stopPropagation(event));
	},
	generico : function(event,onclick)
	{
		//alert("arbolDo.Generico");
		ob=this.getOpcionMenu(event); //crossbrowser event
		eval("if(typeof(MENU_"+ob.parentElement.parentElement.level+")!='undefined') MENU_"+ob.parentElement.parentElement.level+".select("+ob.parentElement.id.substr(4)+")"); //prendo la opcion en el menu
		onSkinChange(ob.parentElement.arbol_skin); //llamado al cambio de skin
		this.llamarSubMenu(ob.parentElement);
		eval(unescape(onclick));
		//return(this.stopPropagation(event)); en este no stopeo nada
	},
	llamarSubMenu : function(ob,seleccionado,bAsync)
	{
		//alert(ob);
		if(typeof bAsync=="undefined"){
			bAsync=true;
		}
		var id=ob.id.substr(4);
		var reg=ob.parentElement.region;
		var sub=ob.parentElement.subregion;
		var level=ob.parentElement.level;
		//eval("MENU_"+level+".select("+id+")"); //prendo la opcion en el menu
		//alert("Poniendo en  arbChilds"+level+" el ["+reg+"."+sub+"."+id+"]");
		if(bAsync){
			FWK.loadApiInto('arbChilds'+level,"arbol|arbol|arbol|principal","sub","&idReg="+reg+"&idSub="+sub+"&idItem="+id+"&idSel="+seleccionado);
		}else{
			if(document.getElementById('arbChilds'+level)){
				document.getElementById('arbChilds'+level).innerHTML=FWK.loadApi("arbol|arbol|arbol|principal","sub","&idReg="+reg+"&idSub="+sub+"&idItem="+id+"&idSel="+seleccionado);
			}
		}
	},
	//--[UTILIDADES]-----------------------------------------
	getOpcionMenu : function(event)
	{
		ob=(document.all)?event.srcElement:event.target; //crossbrowser event
		while(ob.tagName!="A") ob=(document.all)?ob.parentElement:ob.parentNode; //bubble hasta el A
		return(ob);
	},
	stopPropagation : function(event)
	{
		if(!document.all) {	event.stopPropagation(); event.preventDefault(); }
		event.cancelBubble=true; event.returnValue=false; //cierre, deshabilito el A ------
		return false;
	},
	setTopTitle : function(titulo)
	{
		top.document.title=titulo;
	},
	
	irA : function(sPath) {
		if (sPath) {
			var aPath = sPath.split("/");
			var ob = document.getElementById("item"+aPath[0]);
			if (ob) {
				ob = ob.getElementsByTagName("A")[0];
				if(aPath.length==1){
					if (ob) {
						ob.click();
					}
				} else {
					eval("if(typeof(MENU_"+ob.parentElement.parentElement.level+")!='undefined') MENU_"+ob.parentElement.parentElement.level+".select("+ob.parentElement.id.substr(4)+")"); //prendo la opcion en el menu
					if (ob) {
						onSkinChange(ob.parentElement.arbol_skin)
						this.llamarSubMenu(ob.parentElement,true,false);				
						this.irA(aPath.slice(1,aPath.length).join("/"));
					}
				}				
			}
		}
	}
}
