<?php
function makeMenu($arrMenu,$nivel="1"){
	$menu.="";
	$numMen=0;
	foreach($arrMenu as $nom=>$val){
		$numMen++;
		$auxArrMenu=$arrMenu[$nom];
		if(is_string($val)){
			$auxVal=explode("|",$val);
			$menu.=getOptionMenu(strtoupper($nom),"$nivel"."_"."$numMen",$auxVal[0],$auxVal[1])."\n";
		}elseif(is_array($val)){
			//Se Verifica si Se Contiene Configuracion de Menu
			if(isset($val['setupMenu'])){
				$auxSetup=explode("|",$val['setupMenu']);
				$action=$auxSetup[0];
				$target=$auxSetup[1];
				$showSubMenu=$auxSetup[2];//1:SI,0:NO
				unset($val['setupMenu']);
				$opened=$auxSetup[3];
				if($action!="")
					$class="a2e";
			}else{
				$action="";
				$target="";
				$class="a2";
				$showSubMenu=1;
				$opened=false;
			}
					
			$menu.=getTitleMenu(strtoupper($nom),"$nivel"."_"."$numMen",$showSubMenu,$opened,$action,$target,$class)."\n";
			$menu.=startMenu("$nivel"."_"."$numMen",$opened)."\n";
			//Llamada Recursiva para Submenus, Verifica si Debe Mostrarlo o No
			if($showSubMenu) $menu.=makeMenu($val,"$nivel"."_"."$numMen");
			$menu.=endMenu()."\n";
		}	
	}
	return $menu;
}

function getOptionMenu($label,$id,$action,$target){
	return "<div id=\"opcion_$id\"><a href=\"$action\" target=\"$target\">$label</a></div>";
}

function getTitleMenu($label,$id,$canOpen=true,$opened=false,$action="",$target="",$class="a2"){
	if(strcmp(trim($action),"")!=0){
		//$extraOptions="href=\"$action\" target=\"$target\"";
		$extraOptions="onClick=\"loadFrame('$action','$target');\"";
	}
	if($canOpen)
		$extraOptions .=" onClick=\"openCloseMenu('menu_$id','imgMenu_$id');\"";
	if(!$opened)
		$srcImg="img/ABRIR.png";
	else
		$srcImg="img/CERRAR.png";	
	return "<div id=\"titleMenu_$id\" name=\"titleMenu\"> <a  class=\"$class\" $extraOptions><img src=\"$srcImg\" alt=\"\" id=\"imgMenu_$id\" border=\"0\"/>$label</a></div>";
}
function startMenu($id,$opened=false){
	if(!$opened)
		return " <div id=\"menu_$id\" class=\"menuClose\">";
	else
		return " <div id=\"menu_$id\" class=\"menuOpen\">";	
}
function endMenu(){
	return "</div>";
}
?>