var categ_index = new Array();
var tree;
	
	function ExpandItem(Node)
	{
		Node.expand();
		if ((Node.parent!=null) && (Node.parent!=tree.getRoot))
		{
			if (Node.parent!=tree.getRoot) ExpandItem(Node.parent);
		}
		else 
		{	
			Node.expand();
		}
	}
	function FindByName(id_nom, mess_trouve)
	{
	var nomRechMaj, nomListeMaj;
	var nb_ligne_trouvee=0;
	var LibLig;

		nom=document.getElementById(id_nom);
		nomRechMaj = unescapeEntities(nom.value.toUpperCase());
		tree.collapseAll();

		for (var i = 0; i < YAHOO.widget.TreeView.nodeCount; i++) {
			tempNode = tree.getNodeByIndex(i);          
			if (tempNode) {             
				labelNode = tempNode.label.toUpperCase();
				if(labelNode.indexOf(nomRechMaj)!=-1)
				{
					tempNode.labelStyle = "icon-found";
					++nb_ligne_trouvee;
					ExpandItem(tempNode);
				}
				else tempNode.labelStyle = "ygtvlabel";
			}       
		}
		if (nb_ligne_trouvee>0) alert_conv(nb_ligne_trouvee+' '+mess_trouve);
	}

	function ConstruireArbreCategorie() {

		clearTimeout(window.tid);

		DivCible=document.getElementById("treeDivWait");
		KeepCateg=document.getElementById("keep_categ");
		//instantiate the tree:
		tree = new YAHOO.widget.TreeView("treeDiv1");
		AjouteEnfant(-1, tree.getRoot(), true);
	    DivCible.innerHTML="";

		tree.subscribe("labelClick", function(node) 
		{ 
			// Fonction appelée lorsque l'on clique sur un item
			if (node.hasChildren(true)==false) 
			{
				var num_lig_tab_categ=categ_index[node.index];
				var categorie_id=categ_id[num_lig_tab_categ];
				var libelle_categorie=GetNomCateg(categorie_id);
				var TotItem=categ_TotItem[num_lig_tab_categ];
				window.open("manufacturer/product_catalogue.php?rech_prod=1&cat="+categorie_id+"&TotItem="+TotItem+"&cat_name="+libelle_categorie,"","scrollbars=1,top=0,left=0,width="+screen.width+",height="+screen.height); 

				//popup("product_catalogue.php?rech_prod=1&cat="+categorie_id+"&TotItem="+TotItem+"&cat_name="+libelle_categorie,"",screen.height,screen.width);
			}
			}  ); 

		tree.draw();
	}

//an anonymous function wraps our code to keep our variables
//in function scope rather than in the global namespace:
(function() {
//	var tree; //will hold our TreeView instance
	
	function treeInit() {

		//Hand off ot a method that randomly generates tree nodes:
		DivCible=document.getElementById("treeDivWait");
	    DivCible.innerHTML="<p /><p /><div align='center'><img src='images/ajax-loader.gif' /></div>";
		window.tid=setTimeout("ConstruireArbreCategorie()",100);
		
		//handler for expanding all nodes
		YAHOO.util.Event.on("expand", "click", function(e) {
			tree.expandAll();
			YAHOO.util.Event.preventDefault(e);
		});
		
		//handler for collapsing all nodes
		YAHOO.util.Event.on("collapse", "click", function(e) {
			tree.collapseAll();
			YAHOO.util.Event.preventDefault(e);
		});
	}

	//When the DOM is done loading, we can initialize our TreeView
	//instance:
	YAHOO.util.Event.onDOMReady(treeInit);	
})();//anonymous function wrapper closed; () notation executes function
