/**************************************************************************
	Copyright (c) 2001-2003 Geir Landr? (drop@destroydrop.com)
	JavaScript Tree - www.destroydrop.com/hjavascripts/tree/
	Version 0.96

	This script can be used freely as long as all copyright messages are
	intact.
**************************************************************************/

// Arrays for nodes and icons
var nodes		= new Array();;
var openNodes	= new Array();
var icons		= new Array(6);
nodVar 			= "";

// Loads all icons that are used in the tree
function preloadIcons(foldericon) {
	icons[0] = new Image();
	icons[0].src = "includes/treeview/img/plus.gif";
	icons[1] = new Image();
	icons[1].src = "includes/treeview/img/plusbottom.gif";
	icons[2] = new Image();
	icons[2].src = "includes/treeview/img/minus.gif";
	icons[3] = new Image();
	icons[3].src = "includes/treeview/img/minusbottom.gif";
	icons[4] = new Image();
	icons[4].src = "themes/well/images/" + foldericon + "menuitem3.gif";
	icons[5] = new Image();
	icons[5].src = "themes/well/images/" + foldericon + "menuitem1.gif";
}
// Create the tree
function createTree(arrName, foldericon, adminflag, idcdl, isAllOpened, currentpage, idfac, parentpage, startNode, openNode) {


	nodes = arrName;
	if (nodes.length > 0) {
		preloadIcons(foldericon);
		if (startNode == null) startNode = 0;
		if (openNode != 0 || openNode != null) setOpenNodes(openNode);

		if (startNode !=0) {
			var nodeValues = nodes[getArrayId(startNode)].split("|");
			document.write("<a href=\"" + nodeValues[3] + "\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\"><img border=0 src=\"includes/treeview/img/folderopen.gif\" align=\"absbottom\" alt=\"\" />" + nodeValues[2] + "</a><br />");
		}

		var recursedNodes = new Array();

		addNode(startNode, recursedNodes, foldericon, adminflag, idcdl, isAllOpened, currentpage, idfac, parentpage);

		}
	if (isAllOpened == 1) {
	if (nodes.length > 0) {

	if (startNode == null) startNode = 0;
	var recursedNodesOpen = new Array();

  openNodeFunc(startNode, recursedNodesOpen);
	}
	}

}
function openNodeFunc(parentNode, recursedNodesOpen) {
	for (var i = 0; i < nodes.length; i++) {

		var nodeValues = nodes[i].split("|");
		if (nodeValues[1] == parentNode) {

			var ls	= lastSibling(nodeValues[0], nodeValues[1]);
			var hcn	= hasChildNode(nodeValues[0]);
			var ino = isNodeOpen(nodeValues[0]);
			var NodVar = "";
			// Write out line & empty icons

			for (g=0; g<recursedNodesOpen.length; g++) {
			}

			// Write out join icons
			if (hcn) {
				if (ls) {
				oc(nodeValues[0], 1, 1);
				} else {
				oc(nodeValues[0], 0, 1);
				}
			}
		  // Write out folder & page icons
			if (hcn) {
				openNodeFunc(nodeValues[0], recursedNodesOpen);
			}
			// remove last line or empty icon
			recursedNodesOpen.pop();
		}
	}
}
// Returns the position of a node in the array
function getArrayId(node) {
	for (i=0; i<nodes.length; i++) {
		var nodeValues = nodes[i].split("|");
		if (nodeValues[0]==node) return i;
	}
}
// Puts in array nodes that will be open
function setOpenNodes(openNode) {
	for (i=0; i<nodes.length; i++) {
		var nodeValues = nodes[i].split("|");
		if (nodeValues[0]==openNode) {
			openNodes.push(nodeValues[0]);
			setOpenNodes(nodeValues[1]);
		}
	}
}
// Checks if a node is open
function isNodeOpen(node) {
	for (i=0; i<openNodes.length; i++)
		if (openNodes[i]==node) return true;
	return false;
}
// Checks if a node has any children
function hasChildNode(parentNode) {
	for (i=0; i< nodes.length; i++) {
		var nodeValues = nodes[i].split("|");
		if (nodeValues[1] == parentNode) return true;
	}
	return false;
}
// Checks if a node is the last sibling
function lastSibling (node, parentNode) {
	var lastChild = 0;
	for (i=0; i< nodes.length; i++) {
		var nodeValues = nodes[i].split("|");
		if (nodeValues[1] == parentNode)
			lastChild = nodeValues[0];
	}
	if (lastChild==node) return true;
	return false;
}
// Adds a new node to the tree
function addNode(parentNode, recursedNodes, foldericon, adminflag, idcdl, isAllOpened, currentpage, idfac, parentpage) {

	for (var i = 0; i < nodes.length; i++) {

		var nodeValues = nodes[i].split("|");
		if (nodeValues[1] == parentNode) {

			var ls	= lastSibling(nodeValues[0], nodeValues[1]);
			var hcn	= hasChildNode(nodeValues[0]);
			var ino = isNodeOpen(nodeValues[0]);
			var NodVar = "";
			// Write out line & empty icons

			if (isAllOpened == 1) { // ALBERO TUTTO APERTO E LINK DISATTIVATI
			//Write Pre table
			document.write("<table style=\"border: 1px solid #C6C6C6; margin: 1px;\" width=\"100%\" height=\"9\" border=\"0\" cellspaing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td width=\"1\" height=\"9\"><font class=\"tinytiny\">&nbsp;&nbsp;</font></td><td width=\"1\" height=\"9\">");


			for (g=0; g<recursedNodes.length; g++) {
				if (recursedNodes[g] == 1) document.write("&nbsp;");
				else  document.write("&nbsp;");
			}

			//Write Pre Post table
			document.write("</td><td width=\"1\" height=\"9\" valign=\"top\">");
			// put in array line & empty icons
			if (ls) recursedNodes.push(0);
			else recursedNodes.push(1);


			// Write out join icons
			if (hcn) {
				if (ls) {
					document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 1);\"><img width=\"0\" height=\"0\" border=0 id=\"join" + nodeValues[0] + "\" src=\"includes/treeview/img/");
					 	if (ino) document.write("minus");
						else document.write("plus");
					document.write("bottom.gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
				} else {
					document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 0);\"><img width=\"0\" height=\"0\" border=0 id=\"join" + nodeValues[0] + "\" src=\"includes/treeview/img/");
						if (ino) document.write("minus");
						else document.write("plus");
					document.write(".gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
				}
			} else {
				if (ls) document.write("<img width=\"0\" height=\"0\" border=0 src=\"includes/treeview/img/joinbottom.gif\" align=\"absbottom\" alt=\"\" />");
				else document.write("<img width=\"0\" height=\"0\" border=0 src=\"includes/treeview/img/join.gif\" align=\"absbottom\" alt=\"\" />");
			}

		  // Write out folder & page icons
			if (hcn) {
				document.write("<img border=0 id=\"icon" + nodeValues[0] + "\" src=\"themes/well/images/blank");
				document.write(".gif\" align=\"absbottom\" alt=\"Folder\"  width=\"1\" height=\"1\"/>");
			} else {
			if (nodeValues[1] != 0) {
		  document.write("<img border=0 id=\"icon" + nodeValues[0] + "\" src=\"themes/well/images/blank.gif\" align=\"absbottom\" alt=\"Page\"  width=\"1\" height=\"1\"/>");
		  } else {
		  document.write("<img border=0 id=\"icon" + nodeValues[0] + "\" src=\"themes/well/images/blank.gif\" align=\"absbottom\" alt=\"Page\"  width=\"1\" height=\"1\"/>");
		  }
		  }

			// Write In Table
			document.write("</td><td width=\"1\" height=\"9\"><font class=\"tinytiny\">&nbsp;&nbsp;&nbsp;&nbsp;</font></td><td width=\"100%\" height=\"9\" valign=\"middle\" align=\"left\"><font class=\"blockmenu_2\">");

			// Start link

			if (ls) {
			if (nodeValues[3] != "" && nodeValues[3] != "#") {
			if (!hcn) {
			document.write("<a href=\"javascript:void(0); \" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  } else {
		  document.write("<a href=\"javascript:oc(" + nodeValues[0] + ", 1);\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  }
		  } else {
		  if (!hcn) {
		  document.write("<a href=\"javascript:void(0); \" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  } else {
		  document.write("<a href=\"javascript:oc(" + nodeValues[0] + ", 1);\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  }
		  }
		  } else {
		  if (nodeValues[3] != "" && nodeValues[3] != "#") {
		  if (!hcn) {
		  document.write("<a href=\"javascript:void(0); \" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  } else {
		  document.write("<a href=\"javascript:oc(" + nodeValues[0] + ", 1);\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  }
		  } else {
		  if (!hcn) {
		  document.write("<a href=\"javascript:void(0); \" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  } else {
		  document.write("<a href=\"javascript:oc(" + nodeValues[0] + ", 1);\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  }
		  }

		  }



			// Write out node name
			document.write(nodeValues[2]);

			// End link
			document.write("</a><br />");

			// Write END Table
			document.write("</font></td>")
			if (adminflag == 1) {
			if (idfac == 2) {
			if	(nodeValues[4] == 1) {
			document.write("<td width=\"65\" align=\"center\" nowrap><img src=\"themes/well/images/up_gray.gif\" width=\"13\" height=\"13\" alt=\"Sposta Su\" border=\"0\">&nbsp;");
			} else {
			document.write("<td width=\"65\" align=\"center\" nowrap><a href=\"javascript:window.location.href='gestione00.php?op=boglobal_wizardmenu2_cdl_up&idcdl=" + idcdl + "&idpage=" + nodeValues[0] + "&nodVar=' + nodVar;\"><img src=\"themes/well/images/up.gif\" width=\"13\" height=\"13\" alt=\"Sposta Su\" border=\"0\"></a>&nbsp;");
		  }
		  if	(nodeValues[4] == nodeValues[5]) {
			document.write("<img src=\"themes/well/images/down_gray.gif\" width=\"13\" height=\"13\" alt=\"Sposta Gi?\" border=\"0\"></td><td width=\"1\"><font class=\"tinytiny\">&nbsp;</font></td>");
			} else {
			document.write("<a href=\"javascript:window.location.href='gestione00.php?op=boglobal_wizardmenu2_cdl_down&idcdl=" + idcdl + "&idpage=" + nodeValues[0] + "&nodVar=' + nodVar;\"><img src=\"themes/well/images/down.gif\" width=\"13\" height=\"13\" alt=\"Sposta Gi?\" border=\"0\"></a></td><td width=\"1\"><font class=\"tinytiny\">&nbsp;</font></td>");
		  }
		  document.write("<td width=\"80\" nowrap align=\"center\"><a href=\"javascript:window.location.href='gestione00.php?op=boglobal_modifymenu2_cdl&idcdl=" + idcdl + "&idpagecdl=" + nodeValues[0] + "&nodVar=' + nodVar;\"><img src=\"themes/well/images/000000/modifica.gif\" width=\"13\" height=\"12\" alt=\"Modifica\" border=\"0\"></a></td><td width=\"1\"><font class=\"tinytiny\">&nbsp;</font></td><td width=\"50\" align=\"center\" nowrap><a href=\"javascript:window.location.href='gestione00.php?op=boglobal_cancelmenu2_cdl&idcdl=" + idcdl + "&idpagecdl=" + nodeValues[0] + "&nodVar=' + nodVar;\"><img src=\"themes/well/images/000000/cancella.gif\" width=\"10\" height=\"10\" alt=\"Cancella\" border=\"0\"></a></td><td width=\"1\"><font class=\"tinytiny\">&nbsp;</font></td>");
		  } else {
			if	(nodeValues[4] == 1) {
			document.write("<td width=\"30\" align=\"center\" nowrap><img src=\"themes/well/images/up_gray.gif\" width=\"13\" height=\"13\" alt=\"Sposta Su\" border=\"0\">&nbsp;");
			} else {
			document.write("<td width=\"30\" align=\"center\" nowrap><a href=\"javascript:window.location.href='gestione00.php?op=boglobal_wizardmenu_cdl_up&idcdl=" + idcdl + "&idpage=" + nodeValues[0] + "&nodVar=' + nodVar;\"><img src=\"themes/well/images/up.gif\" width=\"13\" height=\"13\" alt=\"Sposta Su\" border=\"0\"></a>&nbsp;");
		  }
		  if	(nodeValues[4] == nodeValues[5]) {
			document.write("<img src=\"themes/well/images/down_gray.gif\" width=\"13\" height=\"13\" alt=\"Sposta Gi?\" border=\"0\"></td><td width=\"1\"><font class=\"tinytiny\">&nbsp;</font></td>");
			} else {
			document.write("<a href=\"javascript:window.location.href='gestione00.php?op=boglobal_wizardmenu_cdl_down&idcdl=" + idcdl + "&idpage=" + nodeValues[0] + "&nodVar=' + nodVar;\"><img src=\"themes/well/images/down.gif\" width=\"13\" height=\"13\" alt=\"Sposta Gi?\" border=\"0\"></a></td><td width=\"1\"><font class=\"tinytiny\">&nbsp;</font></td>");
		  }
		  if	(nodeValues[1] != 0) {
		  document.write("<td width=\"80\" align=\"center\" nowrap><a href=\"javascript:void(0);window.location.href='gestione00.php?op=boglobal_wizardmenu_cdl_left&idcdl=" + idcdl + "&idpage=" + nodeValues[0] + "&nodVar=' + nodVar;\"><img src=\"themes/well/images/left.gif\" width=\"13\" height=\"13\" alt=\"Sposta Sx\" border=\"0\"></a>&nbsp;");
		  } else {
		  document.write("<td width=\"80\" align=\"center\" nowrap><img src=\"themes/well/images/left_gray.gif\" width=\"13\" height=\"13\" alt=\"Sposta Sx\" border=\"0\">&nbsp;");
		  }
		  if	(nodeValues[4] > 1) {
		  document.write("<a href=\"javascript:window.location.href='gestione00.php?op=boglobal_wizardmenu_cdl_right&idcdl=" + idcdl + "&idpage=" + nodeValues[0] + "&nodVar=' + nodVar;\"><img src=\"themes/well/images/right.gif\" width=\"13\" height=\"13\" alt=\"Sposta Dx\" border=\"0\"></a></td><td width=\"1\"><font class=\"tinytiny\">&nbsp;</font></td>");
		  } else {
		  document.write("<img src=\"themes/well/images/right_gray.gif\" width=\"13\" height=\"13\" alt=\"Sposta Dx\" border=\"0\"></td><td width=\"1\"><font class=\"tinytiny\">&nbsp;</font></td>");
		  }
		  document.write("<td width=\"60\" nowrap align=\"center\"><a href=\"javascript:window.location.href='gestione00.php?op=boglobal_modifymenu_cdl&idcdl=" + idcdl + "&idpagecdl=" + nodeValues[0] + "&nodVar=' + nodVar;\"><img src=\"themes/well/images/000000/modifica.gif\" width=\"13\" height=\"12\" alt=\"Modifica\" border=\"0\"></a></td><td width=\"1\"><font class=\"tinytiny\">&nbsp;</font></td><td width=\"70\" align=\"center\" nowrap><a href=\"javascript:window.location.href='gestione00.php?op=boglobal_cancelmenu_cdl&idcdl=" + idcdl + "&idpagecdl=" + nodeValues[0] + "&nodVar=' + nodVar;\"><img src=\"themes/well/images/000000/cancella.gif\" width=\"10\" height=\"10\" alt=\"Cancella\" border=\"0\"></a></td><td width=\"1\"><font class=\"tinytiny\">&nbsp;</font></td><td width=\"60\" nowrap align=\"center\"><a href=\"javascript:window.location.href='gestione00.php?op=boglobal_insertmenu_cdl&idcdl=" + idcdl + "&parent=" + nodeValues[0] + "&nodVar=' + nodVar;\"><img src=\"themes/well/images/000000/inserisci.gif\" width=\"12\" height=\"8\" alt=\"Inserisci\" border=\"0\"></a></td>");
		  }
			} else {

			}
			document.write("</tr></table>");

			// If node has children write out divs and go deeper
			if (idfac != 2) {
			if (hcn) {
				document.write("<div id=\"div" + nodeValues[0] + "\"");
					if (!ino) document.write(" style=\"display: none;\"");
				document.write(">");
				addNode(nodeValues[0], recursedNodes, foldericon, adminflag, idcdl, isAllOpened);
				document.write("</div>");
				}
			}

			// remove last line or empty icon
			recursedNodes.pop();


			} else { // ALBERO APRIBILE E CHIUDIBILE E LINK ATTIVI

			//Write Pre table

			document.write("<table width=\"100%\" height=\"9\" border=\"0\" cellspaing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td width=\"1\" height=\"9\">");




			//Write Pre Post table
			document.write("</td><td width=\"1\" height=\"9\" valign=\"top\">");
			// put in array line & empty icons
			if (ls) recursedNodes.push(0);
			else recursedNodes.push(1);


			// Write out join icons
			if (hcn) {
				if (ls) {
					document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 1);\"><img width=\"0\" height=\"0\" border=0 id=\"join" + nodeValues[0] + "\" src=\"includes/treeview/img/");
					 	if (ino) document.write("minus");
						else document.write("plus");
					document.write("bottom.gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
				} else {
					document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 0);\"><img width=\"0\" height=\"0\" border=0 id=\"join" + nodeValues[0] + "\" src=\"includes/treeview/img/");
						if (ino) document.write("minus");
						else document.write("plus");
					document.write(".gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
				}
			} else {
				if (ls) document.write("<img width=\"0\" height=\"0\" border=0 src=\"includes/treeview/img/joinbottom.gif\" align=\"absbottom\" alt=\"\" />");
				else document.write("<img width=\"0\" height=\"0\" border=0 src=\"includes/treeview/img/join.gif\" align=\"absbottom\" alt=\"\" />");
			}

		  // Write out folder & page icons
			if (hcn) {
				document.write("<img border=0 id=\"icon" + nodeValues[0] + "\" src=\"themes/well/images/blank")
				document.write(".gif\" align=\"absbottom\" alt=\"Folder\" width=\"1\" height=\"1\" />");
			} else {
			if (nodeValues[1] != 0) {
			if (currentpage == nodeValues[0]) {
		  document.write("<img border=0 id=\"icon" + nodeValues[0] + "\" src=\"themes/well/images/blank.gif\" align=\"absbottom\" alt=\"Page\" width=\"1\" height=\"1\" />");
		  } else {
		  document.write("<img border=0 id=\"icon" + nodeValues[0] + "\" src=\"themes/well/images/blank.gif\" align=\"absbottom\" alt=\"Page\" width=\"1\" height=\"1\" />");
		  }
		  } else {
		  if (currentpage == nodeValues[0]) {
		  document.write("<img border=0 id=\"icon" + nodeValues[0] + "\" src=\"themes/well/images/blank.gif\" align=\"absbottom\" alt=\"Page\" width=\"1\" height=\"1\" />");
		  } else {
		  document.write("<img border=0 id=\"icon" + nodeValues[0] + "\" src=\"themes/well/images/blank.gif\" align=\"absbottom\" alt=\"Page\" width=\"1\" height=\"1\" />");
		  }
		  }
		  }

			// Write In Table
			if (getParentID(nodeValues[0]) == 0) {
			document.write("</td><td width=\"1\" height=\"9\"><font class=\"tinytiny\">&nbsp;</font></td><td width=\"100%\" height=\"9\" valign=\"middle\" align=\"right\"><span class=\"menusx\">");
			} else {
			document.write("</td><td width=\"1\" height=\"9\"><font class=\"tinytiny\">&nbsp;</font></td><td width=\"100%\" height=\"9\" valign=\"middle\" align=\"left\"><span class=\"menusx\">");
			}
			// Start link
			if (getParentID(nodeValues[0]) == 0) {
			var add = "";
			} else {
			var add = "_2";
			}
			if (nodeValues[1] != 0) {
			if (currentpage == nodeValues[0])	{
			document.write("<font class=\"submenu_selected" + add + "\">");
		  } else {
		  document.write("<font class=\"submenu" + add + "\">");
		  }
			} else {
			if (currentpage == nodeValues[0])	{
			document.write("<font class=\"submenu_selected" + add + "\">");
		 	 } else {
		  	document.write("<font class=\"submenu" + add + "\">");
		  	}
			}
			// Write END Table
			for (g=0; g<recursedNodes.length; g++) {
				if (recursedNodes[g] == 1) document.write("&nbsp;");
				else  document.write("&nbsp;");
			}
			if (ls) {
			if (nodeValues[3] != "" && nodeValues[3] != "#") {
			if (!hcn) {
			document.write("<a href=\"javascript:window.location='" + nodeValues[3] + "&nodVar=' + nodVar;\" onClick=\"javascript: window.location='" + nodeValues[3] + "&nodVar=' + nodVar;\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  } else {
		  document.write("<a href=\"javascript:window.location='" + nodeValues[3] + "&nodVar=' + nodVar;\" onClick=\"javascript: oc(" + nodeValues[0] + ", 1); window.location='" + nodeValues[3] + "&nodVar=' + nodVar;\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  }
		  } else {
		  if (!hcn) {
		  document.write("<a href=\"javascript:void(0);\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  } else {
		  document.write("<a href=\"javascript:void(0);\" onClick=\"javascript: oc(" + nodeValues[0] + ", 1);\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  }
		  }
		  } else {
		  if (nodeValues[3] != "" && nodeValues[3] != "#") {
		  if (!hcn) {
		  document.write("<a href=\"javascript:window.location='" + nodeValues[3] + "&nodVar=' + nodVar;\" onClick=\"javascript: window.location='" + nodeValues[3] + "&nodVar=' + nodVar;\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  } else {
		  document.write("<a href=\"javascript:window.location='" + nodeValues[3] + "&nodVar=' + nodVar;\" onClick=\"javascript: oc(" + nodeValues[0] + ", 0); window.location='" + nodeValues[3] + "&nodVar=' + nodVar;\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  }
		  } else {
		  if (!hcn) {
		  document.write("<a href=\"javascript:void(0);\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  } else {
		  document.write("<a href=\"javascript:void(0);\" onClick=\"javascript: oc(" + nodeValues[0] + ", 0);\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
		  }
		  }

		  }



			// Write out node name
			document.write(nodeValues[2]);
			document.write("</a>");

			if (nodeValues[1] != 0) {
			if (currentpage == nodeValues[0])	{
			document.write("</font>");
		  } else {
		  document.write("</font>");
		  }
			} else {
			document.write("</font>");
			}

			// End link



			document.write("<br /></span></td>")
			if (adminflag == 1) {

			if (idfac == 2) {
			if (parentNode == 0) {
			document.write("<td width=\"1\" align=\"right\">&nbsp;</td><td width=\"15\" align=\"right\"><a href=\"javascript:void(0);\" onClick=\"JAVASCRIPT:openPU2('gestione00.php?op=boglobal_insertmenu2_text_cdl&idcdl=" + idcdl + "&idpagecdl=" + nodeValues[0] + "&nodVar=' + nodVar,700,500,null,null,'popup',1,true,true,true,'WELL - AMMINISTRAZIONE');\"><img src=\"themes/well/images/000000/inserisci.gif\" width=\"12\" height=\"8\" alt=\"Inserisci\" border=\"0\" onmouseover=\"this.T_WIDTH=110; return escape('Inserisci Articolo')\"></a></td>");
		  } else {
		  }
		  } else {
			if (nodeValues[6] == 0) {
			document.write("<td width=\"1\" align=\"right\">&nbsp;</td><td width=\"15\" align=\"right\"><a href=\"javascript:void(0);\" onClick=\"JAVASCRIPT:openPU2('gestione00.php?op=boglobal_insertmenu_text_cdl&idcdl=" + idcdl + "&idpagecdl=" + nodeValues[0] + "&nodVar=' + nodVar,700,500,null,null,'popup',1,true,true,true,'WELL - AMMINISTRAZIONE');\"><img src=\"themes/well/images/000000/inserisci.gif\" width=\"12\" height=\"8\" alt=\"Inserisci\" border=\"0\" onmouseover=\"this.T_WIDTH=200; return escape('Attiva pagina contenuti collegata')\"></a></td>");
		  } else {
			document.write("<td width=\"1\" align=\"right\">&nbsp;</td><td width=\"15\" align=\"right\"><a href=\"javascript:void(0);\" onClick=\"JAVASCRIPT:openPU2('gestione00.php?op=boglobal_cancelmenu_text_cdl&idcdl=" + idcdl + "&idpagecdl=" + nodeValues[0] + "&nodVar=' + nodVar,700,500,null,null,'popup',1,true,true,true,'WELL - AMMINISTRAZIONE');\"><img src=\"themes/well/images/000000/cancella.gif\" width=\"10\" height=\"10\" alt=\"Cancella\" border=\"0\" onmouseover=\"this.T_WIDTH=220; return escape('Disattiva pagina contenuti collegata')\"></a></td>");
		  }
		  }
			} else {

			}
			document.write("</tr></table>");

			// If node has children write out divs and go deeper
			if (idfac != 2) {
			if (hcn) {
				if (getParentID(nodeValues[0]) == 0) {
				document.write("<div id=\"div" + nodeValues[0]+ "\" style=\"left:+165px; width: 160px; position: relative;");
				} else {
				document.write("<div  id=\"div" + nodeValues[0] + "\" style=\"");
				}

				if (!ino) document.write(" display: none;");
				document.write("\">");
				addNode(nodeValues[0], recursedNodes, foldericon, adminflag, idcdl, isAllOpened, currentpage, idfac);
				document.write("</div>");
			}
		  }

			// remove last line or empty icon
			recursedNodes.pop();
		}
	 }
	}
}
function getParentID(node) {
  		var nodearray = nodes[getArrayId(node)].split("|");
  		var parentnode = nodearray[1];
  		return parentnode;
}

function myNodeOpen(node) {
var theDiv = document.getElementById("div" + node);
	if (theDiv.style.display == 'none') {
	return true;
	} else {
	return false;
	}
}


function closeRootNode(targetnode, callingnode) {
	if (myNodeOpen(callingnode)) {
		oc(targetnode,1);
	}
}

function ismychild(targetnode, callingnode) {
	var parentid = getParentID(targetnode);
	if (parentid == 0) {
		return true;
	} else {
	if (parentid == callingnode) {
		return true;
	} else {
		ismychild(parentid, callingnode);
	}
	}
	return false;
}

function ismyparent(targetnode, callingnode) {
	var parentid = getParentID(callingnode);
	if (parentid == 0) {
		return true;
	} else {
	if (parentid == targetnode) {
		return true;
	} else {
		ismychild(parentid, targetnode);
	}
	}
	return false;
}

function check(node) {
		var parentnode = getParentID(node);
  		if (parentnode == 0) {
			var nodArray;
			nodArray = nodVar.split(';');
			nodArray.unique;
				for (var i=0;i<nodArray.length;i++) {
  					var theId = nodArray[i];
  						if (theId != 0 && theId != "" && theId != node) {
  						var parentparentref = getParentID(theId);
  							if (parentparentref == 0) {
  								closeRootNode(nodArray[i],node);
  							}
  						}
				}

  		} else {

			var nodArray;
			nodArray = nodVar.split(';');
			nodArray.unique;
				for (var i=0;i<nodArray.length;i++) {
  					var theId = nodArray[i];
  						if (theId != 0 && theId != "" && theId != node) {
  						var parentparentref = ismychild(theId, node);
  						var parentparentref2 = ismyparent(theId, node);
  							if (parentparentref == false && parentparentref2 == false) {
  								closeRootNode(nodArray[i],node);
  							}
  						}
				}

  		}

}
// Opens or closes a node
function oc(node, bottom, allopen) {
	mystring = ";" + node + ";";
	if (nodVar.indexOf(mystring) == -1) {
	nodVar = nodVar + mystring;
    } else {
    nodVar = nodVar.replace(mystring,"");
    }
	var theDiv = document.getElementById("div" + node);
	var theJoin	= document.getElementById("join" + node);
	var theIcon = document.getElementById("icon" + node);
	if (allopen != 1) check(node);
	if (theDiv.style.display == 'none') {
		if (bottom==1) theJoin.src = icons[3].src;
		else theJoin.src = icons[2].src;
		theIcon.src = icons[5].src;
		theDiv.style.display = '';
	} else {
		if (bottom==1) theJoin.src = icons[1].src;
		else theJoin.src = icons[0].src;
		theIcon.src = icons[4].src;
		theDiv.style.display = 'none';
	}
}
// Push and pop not implemented in IE
if(!Array.prototype.push) {
	function array_push() {
		for(var i=0;i<arguments.length;i++)
			this[this.length]=arguments[i];
		return this.length;
	}
	Array.prototype.push = array_push;
}
if(!Array.prototype.pop) {
	function array_pop(){
		lastElement = this[this.length-1];
		this.length = Math.max(this.length-1,0);
		return lastElement;
	}
	Array.prototype.pop = array_pop;
}

