function getParent(id) {
	for (i=0;i<menu.length;i++) {
		var item=menu[i];
		if (item[0]== id) return item[2];
	    }
	return 0;
}
function getAncestor(id) {
	var ancestor= new Array();
	var idx=0;
	ancestor[0]=id;
	idx++;
	p=getParent(id);
	
	while (p != 0) {
		
		ancestor[idx]=p;
		idx++;
		p=getParent(p);
    	}

	return ancestor;
   }

function inArray(tab,val) {
	var i=0;

	for (i=0;i<tab.length;i++) {
        if (tab[i] == val) return true;		
	    }
	return false;
   }


function isParent(id) {
    var i=0;
    for (i=0;i<menu.length;i++) {
    	var item=menu[i];
    	var myParent=item[2];
    	
    	if (id == myParent) return true;
         }
    
    return false;
	}




function menuDevFront(ancestors,choice, level,indent) {
	var i=0;
	var s='';
        var first = true;
	for (i=0;i<menu.length;i++)
	    {
	        var item=menu[i];
	        var myId = item[0];
	        var label=item[1];
	        var parent=item[2];
                var page=item[3];
                
	        if (parent == level) {
	            if (level==1) {
                        if (first) {
                                first=false;
                                s=s+'<br>';    
                                } else {
                                s=s+'<img src="/phoenixfo/images/pnxseparator.gif" border="0" height="1" width="180"><br>';    
                                }
                          }

	            if (inArray(ancestors,myId)) {
                      var parentTag = (isParent(myId))?'&nbsp;&nbsp;<img src="/phoenixfo/images/pnxssrubrique.gif" align="top" border="0">':'';
	                if (choice == myId) {
	            	s=s+indent+'<a class="pnxMenuLink" href="javascript:menuSetChoiceFront(\''+myId+'\')" >'+'<b>'+label+'</b></a>'+parentTag+'<br>';
	            	s=s+menuDevFront(ancestors,choice,myId,indent+'&nbsp;&nbsp;');
	            	} else {
	            	s=s+indent+'<a  class="pnxMenuLink" href="javascript:menuSetChoiceFront(\''+myId+'\')" >'+label+'</a>'+parentTag+'<br>';
	            	s=s+menuDevFront(ancestors,choice,myId,indent+'&nbsp;&nbsp;');
	            	}
	            } else {
	                var parentTag = (isParent(myId))?'&nbsp;&nbsp;<img src="/phoenixfo/images/pnxssrubrique.gif" align="top" border="0">':'';
	            	s=s+indent+'<a  class="pnxMenuLink" href="javascript:menuSetChoiceFront(\''+myId+'\')">'+label+'</a>'+parentTag+'<br>';
	            	}
                	            
	        	}
 
	        
	    	}
	return s;
	}


function menuDev(ancestors,choice, level,indent) {
	var i=0;
	var s='';
	for (i=0;i<menu.length;i++)
	    {
	        var item=menu[i];
	        var myId = item[0];
	        var label=item[1];
	        var parent=item[2];
	        if (parent == level) {
	            
	            if (inArray(ancestors,myId)) {
	                if (choice == myId) {
	            	s=s+'<span onMouseOut="this.style.cursor=\'default\';" onMouseOver="this.style.cursor=\'pointer\';" onClick="menuSetChoice(\''+myId+'\')" >'+indent+'<b>'+label+'</b></span><br>';
	            	s=s+menuDev(ancestors,choice,myId,indent+'&nbsp;&nbsp;');
	            	} else {
	            	s=s+'<span onMouseOut="this.style.cursor=\'default\';" onMouseOver="this.style.cursor=\'pointer\';"  onClick="menuSetChoice(\''+myId+'\')" >'+indent+label+'</span><br>';
	            	s=s+menuDev(ancestors,choice,myId,indent+'&nbsp;&nbsp;');
	            	}
	            } else {
	                var parentTag = (isParent(myId))?' >':'';
	            	s=s+'<span onMouseOut="this.style.cursor=\'default\';" onMouseOver="this.style.cursor=\'pointer\';" onClick="menuSetChoice(\''+myId+'\')">'+indent+label+parentTag+'</span><br>';
	            	}
                	            
	        	}
 
	        
	    	}
	return s;
	}

function getChoiceIndex(id) {
	for(i=0;i<menu.length;i++) 
	   if (menu[i][0]==id) return i;
	return null;
}

function menuSetChoiceFront(id) {
   var elt=document.getElementById('_menu');
   var lastChoice=elt.choice;
   

   if (lastChoice != id) {
      elt.choice=id;
      currentChoice=id;
      var myIndex= getChoiceIndex(id) ;
      var myPage=menu[myIndex][3];

      if (myPage != ''){
         // alert(cPath);

        
                 var reg1=new RegExp("cPath","g");
                 if (!myPage.match(reg1)) {
         if (cPath != '') myPage=myPage+'%26cPath='+cPath;
                 }




         var p='pnxmenutest.php?page='+myPage+'&mPath='+id;
       
         document.location=p;
         
         }
      //menuDisplayFront();
      }
   }

function menuSetChoice(id) {
   var elt=document.getElementById('_menu');
   var lastChoice=elt.choice;
   

   if (lastChoice != id) {
      elt.choice=id;
      if (document.getElementById('_menuId') ) {
   	   pnxMenuUpdate();
   	   }
      menuDisplay();
      }
   }
function menuDisplay() {
    
    var elt=document.getElementById('_menu');

    var choice= elt.choice;
    var ancestors=getAncestor(choice);
    var str=menuDev(ancestors,choice,0,'');
 
    elt.innerHTML=str;
    }

function menuDisplayFront() {
    
    var elt=document.getElementById('_menu');

    var choice= currentChoice;
    var ancestors=getAncestor(choice);
    
    var str=menuDevFront(ancestors,choice,1,'&nbsp;');
 
    elt.innerHTML=str+'<br>';
    }
