//MenuViewCtrl (c) 2003-2006 Zucchetti Spa
//vers. 2.9
//by Maurizio Sanguinetti, Cristian Sicuteri, Daniele Baldi

// TODO
// Modalitą Flat: l'incrementale richiede una modalitą depth >= 2. Aggiungere sulle voci menu 1 livello link mod. incrementale;
// Modalitą Horizzontal2: sul primo livello del menu sono ammesse solo voci con figli (submenu) 

// Main control
ZtVWeb.MenuViewCtrl=function(form,id,name,x,y,w,h,font,font_size,font_weight,font_color,font_color_smenu,bg_color,overcolor,textovercolor,menu_type,tag_node,max_level,link_secondary,target_default,close_level,css,className,root_value,separator,separator_vert,sx_btn_image,dx_btn_image,sx_btnover_image,dx_btnover_image,arrow_image,bg_color_smenu,over_color_smenu,textover_color_smenu,btn_imageWidth,z_index,btn_image,btnover_image,anchor,emitter_name){
	//Proprietą del control MenuView
	this.form = form;
	this.id = id;
	this.name = name;
	this.font=LRTrim(font); 
	this.bg_color=LRTrim(bg_color);
	this.max_level=max_level;
	this.link_secondary=LRTrim(link_secondary);
	this.target_default=LRTrim(target_default);
	this.close_level=LRTrim(close_level);
	this.css=LRTrim(css);
	this.className=LRTrim(className);
	this.font_color_smenu=LRTrim(font_color_smenu);
	this.textover_color_smenu = Lower(textover_color_smenu)
	this.bg_color_smenu = Lower(bg_color_smenu)
	this.over_color_smenu = Lower(over_color_smenu)
	this.arrow_image = LRTrim(arrow_image);
	this.btn_image = LRTrim(btn_image);
	this.btnover_image = LRTrim(btnover_image);
	this.sx_btn_image = LRTrim(sx_btn_image);
	this.sx_btnover_image = LRTrim(sx_btnover_image);
	this.dx_btn_image = LRTrim(dx_btn_image);
	this.dx_btnover_image = LRTrim(dx_btnover_image);
	this.separator = LRTrim(separator);
	this.separator_vert = LRTrim(separator_vert);
	this.root_value=root_value;
	this.btn_imageWidth=btn_imageWidth;
	this.z_index=0+z_index;
	this.tag_node=tag_node;
	this.menu_type=menu_type;// flat, horizontal, vertical
	// x compatibilitą con versioni precedenti
	if (menu_type=="true" || menu_type=="false") {
		this.menu_type=(eval(menu_type) ? "horizontal": "vertical");
	}
	this.overcolor=Lower(overcolor);
	this.textovercolor=Lower(textovercolor);
	this.fontweight=LRTrim(font_weight);
	this.fontsize=font_size;
	this.font_color=LRTrim(font_color);
	this.emitter_name=emitter_name;
	this.Ctrl = document.getElementById(this.id);  // Riferimento al controllo
	//Setto la posizione del control e lo aggiungo al form
	this.setCtrlPos(this.Ctrl,x,y,w,h,anchor,this.form.width,this.form.height);
	this.addToForm(this.form,this)
	this.isCssBased=(Empty(this.font) || this.fontsize==0 || Empty(this.fontweight) || Empty(this.font_color) || Empty(this.font_color_smenu) || Empty(this.bg_color_smenu));
	
	this.selectedId="";
	this.selectedId2=""; //utilizzata solo nella modalitą horizontal2
	this.querynode=null;
	this.querynodesList=new Array(); //lista dei nodi sui quali eseguire la query
	this.datasource=null;
	this.paramconsumers=new Array();
	this.dataconsumers=new Array();
	
	this.level_old = 0; //Variabile che serve per discriminare quando passo dal livello principale ai sottolivelli
	this.over = false; // Attiva e disattiva l'aperture al mouseover dei sottomenu
		
	this.Value=function(){
		if(this.querynodesList.length!=0){
			this.querynode=this.querynodesList.shift();
			return this.querynode.nodeid;
		}
		else if(typeof(this.Tree.currentnode)!='undefined'){
			return this.Tree.currentnode.nodeid;
		}
		return"";
	}
	
	// Albero contenente tutti i nodi del menł
	this.tree=function(ctrl){
		this.ctrl=ctrl;
		this.allnodes=new Array();
		this.root=new tree_node(this,ctrl.root_value,-1,"");
		this.currentnode=this.root;
		this.getRoot=function(){
			return this.root;
		}
		
		// rendering tree view menu
		this.render=function(){
			var domObj=document.getElementById(this.ctrl.id);
			domObj.style.zIndex=this.ctrl.z_index;
			this.ctrl.form.Ctrl.style.zIndex=this.ctrl.z_index;
			this.root.opened=true;			
			switch (this.ctrl.menu_type) {
				case "vertical":
					domObj.innerHTML=this.root.viewVertical();
					break;
				case "horizontal":
					domObj.innerHTML=this.root.viewHorizontal();
					break;
				case "flat":
					domObj.innerHTML=this.root.viewFlat();
					break;				
				case "horizontal2":
					domObj.innerHTML=this.root.viewHorizontal2();
					break;
				case "slide":
					domObj.innerHTML=this.root.viewSlide();					
			}			
		}
	}
	
 	function tree_node(tree,nodeid,level,descr,childnum,nodeseq,link,target,icon,iconOver,expr,exprNot,parent,nodeFather){
		this.tree=tree;
		tree.allnodes.push(this);
		this.index=tree.allnodes.length-1;	// index node
		this.nodeseq=nodeseq;		//sequenza nodo 
		this.nodeid=nodeid;			// id node
		this.parent=parent;			// node parent
		this.descr=descr;			//caption
		this.childnum=childnum;		//numero figli
		this.link=link;				// link
		this.target=target;			// target
		this.icon=icon;				// icona
		this.iconOver=iconOver;	// icona rollover
		this.expr=expr;				
		this.exprNot=exprNot;			
		this.children=new Array();		// node children
		this.level=level				//livello
		this.executequery= false;
		this.opened=false;
		
		this.nodeFather=nodeFather;	//Nodo padre utilizzato per ricostruire il percorso
		
		this.setExecuteQuery=function(value){
			//Setto se devo eseguire la query a partire dal nodo corrente
			this.executequery=value;
		}
		
		this.setOpened=function(value){
			//Setto se il nodo č stato aperto o meno
			this.opened=value;
		}
		// add new node child
		this.addChild=function(nodeid,level,descr,childnum,nodeseq,link,target,icon,iconOver,expr,exprNot,parent,nodeFather){
			var newnode=new tree_node(this.tree,nodeid,level,descr,childnum,nodeseq,link,target,icon,iconOver,expr,exprNot,parent,nodeFather);
			this.children.push(newnode);
			return newnode;
		}
		
		this.getChildNum=function(){
			return this.children.length;
		}
		
		this.selectNode=function(e){
			if(e.stopPropagation)
				e.stopPropagation();
			else
				e.cancelBubble = true;
			this.tree.currentnode=this;
			if(this.childnum=='0' || ((this.level+1 )>= this.tree.ctrl.max_level && this.tree.ctrl.max_level > 0)){
				this.tree.ctrl.over=false;
				this.tree.ctrl.onMenuClick();
			} else {
					this.tree.ctrl.over=true;
					if(this.tree.ctrl.menu_type=="horizontal2"&&this.level==0){
						this.tree.ctrl.deselect_all(true);
						this.tree.ctrl.highlightCurrentNode2();
					}
					if (this.executequery){
						this.opened=true;
						this.fillNode()
					} else {
						this.opened=!this.opened;						
						this.view();						
					}
			}		
			//ridimensionamento portlet per menu flat
			if (this.tree.ctrl.menu_type == 'flat'){				
				//adatta altezza menu
				if (parseInt(this.tree.ctrl.form.Ctrl.style.height)<window.document.getElementById(this.tree.ctrl.id+'_main_menu').offsetHeight){
					this.tree.ctrl.form.Ctrl.style.height = window.document.getElementById(this.tree.ctrl.id+'_main_menu').offsetHeight
				}else{
					//mantengo l'altezza settata nel portlet				
					if (window.document.getElementById(this.tree.ctrl.id+'_main_menu').offsetHeight<this.tree.ctrl.form.height){
						this.tree.ctrl.form.Ctrl.style.height = this.tree.ctrl.form.height;
					}else{				
						//riduco la dimensione del portlet adattandola al menu
						this.tree.ctrl.form.Ctrl.style.height = window.document.getElementById(this.tree.ctrl.id+'_main_menu').offsetHeight
					}
				}
			}
			
		}
		
		this.checkCondition=function(){
			// Controlla la visibilitą condizionata delle voci di menu
			// return true se devo far vedere la voce di menu
			var visualizer=true;
			if (this.expr.length>0 || this.exprNot.length>0) {							
				try{
					visualizer = eval(this.tree.ctrl.form.formid+"."+this.tree.ctrl.name+"_Validate('"+this.expr+"','"+this.exprNot+"')");										
				}catch(e){}
			}			
			return visualizer;
		}
		
		this.prepareCallBackSelectNode=function(){				
			return this.tree.ctrl.form.formid+"."+this.tree.ctrl.name+".Tree.allnodes["+this.index+"].selectNode(event)";
		}
	
		this.prepareCallBackOverNode=function(){
			return this.tree.ctrl.form.formid+"."+this.tree.ctrl.name+".Tree.allnodes["+this.index+"].overNode()";
		}
		
		this.prepareCallBackSelectOut=function(){
			return this.tree.ctrl.form.formid+"."+this.tree.ctrl.name+".select_out(event)";
		}
		
		//CUSTOM
		this.prepareCallBackOpenClose=function(index_menu){					
			return this.tree.ctrl.form.formid+"."+this.tree.ctrl.name+".Tree.allnodes["+this.index+"].openClose("+index_menu+")";
		}		
		//aggiunto parentNode per nmantenere aperta la voce selezionata nel menu slide
		this.prepareCallBackLinkSlideMenu=function(link,target,parentNode){			
			//	parentNode viene aggiunto ai parametri del link per mantenere apčerto il menu slide.
			return this.tree.ctrl.form.formid+"."+this.tree.ctrl.name+".Tree.allnodes["+this.index+"].linkSlideMenu('"+link+"','"+target+"','"+parentNode+"')";
		}		
		this.prepareRollover=function(id){			
			return this.tree.ctrl.form.formid+"."+this.tree.ctrl.name+".Tree.allnodes["+this.index+"].rollImage('"+id+"','"+iconOver+"')";
		}
		this.prepareRollout=function(id){			
			return this.tree.ctrl.form.formid+"."+this.tree.ctrl.name+".Tree.allnodes["+this.index+"].rollImage('"+id+"','"+icon+"')";
		}		
		this.rollImage=function(id,rollover){			
			if(!Empty(rollover)){eval("document.getElementById('"+id+"').src='../"+rollover+"'");}
			if (this.tree.ctrl.menu_type!="flat")
				eval(this.tree.ctrl.form.formid+"."+this.tree.ctrl.name+".Tree.allnodes["+this.index+"].overNode()");
			if (this.tree.ctrl.menu_type!="flat"){
				//eval(this.tree.ctrl.form.formid+"."+this.tree.ctrl.name+".Tree.allnodes["+this.index+"].overNode()");
				//CUSTOM
				this.tree.currentnode=this;
				this.tree.ctrl.highlightCurrentNode();
				if(this.tree.ctrl.over) {
				  if (this.executequery){
					this.fillNode();
				  }
				}
				//END CUSTOM
			}
			
		}
		//END CUSTOM		

		this.overNode=function(){			
			this.tree.currentnode=this;
			this.tree.ctrl.highlightCurrentNode();
			if(this.tree.ctrl.over) {
				if (this.executequery){
					this.fillNode();
				} else {
					this.view();
				}
			}
		}
		
		this.fillNode=function(){
			this.tree.ctrl.querynodesList.push(this);
			this.executequery=false;
			this.markLoading();
			setTimeout(this.tree.ctrl.form.formid+'.'+this.tree.ctrl.name+'.datasource.Query()',1);
		}
		
		// get html element relative to node
		this.getCtrlElement=function(){
			return document.getElementById(this.tree.ctrl.id+"_"+this.index);
		}
		
		// get control html element for submenu
		this.getCtrlElementSubMenu=function(){
			if (this.tree.ctrl.menu_type=="flat")
				return document.getElementById(this.tree.ctrl.id+"_"+this.index+"_sub");
			else if(this.tree.ctrl.menu_type=="horizontal2")
				if(this.level==0)
					return document.getElementById(this.tree.ctrl.id+"_"+this.level+"_sec");
				else if(this.level==1)
					return document.getElementById(this.tree.ctrl.id+"_"+this.level+"_sub2");
				else
					return document.getElementById(this.tree.ctrl.id+"_"+this.level+"_sub");
			else
				return document.getElementById(this.tree.ctrl.id+"_"+this.level+"_sub");
		}
		
		this.markLoading=function(){
			var Selection;
			var top=0,left=0;
			var ctrl=this.getCtrlElementSubMenu();
			if (this.tree.ctrl.menu_type!="flat") {
				if (this.tree.ctrl.menu_type=="horizontal2" && this.level==0) {
					Selection=ctrl;
					top=0;
				}
				else { 
					Selection=document.getElementById(this.tree.ctrl.selectedId);
					top=Selection.offsetTop;
				}
				left=Selection.offsetLeft;
			}
			ctrl.innerHTML='<div id="__LOADING__" style="padding-top:'+top+';padding-left:'+left+';font-family:sans-serif;font-size:7pt;">Loading...</div>';
			ctrl.style.display='block';
		}
		
		// visualizza un sottomenu
		this.view=function(){
			// TODO Separare per modalitą
			var ctrl=this.getCtrlElementSubMenu();
			var html="";
			// sotto voci menu da disegnare su questo menu (inline)
			if (this.children.length>0 ){
			    if (this.tree.ctrl.menu_type=="flat") {
					var i=ctrl.parentNode.className.lastIndexOf("_");
					if(this.opened){
						if(ctrl.innerHTML.indexOf("__LOADING__")!=-1){
							ctrl.innerHTML=this.tree.ctrl.drawFlatItems(this,999,1);
							ctrl.parentNode.className=ctrl.parentNode.className.substr(0,i)+"_open";
							ctrl.style.display="block";
						}
						else{						
							ctrl.parentNode.className=ctrl.parentNode.className.substr(0,i)+"_open";
							ctrl.style.display="block";
						}
					}
					else{
						ctrl.parentNode.className=ctrl.parentNode.className.substr(0,i)+"_close";
						ctrl.style.display="none";
					}
				} else if(this.tree.ctrl.menu_type=="horizontal2"&&this.level==0){
					html=this.viewHorizontal();
					ctrl.innerHTML=html;
				}
				else{
					if (document.getElementById(this.tree.ctrl.selectedId)!=null){					
						//CUSTOM
						if(!Empty(this.icon))              
						  var Selection = document.getElementById(this.tree.ctrl.selectedId+"_icons")
						else
						  var Selection=document.getElementById(this.tree.ctrl.selectedId);
						if (document.getElementById(this.tree.ctrl.selectedId+"_sx")!=null){
							Selection = document.getElementById(this.tree.ctrl.selectedId+"_sx")
						}
						//CUSTOM
						var top=Selection.offsetTop;
						var left=Selection.offsetLeft;
					}					
					if((this.tree.ctrl.menu_type=="horizontal"||this.tree.ctrl.menu_type=="horizontal2") && left>0)
						html+="<table border=0 cellspacing=0 cellpadding=0><tr><td><div style='width:"+left+";z-index:"+this.tree.ctrl.z_index+"'></div><td>";
					
					if(top>0&&this.level>=0) {//CUSTOM da ">" a ">=" per corretto allineamento dei sottomenu del menu verticale
						//Aggiungo questo div per disegnare i sottomenu nella posizione corretta
						html+="<div style='font-size:0;margin:0px;border:0px;padding:0px;height:"+top+";z-index:"+this.tree.ctrl.z_index+"'></div>";
					}
					html+="<table border=0 cellspacing=0 cellpadding=0 style=''><tr><td valign=top>";
					html+="<table id='submenu_table' border=0 class='submenu_border' cellpadding=3 cellspacing=0>";
					// loop
					for(var i=0;i<this.children.length;i++){
						var node=this.children[i];
						if (node.checkCondition()){
							if (!this.tree.ctrl.isCssBased)
								html+="<tr id='"+this.tree.ctrl.id+"_"+node.index+"' bgcolor='"+this.tree.ctrl.bg_color_smenu+"' onclick='"+node.prepareCallBackSelectNode()+"' style='font-family:"+this.tree.ctrl.font+";font-size:"+this.tree.ctrl.fontsize+";font-weight:"+this.tree.ctrl.fontweight+";color:"+this.tree.ctrl.font_color_smenu+";cursor:pointer'";
							else
								html+="<tr id='"+this.tree.ctrl.id+"_"+node.index+"' onclick='"+node.prepareCallBackSelectNode()+"' class='submenu_font'";
							//controllo che la voce precedente non sia gią un separatore
							if(node.descr.indexOf("-----")==0){
								if (i<this.children.length-1){
									if (!Empty(this.tree.ctrl.css))
										html+="><td class='icons_smenu'></td><td colspan=2  id='"+this.tree.ctrl.id+"_"+node.index+"_descr'><table cellpadding=0 cellspacing=0 class='submenu_sep_vert'><tr><td></td></tr></table></td>";
									else
										html+="><td class='icons_smenu'></td><td colspan=2  id='"+this.tree.ctrl.id+"_"+node.index+"_descr'><table cellpadding=0 cellspacing=0 class='submenu_sep_vert' style='height:1;width:100%;border-bottom:1px solid'><tr><td></td></tr></table></td>";
								}
							}else{
								html+=" onmouseover='"+node.prepareCallBackOverNode()+"'>";
								// icona voce menu
								if (!Empty(node.icon))
									//html+="<td class='icons_smenu' id='"+this.tree.ctrl.id+"_"+node.index+"_icons' ><img src='../"+node.icon+"'></td>";
									html+="<td class='icons_smenu' id='"+this.tree.ctrl.id+"_"+node.index+"_icons' ><a href='"+node.link+"' target='"+node.target+"'><img id='"+this.tree.ctrl.id+"_"+node.index+"_image' src='../"+node.icon+"' style='border:0' onmouseover="+node.prepareRollover(this.tree.ctrl.id+"_"+node.index+"_image")+" onmouseout="+node.prepareRollout(this.tree.ctrl.id+"_"+node.index+"_image")+"></a></td>"
								else
									html+="<td class='icons_smenu' id='"+this.tree.ctrl.id+"_"+node.index+"_icons'></td>";
								// caption
								//CUSTOM 
								var item=node.descr.replace(/\ /g,"&nbsp;");																
								//html+="<td id='"+this.tree.ctrl.id+"_"+node.index+"_descr'>"+item+"</td>"							
								html+="<td id='"+this.tree.ctrl.id+"_"+node.index+"_descr' width='"+document.getElementById(this.tree.ctrl.selectedId+"_icons").offsetWidth+"' class='submenu_description'>"+item+"</td>"
								//END CUSTOM
								//arrow image
								if(parseInt(node.childnum)>0){
									if (!Empty(this.tree.ctrl.arrow_image))
										html+="<td><img id='"+this.tree.ctrl.id+"_"+node.index+"_img' src='"+this.tree.ctrl.arrow_image+"'></img></td>";
									else 
										if (!Empty(this.tree.ctrl.css))
											html+="<td><div id='"+this.tree.ctrl.id+"_"+node.index+"_img' class='menu_img_arrow'></div></td>";
								}else{
									html+="<td></td>";
								}
								html+="</tr>";
								if (i < this.children.length-1){
									if(node.parent!=this.children[i+1].parent){
										if (!this.tree.ctrl.isCssBased && !Empty(this.tree.ctrl.bg_color_smenu)) 
											html+="<tr id='"+this.tree.ctrl.id+"_"+node.index+"_smout' height='1px' onmouseout='"+node.prepareCallBackSelectOut()+"' bgcolor='"+this.tree.ctrl.bg_color_smenu+"'><td class='icons_smenu' colspan=3></td></tr>";
										else
											html+="<tr id='"+this.tree.ctrl.id+"_"+node.index+"_smout' height='1px' onmouseout='"+node.prepareCallBackSelectOut()+"' class='submenu_font'><td class='icons_smenu' colspan=3></td></tr>";
									}
								} else{
									try{
										html+="<tr id='"+this.tree.ctrl.id+"_"+node.index+"_smout' height='1px' onmouseout='"+node.prepareCallBackSelectOut()+"'><td class='submenu_font' colspan=3></td></tr>"
									}catch(e){}
								}
							}
						}
					}
					//costruisco l'id per agganciarci il livello successivo
					var idlevel=this.tree.ctrl.id+"_"+LRTrim(Str(this.level+1))+"_sub";
					html+="</table></td><td valign=top id='"+idlevel+"'></td></tr></table>";
					if((menu_type=="horizontal"||menu_type=="horizontal2")&&(top>0)) html+="</tr></table>";
					ctrl.innerHTML=html;
				}
			}else{
				ctrl.innerHTML="";
			}
		}

		// menu principale verticale
		this.viewVertical=function(){			
		
			var html="<table id='"+this.tree.ctrl.id+"_main_menu' width="+(w)+" border=0 cellspacing=0 cellpadding=0><tr  width="+(w)+"><td valign=top  width="+(w)+">"+"<table width="+(w)+" border=0  class='menu_border' cellpadding=0 cellspacing=0>";

			// loop sui figli della root
			for(var i=0;i<this.children.length;i++){
				var node=this.children[i];
				if (node.checkCondition()){
					//riga di tre pixel per il mouseout
					if (i == 0) html+="<tr><td colspan='4' height=3 onmouseout='"+node.prepareCallBackSelectOut()+"'></td></tr>";
					if (!Empty(this.tree.ctrl.btn_image))
						html+="<tr id='"+this.tree.ctrl.id+"_"+node.index+"_back' height="+(h)+" onclick='"+node.prepareCallBackSelectNode()+";"+node.prepareCallBackLinkSlideMenu(node.link,node.target)+"' style='background:transparent;background-image:url("+this.tree.ctrl.btn_image+")'>";
					else
						html+="<tr id='"+this.tree.ctrl.id+"_"+node.index+"_back' height="+(h)+" onclick="+node.prepareCallBackSelectNode()+";"+node.prepareCallBackLinkSlideMenu(node.link,node.target)+" class='menu_img'>";
					//img sinistra
					if (!Empty(this.tree.ctrl.sx_btn_image))
						html+="<td cellpadding=0 cellspacing=0 width="+this.tree.ctrl.btn_imageWidth+" id='"+this.tree.ctrl.id+"_"+node.index+"_sx' align='right' style='padding-left:0px;padding-right:0px;border:0px;background-image:url("+this.tree.ctrl.sx_btn_image+")'></td>";
					else {
						if (!Empty(this.tree.ctrl.css))
							html+="<td cellpadding=0 cellspacing=0 id='"+this.tree.ctrl.id+"_"+node.index+"_sx' align='right' class='menu_img_sx' onmouseout='"+node.prepareCallBackSelectOut()+"'></td>";
						else
							html+="<span id='"+this.tree.ctrl.id+"_"+node.index+"_sx' width='0px'></span>";
					}
					// icona voce menu
					if (!Empty(this.tree.ctrl.field_Icons)){
						if (!Empty(node.icon))
							//html+="<td style='padding:0px; margin:0px;' class='icons_menu' id='"+this.tree.ctrl.id+"_"+node.index+"_icons' ><img src='../"+node.icon+"'></td>";
							html+="<td style='padding:0px; margin:0px;' class='icons_menu' id='"+this.tree.ctrl.id+"_"+node.index+"_icons' ><a href='"+node.link+"' target='"+node.target+"' onmouseover="+node.prepareRollover(this.tree.ctrl.id+"_"+node.index+"_image")+" onmouseout="+node.prepareRollout(this.tree.ctrl.id+"_"+node.index+"_image")+"><img id='"+this.tree.ctrl.id+"_"+node.index+"_image' src='../"+node.icon+"' style='border:0' ></a></td>"
						else
							html+="<td style='padding:0px; margin:0px;' class='icons_menu' id='"+this.tree.ctrl.id+"_"+node.index+"_icons' onmouseover="+node.prepareRollover(this.tree.ctrl.id+"_"+node.index+"_image")+" onmouseout="+node.prepareRollout(this.tree.ctrl.id+"_"+node.index+"_image")+"></td>";
					}
					// voce menu
					var item=node.descr;					
					if(!Empty(node.link) && node.link.indexOf('function')<0){
						// HREF per uso da tasto destro
						//CUSTOM
						if (!this.tree.ctrl.isCssBased)
							item="<a style='text-decoration:none' href='"+node.link+"' target='"+node.target+"' onclick='return false'><font id='"+this.tree.ctrl.id+"_"+node.index+"_descr_font' style='text-decoration:none' href='"+node.link+"' target='"+node.target+"' onclick='return false;'><font style='font-family:"+this.tree.ctrl.font+";font-size:"+this.tree.ctrl.fontsize+";font-weight:"+this.tree.ctrl.fontweight+";color:"+this.tree.ctrl.font_color+";cursor:hand;background:transparent'>"+node.descr+"</font></a>";
						else							
							item="<a style='text-decoration:none' href='"+node.link+"' target='"+node.target+"' onclick='return false'><font id='"+this.tree.ctrl.id+"_"+node.index+"_descr_font' class='menu_font'>"+node.descr+"</font></a>";
						//END CUSTOM						
					}
					//aggiunto il Link per SubMenu
					if (!this.tree.ctrl.isCssBased && !Empty(this.tree.ctrl.bg_color)){
						html+="<td bgcolor='"+this.tree.ctrl.bg_color+"' id='"+this.tree.ctrl.id+"_"+node.index+"' style='font-family:"+this.tree.ctrl.font+";font-size:"+this.tree.ctrl.fontsize+";font-weight:"+this.tree.ctrl.fontweight+";color:"+this.tree.ctrl.font_color+"' onmouseover='"+node.prepareCallBackOverNode() +"'>";
						html+="<span style='padding-left:6px;padding-right:6px'>"+item+"</span></td>";
						html+="<td bgcolor='"+this.tree.ctrl.bg_color+"' id='"+this.tree.ctrl.id+"_"+node.index+"_arr' onmouseover='"+node.prepareCallBackOverNode()+"'>";
					}else{
						html+="<td id='"+this.tree.ctrl.id+"_"+node.index+"' class='menu_font' onmouseover='"+node.prepareCallBackOverNode()+"'>";
						html+="<span style='padding-left:6px;padding-right:6px'>"+item+"</span></td>";
						html+="<td id='"+this.tree.ctrl.id+"_"+node.index+"_arr' class='menu_font' onmouseover='"+node.prepareCallBackOverNode()+"'>";
					}
					if(parseInt(node.childnum)>0 && !((node.level+1 )>= this.tree.ctrl.max_level && this.tree.ctrl.max_level > 0)){
						if (!Empty(this.tree.ctrl.arrow_image))
							html+="<img src='" +this.tree.ctrl.arrow_image+ "' style='border:none'>";
						else 
							if (!Empty(this.tree.ctrl.css))
								html+="<table cellpadding=0 cellspacing=0><tr><td class='menu_img_arrow'></td></tr></table>";
					}
					html+="</td>";
					//img destra
					if (this.tree.ctrl.dx_btn_image!="")	
						html+="<td cellpadding=0 cellspacing=0 width="+this.tree.ctrl.btn_imageWidth+" id='"+this.tree.ctrl.id+"_"+node.index+"_dx' align='left' style='border:0px;background-image:url("+this.tree.ctrl.dx_btn_image+")'></td>";
					else 
						if (this.tree.ctrl.css!="")
							html+="<td id='"+this.tree.ctrl.id+"_"+node.index+"_dx' align='left' width='1px' class='menu_img_dx' onmouseout='"+node.prepareCallBackSelectOut()+"'></td>";
						else
							html+="<span id='"+this.tree.ctrl.id+"_"+node.index+"_dx' width='0px'></span>";
					html+="</tr>";
					//separatore
					if (i<this.children.length-1){
						if(node.parent==this.children[i+1].parent){
							if (!Empty(this.tree.ctrl.separator_vert))
								html+="<tr><td colspan='4' align='center'><img src='"+this.tree.ctrl.separator_vert+"'></td></tr>";
							else
								if (!Empty(this.tree.ctrl.css))
									html+="<tr><td colspan='4' class='menu_sep_vert'></td></tr>";
						}
					}else
						html+="<tr><td colspan='4' height=3 onmouseout='"+node.prepareCallBackSelectOut()+"'></td></tr>";
				}
			}//end for
			//costruisco l'id per agganciarci il livello successivo
			var idlevel=this.tree.ctrl.id+"_"+LRTrim(Str(this.level+1))+"_sub";
			html+="</table></td><td valign=top id='"+idlevel+"'></td></tr></table>";
			return html;
		}				
		
		// menu verticale slide a due livelli
		//menu principali del tipo xxxxxxxxxx_MenuView0_menu_3
		// se la voce ha sottovoci č presente un div nascosto del tipo 
				//sottomenu del tipo xxxxxxxxxx_MenuView0_menu_3_0
		//che contiene le voci del sottomuenł		
		this.openClose = function(index_portlet,index_menu){						
			if (this.children[index_menu].childnum != "0"){	var old_style = window.document.getElementById(index_portlet.id+"_menu_"+index_menu+"_0").style.display; }
			else{ var old_style = ""; }
			//chiudo tutti i menu
			for (i=0;i<this.children.length;i++){							
				if (this.children[i].childnum != "0"){
					if ((index_portlet.id+"_menu_"+index_menu+"_0")!=window.document.getElementById(index_portlet.id+"_menu_"+i+"_0").id) 					
						window.document.getElementById(index_portlet.id+"_menu_"+i+"_0").style.display="none"; 
				}		
			}
			//apro o chiudo il menu selezionato			
			if (old_style=="none"){				
				if (this.children[index_menu].childnum != "0"){ window.document.getElementById(index_portlet.id+"_menu_"+index_menu+"_0").style.display="block"; }
			}else{				
				if (this.children[index_menu].childnum != "0"){ window.document.getElementById(index_portlet.id+"_menu_"+index_menu+"_0").style.display="none"; }
			}
			//adatta altezza menu
			if (parseInt(this.tree.ctrl.form.Ctrl.style.height)<window.document.getElementById(index_portlet.id+'_main_menu').offsetHeight){
				this.tree.ctrl.form.Ctrl.style.height = window.document.getElementById(index_portlet.id+'_main_menu').offsetHeight
			}else{
				//mantengo l'altezza settata nel portlet				
				if (window.document.getElementById(index_portlet.id+'_main_menu').offsetHeight<this.tree.ctrl.form.height){
					this.tree.ctrl.form.Ctrl.style.height = this.tree.ctrl.form.height;
				}else{				
					//riduco la dimensione del portlet adattandola al menu
					this.tree.ctrl.form.Ctrl.style.height = window.document.getElementById(index_portlet.id+'_main_menu').offsetHeight
				}
			}
		}
		
		this.linkSlideMenu=function(link,target,parentNode){			
			
			if(link!="undefined" && link!="" && link!=null && link!="../jsp/poba_hnotfound.jsp" && this.tree.ctrl.menu_type!="horizontal" && this.tree.ctrl.menu_type!="vertical"){
				// normalize node_link
				var node_link=link;
				var frame=target;
				if (Substr(node_link,1,9) == "function:" ){
					node_link = Strtran(node_link,"function:","");
					node_link = "javascript:ZtVWeb.getPortlet(\"" +this.form.portletname + "\")." +node_link;
				}
				while(node_link.indexOf('|')>-1) node_link=node_link.replace('|',',');
				if (node_link.indexOf('http://') !=0 && node_link.indexOf('https://') !=0 && !Empty(node_link)){
					node_link='../servlet/'+node_link;
				}
				// Tolgo spazi in fondo
				node_link = node_link.replace(/\s+$/g,"");					
				// normalize frame
				if(Empty(frame)){
					frame=(!Empty(this.target_default))?this.target_default:"_self"
				}
				var width = frame.substring(frame.indexOf('|')+1,frame.lastIndexOf('|'));
				var height = frame.substr(frame.lastIndexOf('|')+1);
								
				//aggiunto parentNode per nmantenere aperta la voce selezionata
				if(parentNode != "undefined"){				
					var node_link = node_link + "&p_openIndexMenu="+parentNode
				}
				
				if (frame.indexOf('dialogwindow') == 0){
					// Il TARGET mi arriva nel formato dialogwindow|altezza|larghezza
					if ((width.length > 0) && (height.length > 0))
						window.open(node_link,'','toolbar=no,scrollbars=no,resizable=yes'+','+'width='+width+','+'height='+height);	
					else
						window.open(node_link,'','toolbar=no,scrollbars=no,resizable=yes');
				}else{
					window.open(node_link,frame,'toolbar=no,scrollbars=no,resizable=yes');
				}
			}
		}
					
		this.drawSlide=function(node,i){
		
			var html = "<div id='"+this.tree.ctrl.id+"_menu_"+i+"'><table cellpadding=0 cellspacing=0 border=0 width="+(w)+">";
			if (!Empty(this.tree.ctrl.btn_image))
				html+="<tr id='"+this.tree.ctrl.id+"_"+node.index+"_back' height="+(h)+" style='background:transparent;background-image:url("+this.tree.ctrl.btn_image+")'>";
			else
				html+="<tr id='"+this.tree.ctrl.id+"_"+node.index+"_back' height="+(h)+" class='menu_img'>";
			//img sinistra
			if (!Empty(this.tree.ctrl.sx_btn_image))
				html+="<td cellpadding=0 cellspacing=0 width="+this.tree.ctrl.btn_imageWidth+" id='"+this.tree.ctrl.id+"_"+node.index+"_sx' align='right' style='padding-left:0px;padding-right:0px;border:0px;background-image:url("+this.tree.ctrl.sx_btn_image+")'></td>";
			else {
				if (!Empty(this.tree.ctrl.css))
					html+="<td cellpadding=0 cellspacing=0 id='"+this.tree.ctrl.id+"_"+node.index+"_sx' align='right' class='menu_img_sx'></td>";
				else
					html+="<span id='"+this.tree.ctrl.id+"_"+node.index+"_sx' width='0px'></span>";
			}
			// icona voce menu
			if (!Empty(this.tree.ctrl.field_Icons)){
				if (!Empty(node.icon))
					//html+="<td style='padding:0px; margin:0px;' class='icons_menu' id='"+this.tree.ctrl.id+"_"+node.index+"_icons'><img src='../"+node.icon+"'></td>";
					html+="<td style='padding:0px; margin:0px;' class='icons_menu' id='"+this.tree.ctrl.id+"_"+node.index+"_icons' ><a href='javascript:void(0)' onclick="+this.prepareCallBackOpenClose(this.tree.ctrl.id+","+i)+";"+this.prepareCallBackLinkSlideMenu(node.link,node.target)+"><img id='"+this.tree.ctrl.id+"_"+node.index+"_image' src='../"+node.icon+"' style='border:0' onmouseover="+node.prepareRollover(this.tree.ctrl.id+"_"+node.index+"_image")+" onmouseout="+node.prepareRollout(this.tree.ctrl.id+"_"+node.index+"_image")+"></a></td>"
				else
					html+="<td style='padding:0px; margin:0px;' class='icons_menu' id='"+this.tree.ctrl.id+"_"+node.index+"_icons' ></td>";
			}
			//voce menu
			if (!this.tree.ctrl.isCssBased && !Empty(this.tree.ctrl.bg_color)){
				html+="<td bgcolor='"+this.tree.ctrl.bg_color+"' id='"+this.tree.ctrl.id+"_"+node.index+"' style='font-family:"+this.tree.ctrl.font+";font-size:"+this.tree.ctrl.fontsize+";font-weight:"+this.tree.ctrl.fontweight+";color:"+this.tree.ctrl.font_color+"' onmouseover='"+node.prepareCallBackOverNode() +"'>";
				html+="<div style='padding-left:6px;padding-right:6pxtext-decoration:none' onclick="+this.prepareCallBackOpenClose(this.tree.ctrl.id+","+i)+";"+this.prepareCallBackLinkSlideMenu(node.link,node.target)+">"
				html+="<font id='"+this.tree.ctrl.id+"_"+node.index+"_descr_font' class='menu_font'>"+node.descr+"</font>"
				html+="</div></td>";			
			}else{
				html+="<td id='"+this.tree.ctrl.id+"_"+node.index+"' class='menu_font' onmouseover='"+node.prepareCallBackOverNode()+"'>";
				html+="<div style='padding-left:6px;padding-right:6pxtext-decoration:none' onclick="+this.prepareCallBackOpenClose(this.tree.ctrl.id+","+i)+";"+this.prepareCallBackLinkSlideMenu(node.link,node.target)+">"
				html+="<font id='"+this.tree.ctrl.id+"_"+node.index+"_descr_font' class='menu_font'>"+node.descr+"</font>"
				html+="</div></td>";			
			}
			//img destra
			if (this.tree.ctrl.dx_btn_image!="")	
				html+="<td cellpadding=0 cellspacing=0 width="+this.tree.ctrl.btn_imageWidth+" id='"+this.tree.ctrl.id+"_"+node.index+"_dx' align='left' style='border:0px;background-image:url("+this.tree.ctrl.dx_btn_image+")'></td>";
			else 
				if (this.tree.ctrl.css!="")
					html+="<td id='"+this.tree.ctrl.id+"_"+node.index+"_dx' align='left' width='1px' class='menu_img_dx'></td>";
				else
					html+="<div id='"+this.tree.ctrl.id+"_"+node.index+"_dx' width='0px'></div>";						
			html += "</tr>"						
			html+="</table></div>";
		
			return html;
		}		
		this.viewSlide=function(){
			var html = "<table id='"+this.tree.ctrl.id+"_main_menu'  border=0 cellspacing=0 cellpadding=0 marginheight=0 marginwidth=0 topmargin=0 leftmargin=0 width="+(w)+" class='menu_border' onmouseout='"+this.prepareCallBackSelectOut()+"'><tr><td>"; //box main_menu 
			html += "<div class='menu_img_top'></div>"	
				// loop
				for(var i=0;i<this.children.length;i++){
					var node = this.children[i];
					if  (node.childnum != "0") {
						//voce con figli
						html+=this.drawSlide(node,i);	
						//div che contiene le sottovoci
						
						//controllo se esplodere la voce di menu in base al parametro impostato sul portlet
						var openMenuIndex = ""
						var id_portlet = id.substring(0,id.indexOf("_"))
						try { openMenuIndex = eval(id_portlet+"_p_openIndexMenu.value") }
						catch(e){}
						if (openMenuIndex!="" && openMenuIndex==i) 
							html +=	"<div id='"+this.tree.ctrl.id+"_menu_"+i+"_0' style='display:block'>"
						else
							html +=	"<div id='"+this.tree.ctrl.id+"_menu_"+i+"_0' style='display:none'>"
							
							
							for (j=0;j<node.childnum;j++){								
								html += "<div><table cellpadding=0 cellspacing=0 border=0 width="+(w)+"><tr>"								
								// icona voce sottomenu				
								try{
								if (!Empty(node.children[j].icon))
									//html+="<td class='icons_smenu' id='"+this.tree.ctrl.id+"_"+node.children[j].index+"_icons'><img src='../"+node.children[j].icon+"'></td>";
									//aggiunto parentNode per nmantenere aperta la voce selezionata (parametro "i")
									tml+="<td class='icons_smenu' id='"+this.tree.ctrl.id+"_"+node.children[j].index+"_icons' ><a href='javascript:void(0)' onclick="+this.prepareCallBackLinkSlideMenu(node.children[j].link,node.children[j].target,i)+"><img id='"+this.tree.ctrl.id+"_"+node.children[j].index+"_image' src='../"+node.children[j].icon+"' style='border:0' onmouseover="+node.children[j].prepareRollover(this.tree.ctrl.id+"_"+node.children[j].index+"_image")+" onmouseout="+node.children[j].prepareRollout(this.tree.ctrl.id+"_"+node.children[j].index+"_image")+"></a></td>"
								else
									html+="<td class='icons_smenu' id='"+this.tree.ctrl.id+"_"+node.children[j].index+"_icons'></td>";
								}catch(e){}
								//voce sottomenu
								try{
								if (!this.tree.ctrl.isCssBased && !Empty(this.tree.ctrl.bg_color)){
									html+="<td valign='middle' bgcolor='"+this.tree.ctrl.bg_color+"' id='"+this.tree.ctrl.id+"_"+node.children[j].index+"' style='font-family:"+this.tree.ctrl.font+";font-size:"+this.tree.ctrl.fontsize+";font-weight:"+this.tree.ctrl.fontweight+";color:"+this.tree.ctrl.font_color+"' onmouseover='"+node.children[j].prepareCallBackOverNode() +"'>";
									html+="<div style='padding-left:6px;padding-right:6pxtext-decoration:none' onclick="+this.prepareCallBackLinkSlideMenu(node.children[j].link,node.children[j].target,i)+">"+node.children[j].descr
									html+="</div></td>";
								}else{									
									html+="<td valign='middle' id='"+this.tree.ctrl.id+"_"+node.children[j].index+"' class='submenu_font' onmouseover='"+node.children[j].prepareCallBackOverNode()+"'>";									
									html+="<div style='padding-left:6px;padding-right:6px;text-decoration:none' onclick="+this.prepareCallBackLinkSlideMenu(node.children[j].link,node.children[j].target,i)+">"+node.children[j].descr
									html+="</div></td>";
								}
								}catch(e){}
								html += "</tr></table></div>";
								if (j<node.childnum-1){//separatore submenu
									html += "<div class='submenu_sep_vert'></div>"
								}
								
							}						
						html +=	"</div>"
					}else{					
						//voce senza figli					
						html+=this.drawSlide(node,i);						
					}
					if (i<this.children.length-1){//separatore menu
						html += "<div class='menu_sep_vert'></div>"
					}
				}
			html += "<div class='menu_img_bottom'></div>"			
			html += "<td><tr></table>"; //fine box main_menu 			
			return html;
		}		
		// fine menu verticale slide a due livelli
		
		
		// menu flat
		this.viewFlat=function(){
			var html="<div id='"+this.tree.ctrl.id+"_main_menu' class='menuFlat'>";
			
			// Wrapper
			html+="<div class='menuWrapper'>";
			
			// Draw root items
			var s="";
			s=this.tree.ctrl.drawFlatItems(this,1,1); 			
			if (s.length >0) {
				html+="<div class='menuRootContainer'>";
				html+="<div class='menuContent'>";
				html+=s;
				html += "</div>"; // box menuContent 
				html += "</div>"; // box menuRootContainer 
			}
			
			// Draw submenu			
			html+="<div class='menuWrapperContainer'>";
			// loop
			for(var i=0;i<this.children.length;i++){				
				if  (this.children[i].childnum != "0") {					
					html+="<div class='menuContainer'>";
					//CUSTOM per link sui SubMenu
					if (this.children[i].link!="undefined" && this.children[i].link!="" && this.children[i].link!=null && this.children[i].link!="../jsp/poba_hnotfound.jsp"){
						html+="<a href='"+this.children[i].link+"' target='"+this.children[i].target+"'><h1>"+this.children[i].descr+"</h1>"
					}else{
						html+="<h1>"+this.children[i].descr+"</h1>"
					}
					//END CUSTOM
					html+="<div class='menuContent'>";
					html+=this.tree.ctrl.drawFlatItems(this.children[i],99999,1);
					html += "</div>"; // box menuContent 
					html += "</div>"; // box menuContainer
				}
			}
			html += "</div>"; // box menuWrapperContainer
			html += "</div>"; // box menuWrapper
			html += "</div>"; // box menuFlat 
			
			return html;  
		}
		
				 	
		this.viewHorizontal=function(){
			var html="<table border=0 cellspacing=0 cellpadding=0 marginheight=0 marginwidth=0 topmargin=0 leftmargin=0><tr><td>"+"<table border=0 marginheight=0 marginwidth=0 topmargin=0 leftmargin=0 class='menu_border' cellpadding=0 cellspacing=0><tr>"			
			// loop sui figli della root
			for(var i=0;i<this.children.length;i++){
				var node=this.children[i];
				if (node.checkCondition() && node.descr.indexOf('-----')!=0){  // esclude separatori
					//img sinistra
					if (!Empty(this.tree.ctrl.sx_btn_image))
						html+="<td height="+(h)+" width="+this.tree.ctrl.btn_imageWidth+" id='"+this.tree.ctrl.id+"_"+node.index+"_sx' align='bottom' style='border:0px;background-image:url("+this.tree.ctrl.sx_btn_image+")'></td>"
					else
						html+="<td height="+(h)+" id='"+this.tree.ctrl.id+"_"+node.index+"_sx' align='bottom' class='menu_img_sx'></td>"
					// icona voce menu
					if (!Empty(this.tree.ctrl.field_Icons)){
						if (!Empty(node.icon)){
							//html+="<td height="+(h)+" class='icons_menu' id='"+this.tree.ctrl.id+"_"+node.index+"_icons' ><a href='"+node.link+"' target='"+node.target+"'><font id='"+this.tree.ctrl.id+"_"+node.index+"_icons_back' class='menu_font'><img id='"+this.tree.ctrl.id+"_"+node.index+"_image' src='../"+node.icon+"' style='border:0' onmouseover="+node.prepareRollover(this.tree.ctrl.id+"_"+node.index+"_image")+" onmouseout="+node.prepareRollout(this.tree.ctrl.id+"_"+node.index+"_image")+"></font></a></td>"
							html+="<td height="+(h)+" class='icons_menu' id='"+this.tree.ctrl.id+"_"+node.index+"_icons' onclick='"+node.prepareCallBackSelectNode()+"'><a href='"+node.link+"' target='"+node.target+"' onclick='return false;' style='outline:none;-moz-outline:none;'><font id='"+this.tree.ctrl.id+"_"+node.index+"_icons_back' class='menu_font'><img id='"+this.tree.ctrl.id+"_"+node.index+"_image' src='../"+node.icon+"' style='border:0' onmouseover="+node.prepareRollover(this.tree.ctrl.id+"_"+node.index+"_image")+" onmouseout="+node.prepareRollout(this.tree.ctrl.id+"_"+node.index+"_image")+"></font></a></td>"
							//html+="<td height="+(h)+" class='icons_menu' id='"+this.tree.ctrl.id+"_"+node.index+"_icons' ><img src='../"+node.icon+"'></td>"																																							  
						}else
							html+="<td height="+(h)+" class='icons_menu' id='"+this.tree.ctrl.id+"_"+node.index+"_icons'></td>"
					}
					if (!this.tree.ctrl.isCssBased)
						html+="<td height="+(h)+" id='"+this.tree.ctrl.id+"_"+node.index+"' bgcolor='"+this.tree.ctrl.bg_color+"' onclick='"+node.prepareCallBackSelectNode()+"' style='font-family:"+this.tree.ctrl.font+";font-size:"+this.tree.ctrl.fontsize+";font-weight:"+this.tree.ctrl.fontweight+";color:"+this.tree.ctrl.font_color+";cursor:hand'>"
					else
						html+="<td height="+(h)+" id='"+this.tree.ctrl.id+"_"+node.index+"' onclick='"+node.prepareCallBackSelectNode()+"' class='menu_font'>" 
					if (!Empty(this.tree.ctrl.btn_image))
						html+="<table id='"+this.tree.ctrl.id+"_"+node.index+"_back' cellspacing=0 cellpadding=0 margin=0 height="+(h)+" style='height:"+(h)+";background:transparent;background-image:url("+this.tree.ctrl.btn_image+");padding-left:3px;padding-right:3px'>"
					else
						html+="<table id='"+this.tree.ctrl.id+"_"+node.index+"_back' cellspacing=0 cellpadding=0 margin=0 height="+(h)+" class='menu_img'><tr>"
					// voce menu
					var item=node.descr;
					//variabile che descimina se gli eventi del mouse sono gestiti da handler presenti sulla cella o sull'anchor
					//Questa distinzione č stata fatta per evitare sfarfallio su IE
					var ctrlmouse="onmouseover='"+node.prepareCallBackOverNode()+"' onmouseout='"+node.prepareCallBackSelectOut()+"'";
					if(!Empty(node.link) && node.link.indexOf('function')<0){
						// HREF per uso da tasto destro
						var ctrlmouse="";
						//CUSTOM
						if (!this.tree.ctrl.isCssBased)
							item="<a onmouseover='"+node.prepareCallBackOverNode()+"' onmouseout='"+node.prepareCallBackSelectOut()+"' style='text-decoration:none' href='"+node.link+"' target='"+node.target+"' onclick='return false;'><font id='"+this.tree.ctrl.id+"_"+node.index+"_descr_font' style='font-family:"+this.tree.ctrl.font+";font-size:"+this.tree.ctrl.fontsize+";font-weight:"+this.tree.ctrl.fontweight+";color:"+this.tree.ctrl.font_color+";cursor:hand;background:transparent'>"+node.descr+"</font></a>";
						else
							item="<a onmouseover='"+node.prepareCallBackOverNode()+"' onmouseout='"+node.prepareCallBackSelectOut()+"' style='text-decoration:none' href='"+node.link+"' target='"+node.target+"' onclick='return false;'><font id='"+this.tree.ctrl.id+"_"+node.index+"_descr_font' class='menu_font'>"+node.descr+"</font></a>";
						//END CUSTOM
					}
					//aggiunto link per SubMenu
					if (!this.tree.ctrl.isCssBased)
						html+="<td "+ctrlmouse+" id='"+this.tree.ctrl.id+"_"+node.index+"_descr' valign=middle style='font-family:"+this.tree.ctrl.font+";font-size:"+this.tree.ctrl.fontsize+";font-weight:"+this.tree.ctrl.fontweight+";color:"+this.tree.ctrl.font_color+";cursor:hand;background:transparent' onclick="+this.prepareCallBackLinkSlideMenu(node.link,node.target)+">"+item+"</td></tr></table>"
					else
						html+="<td "+ctrlmouse+" id='"+this.tree.ctrl.id+"_"+node.index+"_descr' valign=middle class='menu_font' style='background:transparent' onclick="+this.prepareCallBackLinkSlideMenu(node.link,node.target)+">"+item+"</td></tr></table>"
					html+="</td>"
						
					//img destra
					if (!Empty(this.tree.ctrl.dx_btn_image))
						html+="<td height="+(h)+" width="+this.tree.ctrl.btn_imageWidth+" id='"+this.tree.ctrl.id+"_"+node.index+"_dx' align='bottom' style='border:0px;background-image:url("+this.tree.ctrl.dx_btn_image+")'></td>"
					else
						html+="<td height="+(h)+" id='"+this.tree.ctrl.id+"_"+node.index+"_dx' align='bottom' class='menu_img_dx'></td>"
					
					// Separatore (controllo ultima posizione per separatore)
					if(i<this.children.length-1){
						if(node.parent==this.children[i+1].parent){
							if (this.tree.ctrl.separator!="") 
								html+="<td height="+(h)+"><img src='"+this.tree.ctrl.separator+"'></img></td>";
							else if (this.tree.ctrl.css!="")
								html+="<td height="+(h)+" class='menu_sep'></td>";
						}
					}
				}
			}
			//costruisco l'id per agganciarci il livello successivo
			
			var idlevel=this.tree.ctrl.id+"_"+LRTrim(Str(this.level+1))+"_sub";
			html+="</tr></table></td></tr><tr><td id='"+idlevel+"'></td></tr></table>";
			
			return html;
		}
		
		this.viewHorizontal2=function(){		
			var idlevel=this.tree.ctrl.id+"_"+LRTrim(Str(this.level+1))+"_prin";
			var html="<div id='"+idlevel+"' class=menu_prin><table width="+(w)+" border=0 cellpadding=0 cellspacing=0 marginheight=0 marginwidth=0 topmargin=0 leftmargin=0><tr>";
			// loop sui figli della root		
			for(var i=0;i<this.children.length;i++){
				
					var node=this.children[i];						
					if (node.checkCondition() && node.descr.indexOf('-----')!=0 && (0+node.childnum)>0){  // esclude separatori e voci singole
					//img sinistra
					if (!Empty(this.tree.ctrl.sx_btn_image))
						html+="<td height="+(h)+" width="+this.tree.ctrl.btn_imageWidth+" id='"+this.tree.ctrl.id+"_"+node.index+"_sx'  style='border:0px;background-image:url("+this.tree.ctrl.sx_btn_image+")'></td>";
					else
						html+="<td height="+(h)+" id='"+this.tree.ctrl.id+"_"+node.index+"_sx' class='menuPrin_img_sx'></td>";
					// voce menu
					var item=node.descr;					
					if(!Empty(node.link) && node.link.indexOf('function')<0){						
						// HREF per uso da tasto destro
						item="<a style='text-decoration:none' class='menuPrin_font_link' href='"+node.link+"' target='"+node.target+"' onclick='return false;'>"+node.descr+"</a>";
					}					
					if (!this.tree.ctrl.isCssBased)
						html+="<td onclick='"+node.prepareCallBackSelectNode()+"' onmousedown="+this.prepareCallBackLinkSlideMenu(node.link,node.target)+" height="+(h)+" id='"+this.tree.ctrl.id+"_"+node.index+"_descr' valign=middle style='font-family:"+this.tree.ctrl.font+";font-size:"+this.tree.ctrl.fontsize+";font-weight:"+this.tree.ctrl.fontweight+";color:"+this.tree.ctrl.font_color+";cursor:hand;'>"+item+"</td>";
					else
						html+="<td onclick='"+node.prepareCallBackSelectNode()+"' onmousedown="+this.prepareCallBackLinkSlideMenu(node.link,node.target)+" height="+(h)+" id='"+this.tree.ctrl.id+"_"+node.index+"_descr' valign=middle class='menuPrin_font'>"+item+"</td>";
					//img destra
					if (!Empty(this.tree.ctrl.dx_btn_image))
						html+="<td height="+(h)+" width="+this.tree.ctrl.btn_imageWidth+" id='"+this.tree.ctrl.id+"_"+node.index+"_dx' style='border:0px;background-image:url("+this.tree.ctrl.dx_btn_image+")'></td>";
					else
						html+="<td height="+(h)+" id='"+this.tree.ctrl.id+"_"+node.index+"_dx' class='menuPrin_img_dx'></td>";
				}
				// Separatore (controllo ultima posizione per separatore)
				if(i<this.children.length-1){
					if(node.parent==this.children[i+1].parent){
						if (this.tree.ctrl.separator!="") 
							html+="<td height="+(h)+"><img src='"+this.tree.ctrl.separator+"'></img></td>";
						else if (this.tree.ctrl.css!="")
							html+="<td height="+(h)+" class='menuPrin_sep'></td>";
					}
				}
			}
			html+="</td></tr></table></div>";
	
			//costruisco l'id per agganciarci il livello successivo
			idlevel=this.tree.ctrl.id+"_"+LRTrim(Str(this.level+1))+"_sec";
			html+="<div id='"+idlevel+"' class='menu_sec'>";
			html+="</div>"
			idlevel=this.tree.ctrl.id+"_"+LRTrim(Str(this.children[0].level+1))+"_sub2";
			html+="<div style='padding:0px; margin:0px; border:0px;' id='"+idlevel+"'>";
			html+="</div>" 
			return html;			
		}				
	}	
	//.....................................................................................................................................Qui finisce la classe nodo........................................................................................................................................................
			
	
	//click sul portlet che contiene il menu
	/*this.tree.ctrl.form.Ctrl.onmousedown=function(event){	
		if (browser.isIE) el = "window.event.srcElement";
		else el = "event.target";		
		if(eval(el+".id.indexOf('"+name+"')")==-1){
			// disattivo l'aperture al mouseover dei sottomenu	
			tree.ctrl.over=false;		
			eval(tree.ctrl.form.formid+"."+name+".Tree.root.deselect_all('true')")
		}				
	}*/
	
	//CUSTOM
	//resize altezza portlet per menu verticale e slide
	function resize_portlet_height(){
		if ((menu_type=="vertical")||(menu_type=="slide")||(menu_type=="flat")){ 
			id_portlet= id.substring(0,id.indexOf("_"));
			id_portlet_menu = id+"_main_menu";
			height_portlet = parseInt(window.document.getElementById(id_portlet).style.height);
			try{
				if (height_portlet<window.document.getElementById(id_portlet_menu).offsetHeight){
					window.document.getElementById(id_portlet).style.height = window.document.getElementById(id_portlet_menu).offsetHeight;
				}	
			}catch(e){}			
		}
	}
	addEvent(window,'load', resize_portlet_height)
	//END CUSTOM
	
	//funzione che calcola il percorso
	this.getPath=function(node){
		var current=node;
		var pathNode=new Array();
		while(typeof(current.nodeFather)!="undefined"){
			pathNode.push(current);
			current=current.nodeFather;
		}
		pathNode.reverse();
		return pathNode;
	}
	

	//chiude il menu all'uscita dai sottomenu
	//this.select_out=function(index,event){
	this.select_out=function(event){		
	    //el = (window.event.target) ? event.target : window.event.srcElement;	
		//commentate le seguenti righe per link su sottovoci con mozilla
		//if (navigator.userAgent.indexOf("MSIE") > 0) el =event.srcElement;
		//else el = event.target;
		
		//deseleziono se l'elemento non ha id ?????? o se esco dal menu ??????????		
		//if(Empty(el.id)){
			this.deselect_all(false);
		//}
	}
	
	//click sul portlet che contiene il menu
	this.onmousedown=function(event){
		this.deselect_all(false);
	}
	
	
	//apre il menu flat alla voce selezionata
	this.openTree=function(node){
		var openMenuIndex = ""
		var id_portlet = id.substring(0,id.indexOf("_"))
		try { openMenuIndex = eval(id_portlet+"_p_openIndexMenu.value") }
		catch(e){}
		if (openMenuIndex!="" && openMenuIndex==node.nodeid){
			node.setOpened(true);
			var app_id= 'block';						
		}else{				
			node.setOpened(false);
			var app_id= 'none';
			if (node.childnum>0){
				for (var j=0;j<node.childnum;j++){			
					app_id=this.openTree(node.children[j])									
				}				
			}
		}				
		return app_id;		
	}

    //Item Menu Flat
	this.drawFlatItems=function(node,max_level,level) {
		var shtml="";
		// loop su figli
		for(var i=0;i<node.children.length;i++){	
			if (node.children[i].childnum == "0") {
				if (node.children[i].checkCondition()){
					// href sull'anchor non viene utilizzato serve solo per tasto destro e per a:hover
					shtml+= "<li class='itemMenu' onclick='"+node.children[i].prepareCallBackSelectNode()+"'>"
					// icona voce menu
					if (!Empty(node.children[i].icon)){
						shtml+="<a href='"+node.children[i].link+"' target='"+node.children[i].target+"'><font id='"+node.children[i].index+"_icons_back'><img id='"+id+"_"+node.children[i].index+"_image' src='../"+node.children[i].icon+"' style='border:0' onmouseover="+node.children[i].prepareRollover(id+'_'+node.children[i].index+'_image')+" onmouseout="+node.children[i].prepareRollout(id+'_'+node.children[i].index+'_image')+"></font></a>"
					}
					shtml+="<a href='"+node.children[i].link+"' target='"+node.children[i].target+"' onclick='return false'>"+node.children[i].descr+"</a></li>";
				}
			} else if (max_level>1){
				//controllo se esplodere la voce di menu in base al parametro impostato sul portlet
				var styleDisplay = this.openTree(node.children[i]);
				if(styleDisplay=='block'){
					var classItem='subMenu_open';
					var valOpened=true;
				}else{
					var classItem='subMenu_close';
					var valOpened=false;
				}
				shtml+= "<li class='"+classItem+"' onclick='"+node.children[i].prepareCallBackSelectNode()+"'><a href='javascript:void(0)' onclick='return false'>"+node.children[i].descr+"</a>";
				shtml+= "<div style='display:"+styleDisplay+"' id='"+this.id+"_"+node.children[i].index+"_sub'>"+this.drawFlatItems(node.children[i],max_level-1,level+1)+"</div>";
				shtml+= "</li>";				
			}
		}
		return (shtml.length>0 ? ("<ul>"+shtml+"</ul>") : "");
	}

	 this.highlightCurrentNode=function() {	 
		//deseleziona il vecchio
		if (this.selectedId!=''){
			var oldSelId=this.selectedId;
			var deCtrl=document.getElementById(oldSelId);
			//Controllo se sto navigando su livello 0 o se sto lasciando il livello 0
			if(this.level_old==0||(this.level_old==1&&this.menu_type=="horizontal2")){
				//menu principale
				try{
					if (!Empty(this.btn_image))
						document.getElementById(deCtrl.id+"_back").style.background="url("+this.btn_image+")";
					else
						document.getElementById(deCtrl.id+"_back").className="menu_img";
				}catch(e){}
				try{
					if (!Empty(this.sx_btn_image))
						document.getElementById(deCtrl.id+"_sx").style.background="url("+this.sx_btn_image+")";
					else 
						document.getElementById(deCtrl.id+"_sx").className="menu_img_sx";
				}catch(e){}
				try{
					if (!Empty(this.dx_btn_image))
						document.getElementById(deCtrl.id+"_dx").style.background="url("+this.dx_btn_image+")";
					else
						document.getElementById(deCtrl.id+"_dx").className="menu_img_dx";
				}catch(e){}
				try{
					document.getElementById(deCtrl.id+"_icons").className="icons_menu";
				}catch(e){}				
				try{					
					document.getElementById(deCtrl.id+"_icons_back").className="menu_font";
				}catch(e){}
				//ripristino text
				try{
				if (!Empty(this.font_color)&&!Empty(this.bg_color)){
					deCtrl.style.color=this.font_color;
					document.getElementById(deCtrl.id+"_descr").style.color=this.font_color;
					deCtrl.style.backgroundColor='';
				}else{
					deCtrl.className="menu_font";					
					if (this.menu_type=="horizontal"||this.menu_type=="horizontal2"){
						document.getElementById(deCtrl.id+"_descr").className="menu_font";						
						document.getElementById(deCtrl.id+"_descr_font").className="menu_font";						
					}
				}
				}catch(e){}
				//per menu slide 
				if (this.menu_type=="slide") {
					try{document.getElementById(deCtrl.id+"_descr_font").className="menu_font";}catch(e){}
				}
				//per menu verticale
				try{
					if (this.menu_type=="vertical") {
						if (!Empty(document.getElementById(deCtrl.id+"_arr"))){
							document.getElementById(this.selectedId+"_arr").className="menu_font";
							document.getElementById(deCtrl.id+"_descr_font").className="menu_font";
						}
						else{
							document.getElementById(deCtrl.id+"_arr").style.backgroundColor='';
							document.getElementById(deCtrl.id+"_descr_font").style.backgroundColor="";
						}
					}
				}catch(e){}				
			}
			else{
				// submenu
				try{
					if (!Empty(this.font_color_smenu)) {
						deCtrl.style.color=this.tree.ctrl.font_color_smenu;
						deCtrl.style.backgroundColor='';
					}else{
						//per menu slide						
						deCtrl.className="submenu_font";
					}
					try{document.getElementById(deCtrl.id+"_descr_font").className="menu_font";}catch(e){}
					try{document.getElementById(deCtrl.id+"_icons").className="icons_smenu";}catch(e){}				
				}catch(e){}
			}
			this.selectedId='';
		}
		// seleziona il nuovo
		this.level_old=this.Tree.currentnode.level;
		this.selectedId=this.id+"_"+this.Tree.currentnode.index;
		var Selection=document.getElementById(this.selectedId);
		var SelectionBack=document.getElementById(this.selectedId+"_back");
		var SelectionSx=document.getElementById(this.selectedId+"_sx");
		var SelectionDx=document.getElementById(this.selectedId+"_dx");
		var SelectionArr=document.getElementById(this.selectedId+"_arr");
		var SelectionDescr=document.getElementById(this.selectedId+"_descr");
		var SelectionDescrFont=document.getElementById(this.selectedId+"_descr_font");		
		var SelectionSmOut=document.getElementById(this.selectedId+"_smout");
		var SelectionIcons=document.getElementById(this.selectedId+"_icons");
		var SelectionIconsBack=document.getElementById(this.selectedId+"_icons_back");
		if(this.Tree.currentnode.level==0 || (this.menu_type=="horizontal2" && this.Tree.currentnode.level==1)){
			//menu principale
			if (!Empty(this.overcolor) && !Empty(this.textovercolor)){
				Selection.style.backgroundColor=this.overcolor;
				Selection.style.color=this.textovercolor;
				SelectionDescr.style.color=this.textovercolor;
				SelectionDescrFont.style.color=this.textovercolor;
			}else{
				Selection.className="menu_font_over";
				if (this.menu_type=="horizontal"||this.menu_type=="horizontal2"){
					SelectionDescr.className="menu_font_over";
					try{SelectionDescrFont.className="menu_font_over";}catch(e){}
				}
			}
			//per menu verticale
			if (this.menu_type=="vertical") {
				if (!Empty(this.overcolor) && !Empty(this.textovercolor)){
					SelectionArr.style.backgroundColor=this.overcolor
					SelectionArr.style.color=this.textover_color
					try{
						SelectionDescrFont.style.backgroundColor=this.overcolor;
						SelectionDescrFont.style.color=this.textover_color;
					}catch(e){}
				} else{
					SelectionArr.className="menu_font_over"
					try{SelectionDescrFont.className="menu_font_over";}catch(e){}
				}					
			}
			//per menu slide
			if (this.menu_type=="slide") {
				try{
					SelectionDescrFont.className="menu_font_over";
				}catch(e){}
			}			
			if (!Empty(this.btnover_image))
				SelectionBack.style.background="url("+this.btnover_image+")";
			else
				SelectionBack.className="menu_img_over"
			if (this.sx_btnover_image!="")
				SelectionSx.style.background="url("+this.sx_btnover_image+")";
			else
				SelectionSx.className="menu_img_sx_over";
			if (this.dx_btnover_image!="")
				SelectionDx.style.background="url("+this.dx_btnover_image+")";
			else
					SelectionDx.className="menu_img_dx_over";
			if (SelectionIcons != null)
				SelectionIcons.className="icons_menu_over";
			if (SelectionIconsBack != null)
				SelectionIconsBack.className="menu_font_over";
		}
		else{
			// submenu			
			if (!Empty(this.over_color_smenu) && !Empty(this.textover_color_smenu)){
				Selection.style.backgroundColor=this.over_color_smenu;
				Selection.style.color=this.textover_color_smenu;
			}else{				
				Selection.className="submenu_font_over";
				//per menu slide
				try{document.getElementById(Selection.id+"_descr_font").className="menu_font_over";}catch(e){}				
				try{document.getElementById(Selection.id+"_icons").className="icons_smenu_over";}catch(e){}				
				try{document.getElementById(Selection.id+"_icons_back").className="menu_font_over";}catch(e){}				
			}			
		}
	}
	
	this.highlightCurrentNode2=function(){
		//deseleziona il vecchio
		if (this.selectedId2!=''){
			var oldSelId=this.selectedId2;
			try{
				if (!Empty(this.sx_btn_image))
					document.getElementById(oldSelId+"_sx").style.background="url("+this.sx_btn_image+")";
				else 
					document.getElementById(oldSelId+"_sx").className="menuPrin_img_sx";
			}catch(e){}
			try{
				if (!Empty(this.dx_btn_image))
					document.getElementById(oldSelId+"_dx").style.background="url("+this.dx_btn_image+")";
				else
					document.getElementById(oldSelId+"_dx").className="menuPrin_img_dx";
			}catch(e){}
			//ripristino text
			try{
				if (!Empty(this.font_color)&&!Empty(this.bg_color)){
					document.getElementById(oldSelId+"_descr").style.color=this.font_color;
					document.getElementById(oldSelId+"_descr").style.backgroundColor='';
				}else{
						document.getElementById(oldSelId+"_descr").className="menuPrin_font";
				}
			}catch(e){}
		}
		//seleziona il nuovo
		this.selectedId2=this.id+"_"+this.Tree.currentnode.index;
		var SelectionSx=document.getElementById(this.selectedId2+"_sx");
		var SelectionDx=document.getElementById(this.selectedId2+"_dx");
		var SelectionDescr=document.getElementById(this.selectedId2+"_descr");
		if (!Empty(this.overcolor) && !Empty(this.textovercolor)){
			SelectionDescr.style.color=this.textovercolor;
		}else{
				SelectionDescr.className="menuPrin_font_over";
		}
		if (this.sx_btnover_image!="")
			SelectionSx.style.background="url("+this.sx_btnover_image+")";
		else
			SelectionSx.className="menuPrin_img_sx_over";
		if (this.dx_btnover_image!="")
			SelectionDx.style.background="url("+this.dx_btnover_image+")";
		else
			SelectionDx.className="menuPrin_img_dx_over";
	}

	this.onMenuClick=function(){
		if(Empty(this.Tree.currentnode.link) && !Empty(this.link_secondary)){
			//Apertura menu secondario
			var submenu_name=this.Tree.currentnode.descr;
			var submenu_id=this.Tree.currentnode.nodeid;
			window.open(LRTrim(this.link_secondary)+"&start_uid="+submenu_id+"&start="+submenu_name,this.target_default);
		}
		else{
			// normalize node_link
			var node_link=this.Tree.currentnode.link;
			var frame=this.Tree.currentnode.target;
			if (Substr(node_link,1,9) == "function:" ){
				node_link = Strtran(node_link,"function:","");
				node_link = "javascript:ZtVWeb.getPortlet(\"" +this.form.portletname + "\")." +node_link;
			}
			while(node_link.indexOf('|')>-1) node_link=node_link.replace('|',',');
			if (node_link.indexOf('http://') !=0 && node_link.indexOf('https://') !=0 && !Empty(node_link)){
				node_link='../servlet/'+node_link;
			}
			// Tolgo spazi in fondo
			node_link = node_link.replace(/\s+$/g,"");
				
			// normalize frame
			if(Empty(frame)){
				frame=(!Empty(this.target_default))?this.target_default:"_self"
			}
			var width = frame.substring(frame.indexOf('|')+1,frame.lastIndexOf('|'));
			var height = frame.substr(frame.lastIndexOf('|')+1);						
			
			if (menu_type=='flat')
				node_link = node_link + "&p_openIndexMenu=" + this.Tree.currentnode.parent			
			
			if (frame.indexOf('dialogwindow') == 0){
				// Il TARGET mi arriva nel formato dialogwindow|altezza|larghezza
				if ((width.length > 0) && (height.length > 0))
					window.open(node_link,'','toolbar=no,scrollbars=no,resizable=yes'+','+'width='+width+','+'height='+height);	
				else
					window.open(node_link,'','toolbar=no,scrollbars=no,resizable=yes');
			}else{
				window.open(node_link,frame,'toolbar=no,scrollbars=no,resizable=yes');
			}
		}
		//refresh del menu
		this.deselect_all(false);
		//Calcolo il percorso
		if(!Empty(this.emitter_name)&&this.Tree.currentnode.target!="_blank"){
			var path=this.getPath(this.Tree.currentnode);
			var parmsObj={"path":path,"append":false};
			//sollevo evento
			this.form.raiseEvent(this.emitter_name,parmsObj);
		}
	}
	
	//disabilita le voci di menu principali e i sottomenu (click su portlet e su voce menu - mouseout dalle voci senza figli)
	this.deselect_all=function(click_portlet){
		var deCtrl;		
		if (this.menu_type!="flat") { // solo per menu verticale ,orizzontale e slide
			//deve disabilitare sempre anche quando clicco sul portlet 
			//else{			
				var idNode = this.id+"_"+this.Tree.currentnode.index;
				deCtrl=document.getElementById(idNode);
				try{
				if (!Empty(this.btn_image))
					document.getElementById(deCtrl.id+"_back").style.background="url("+this.btn_image+")";
				else				
					document.getElementById(deCtrl.id+"_back").className="menu_img";
				}catch(e){}
				try{
				if (!Empty(this.sx_btn_image))
					document.getElementById(deCtrl.id+"_sx").style.background="url("+this.sx_btn_image+")";
				else
					document.getElementById(deCtrl.id+"_sx").className="menu_img_sx";
				}catch(e){}
				try{
				if (!Empty(this.dx_btn_image))
					document.getElementById(deCtrl.id+"_dx").style.background="url("+this.dx_btn_image+")";
				else 
					document.getElementById(deCtrl.id+"_dx").className="menu_img_dx";
				}catch(e){}
				
				try{document.getElementById(deCtrl.id+"_icons").className = "icons_menu";}
				catch(e){}	
				try{document.getElementById(deCtrl.id+"_icons_back").className = "menu_font";}
				catch(e){}
				
				//ripristino text
				try{
				if (!Empty(this.font_color)&&!Empty(this.overcolor)){
					deCtrl.style.color=this.font_color;
					document.getElementById(deCtrl.id+"_descr").style.color=this.font_color;
					deCtrl.style.backgroundColor='';
				} else {
					deCtrl.className="menu_font";
					if (this.menu_type=="horizontal"){
						document.getElementById(deCtrl.id+"_descr").className = "menu_font";
						try{
							document.getElementById(deCtrl.id+"_descr_font").className="menu_font";
						}catch(e){}
					}						
				}
				}catch(e){}
				//per menu verticale	
				try{
				if (this.menu_type=="vertical" && deCtrl.id!=this.selectedId) {
					document.getElementById(deCtrl.id+"_arr").style.backgroundColor='';
					try{
						document.getElementById(this.selectedId+"_descr_font").className="menu_font";
					}catch(e){}
				}else{
					if (!Empty(document.getElementById(this.selectedId+"_arr"))) {
						document.getElementById(this.selectedId+"_arr").className="menu_font";
					}
					try{
						document.getElementById(this.selectedId+"_descr_font").className="menu_font";
					}catch(e){}							
				}
				}catch(e){}
				//per menu slide
				if (this.menu_type=="slide") {
					try{document.getElementById(deCtrl.id+"_descr_font").className="menu_font";}catch(e){}															
					if(this.Tree.currentnode.level!=0)
						try{deCtrl.className="submenu_font";}catch(e){};
				}
				try{
					document.getElementById(deCtrl.id+"_icons").className="icons_menu";
				}catch(e){}				
			//}
			if(this.Tree.currentnode.level!=0 || click_portlet){
				// remove sub menu
				var submenu=(this.menu_type!="horizontal2")?"sub":"sub2";
				var index=(this.menu_type!="horizontal2")?(this.Tree.root.level+1):(this.Tree.root.level+2);
				deCtrl=document.getElementById(this.id+"_"+index+"_"+submenu);   				
				//per menu slide
				if (this.menu_type!="slide")
					deCtrl.innerHTML="";				
			}
		}
	}

	/*@author Daniele Baldi TODO Aggiustare questa funzione*/
	this.NavXML = function (pNode,pLevel,pNodeXML,pNodeID,pParentID) {
		var level=pLevel;
		var nodeID,parentID;
		var node,NodeID,NodeName,NodeChild,NodeParent,Icons,Frame,NodeLink;
		nodeID=pNodeID;
		parentID=pParentID;
		for (var i=0; i < pNodeXML.childNodes.length;i++) {
			var nodechild=pNodeXML.childNodes.item(i);
			if(i==0)level++;	//incremento il livello se ci sono figli
			if (nodechild.nodeName==this.tag_node) {
				var index=nodeID;
				nodeID++;
				NodeID=getTagValue(nodechild,this.field_NodeID); //Tag del nodo
				NodeName=getTagValue(nodechild,this.field_NodeDescr); // Caption
				NodeChild= getTagValue(nodechild,this.field_ChildCount);	// Numero Childs (elements)
				NodeParent=parentID;	//ID Padre
				if(!Empty(this.field_Icons)) {
				    var value=getTagValue(nodechild,this.field_Icons);
					if (value.indexOf(".")>0)
						Icons=value; // percorso immagine
					else
						Icons="";
				}
				var oLink = new ItemLink(getTagValue(nodechild,this.field_NodeLink));
				NodeLink = oLink.link + (oLink.parameters.length > 0 ? '?'+oLink.parameters : '')	// Link
				Frame = oLink.target;	// target
				if (Frame.length==0) Frame=this.target_default;
				node=pNode.addChild(NodeID,level,NodeName,NodeChild,"",NodeLink,Frame,Icons,"","",NodeParent,pNode);
				returnID=this.NavXML(node,level,nodechild,nodeID,NodeID);
				nodeID=returnID;
			}
		}
		//Se il nodo ha figli ma non sono ancora presenti nel datasource setto che devo eseguire la querynode
		if ((pNode.childnum!='0' && pNode.children.length==0)||pNode.childnum==null){
			pNode.setExecuteQuery(true);
		}
		returnID=nodeID;
		return returnID;
	}
	
	this.getNodesChildSQL = function (pNodeID){
		var idxFieldNodeParent=this.datasource.getFldIdx(this.field_NodeParent);
		var Nodes = new Array();
		var i=0;
		// Seek root. Mi posiziono direttamente sul padre perchč il datasource č ordinato per parent
		while (i<this.datasource.nRecs && this.datasource.Data[i][idxFieldNodeParent]!=pNodeID) i++;
		// loop
		while (i<this.datasource.nRecs && this.datasource.Data[i][idxFieldNodeParent]==pNodeID){
			Nodes.push(this.datasource.Data[i]);
			i++;
		}
		return Nodes;
	}
	
	this.NavSQL = function (pNode,pLevel) {
		var level=pLevel;
		//CUSTOM
		var IconsArray,IconsOver;		
		//END CUSTOM
		var node,NodeID,NodeName,NodeChild,NodeSeq,NodeParent,Icons,Expr,ExprNot,Frame,NodeLink;
		var idxFieldNodeID=this.datasource.getFldIdx(this.field_NodeID);
		var idxFieldNodeName=this.datasource.getFldIdx(this.field_NodeDescr);
		var idxFieldChildNum=this.datasource.getFldIdx(this.field_ChildCount);
		var idxFieldNodeSeq=this.datasource.getFldIdx(this.field_NodeSeq);
		var idxFieldNodeParent=this.datasource.getFldIdx(this.field_NodeParent);
		var idxFieldIcons=this.datasource.getFldIdx(this.field_Icons);
		var idxFieldExpr=this.datasource.getFldIdx(this.field_Expr);
		var idxFieldExprNot=this.datasource.getFldIdx(this.field_ExprNot);
		var idxFieldFrame=this.datasource.getFldIdx(this.field_Frame);
		var idxFieldNodeLink=this.datasource.getFldIdx(this.field_NodeLink);
		var NodesChild=this.getNodesChildSQL(pNode.nodeid);
		for (var i=0; i<NodesChild.length; i++) {
			if(i==0)level++;	//incremento il livello se ci sono figli
			NodeID=Trim(NodesChild[i][idxFieldNodeID]);
			NodeName=Trim(NodesChild[i][idxFieldNodeName]);
			if (idxFieldChildNum!=-1) NodeChild=Trim(NodesChild[i][idxFieldChildNum]);
			NodeSeq=Trim(NodesChild[i][idxFieldNodeSeq]);
			NodeParent=Trim(NodesChild[i][idxFieldNodeParent]);
			
			
			//CUSTOM per rollover su immagini definite per ogni voce di menu
			//Icons=Trim(NodesChild[i][idxFieldIcons]);
			IconsArray=Trim(NodesChild[i][idxFieldIcons]).split("|");						
			if (IconsArray[0]!="") {Icons=LRTrim(IconsArray[0]);
			}else {Icons="";	}
			if (IconsArray[1]!="") {IconsOver=LRTrim(IconsArray[1]);
			}else {IconsOver="";}
			//END CUSTOM
			
			Expr=Trim(NodesChild[i][idxFieldExpr]);
			ExprNot=Trim(NodesChild[i][idxFieldExprNot]);
			Frame=Trim(NodesChild[i][idxFieldFrame]); // target
			if (Frame.length==0) Frame=this.target_default;
			NodeLink=Trim(NodesChild[i][idxFieldNodeLink]);
			node=pNode.addChild(NodeID,level,NodeName,NodeChild,NodeSeq,NodeLink,Frame,Icons,IconsOver,Expr,ExprNot,NodeParent,pNode);
			this.NavSQL(node,level);
		}
		//Se il nodo ha figli ma non sono ancora presenti nel datasource setto che devo eseguire la querynode
		if ((pNode.childnum!='0' && pNode.children.length==0)||pNode.childnum==null){
			pNode.setExecuteQuery(true);
		}
	}
	
	this.FillData=function(data){
		this.datasource=data;
		var root=(this.querynode!=null?this.querynode:this.Tree.getRoot());
		if(typeof(this.datasource.Data) != 'undefined'){
			// SQLDataProvider
			this.NavSQL(root,root.level);
		}else{
			// XMLDataProvider
			var xmlDoc = this.datasource.xmlDoc;
			var nodeXMLRoot=xmlDoc.documentElement.selectSingleNode(this.datasource.root);
			// root description
			this.Tree.descr=getTagValue(nodeXMLRoot,this.field_NodeDescr);
			this.NavXML(root,root.level,nodeXMLRoot,0,-1);
		}
		if(this.querynode==null){
			this.Tree.render();
		}
		else if(this.querynode.nodeid==this.Tree.currentnode.nodeid){
			this.querynode.view();			
		}
	}

	this.setRowsCols=function(NodeID,ChildCount,NodeDescr,NodeSeq,NodeParent,Icons,Expr,ExprNot,Frame,NodeLink){
		this.field_NodeID=NodeID;
		this.field_ChildCount=ChildCount;
		this.field_NodeDescr=NodeDescr;
		this.field_NodeSeq=NodeSeq;
		this.field_NodeParent=NodeParent;
		this.field_Icons=Icons;
		this.field_Expr=Expr;
		this.field_ExprNot=ExprNot;
		this.field_Frame=Frame;
		this.field_NodeLink=NodeLink;
	}
	
	this.addParmConsumer=function(ctrl){
		this.paramconsumers[this.paramconsumers.length] = ctrl;
	}

	this.addDataConsumer=function(ctrl,fld){
		this.dataconsumers[this.dataconsumers.length] = new Array(ctrl,fld);
	}

	this.FindNodeByID=function(nodeid){
		var tmpnode,i
		for(i=0;i<this.Tree.allnodes.length;i++){
			tmpnode=this.Tree.allnodes[i];
			if (tmpnode!=null && tmpnode.nodeid==nodeid)
				return tmpnode;
		}
		return null;
	}

	this.getParam=function(fld){
		if (typeof(this.Tree.currentnode)!='undefined'){
		if (fld==this.field_NodeID) {
			return this.Tree.currentnode.nodeid;
		}else 
			if (fld==this.field_NodeDescr) {
				return this.Tree.currentnode.descr;
			}else{
				return "";
			}
		}
		return "";
	}
	
	// Crea l'albero
	this.Tree=new this.tree(this) ;
	

	this.Ctrl_mousedown=function(e){	
		//el = (window.event.target) ? event.target : event.srcElement;				
		if(typeof(e)=='undefined')
			e = window.event
			
		try{
			if (navigator.userAgent.toLowerCase().indexOf('gecko')!=-1) el =  e.target;
			else el = e.srcElement;
		}catch(e){}
		
		try{
			if(el.id.indexOf(name)==-1){
				this.over=false;   
				this.deselect_all(true);
			}
		}catch(e){}
		
	}
	
	
	this.addObserver('Ctrl',this);
	//TODO sostituire questa funzione con AddListenerToHTMLEvent nella nuova release di Portalstudio
	this.form.Ctrl.onmousedown=new Function('e',this.form.formid+'.'+this.name+'.dispatchEvent("mousedown",e)');
	
}

ZtVWeb.MenuViewCtrl.prototype=new ZtVWeb.StdControl;


/**************Funzioni di libreria***************/
function ItemLink(item) {
	this.link='';
	this.target='';
	this.parameters="";
	var as=item.split('?');
	if (as.length > 0) this.link=as[0];
	if (as.length > 1) {
		var ap=as[1].split('&');
		for (var i=0; i<ap.length; i++) {
			if (ap[i].indexOf('target=') >=0) {
				this.target=ap[i].substr(7);
			} else {
				this.parameters+=(this.parameters.length==0 ? '' : '&')+ap[i];
			}
		}
	}
}

function getTagValue(nodechild,tagname) {
   try {
		return LRTrim(nodechild.selectSingleNode(tagname).firstChild.nodeValue);
	} catch(e) {
		return "";
	}
}

