var selectedId=null;

function initMenu(selId){
	var cerrar = 0;
	var listA=document.getElementById('menu00').getElementsByTagName('A');
	var listUL=document.getElementById('menu00').getElementsByTagName('UL');
	
	if (selId)
	{
		for(var i=0;i<listA.length;i++)
		{
			myLength = selId.length - listA[i].id.length;
												
			if((myLength != 0) && (listA[i].id.substring(0,(document.getElementById(selId).id.length-(myLength-3))) == selId.substring(0,(document.getElementById(selId).id.length - myLength))))
			{
				if (selId.substring((document.getElementById(selId).id.length - myLength),(document.getElementById(selId).id.length - myLength)+1) == "_")
				{
					listA[i].parentNode.className = 'selected';
				}
			}
			else if(listA[i].id == selId)
			{
				listA[i].parentNode.className = 'selected';
			}
			for (var x=0;x<listUL.length;x++)
			{
				if(myLength <= 0)
				{
					if(listUL[x].id.substring(0, listUL[x].id.length - 3)==listA[i].id)
					{
						if (listA[i].parentNode.className == 'hasChildren selected')
						{
							listA[i].parentNode.className = 'hasChildren';
						}
					}
					else
					{
						if (listA[i].parentNode.className == 'selected')
						{
							listA[i].parentNode.className = '';
						}
					}
				}
			}
		}
	}
	
	
	for(var i=0;i<listUL.length;i++){
		if(!selId || selId.indexOf(listUL[i].id.substring(0,(listUL[i].id.length-3)))==-1 || 
		(selId.substring(listUL[i].id.length-3,listUL[i].id.length-2) != "_" && selId.substring(listUL[i].id.length-3,listUL[i].id.length-2) != "")
		)
		{
			listUL[i].style.display='none';
			if (cerrar == 1)
			{
				if(selId == listUL[i].id.substring(0,(selId.length)))
					{
						document.getElementById(listUL[i].id.substring(0,(listUL[i].id.length-3))).parentNode.className='hasChildren';	
					}
			}	
		}else if(selId==listUL[i].id.substring(0,(listUL[i].id.length-3))){
			listUL[i].style.display=(listUL[i].style.display=='block')?'none':'block';
			
			if (listUL[i].style.display == 'none')
				cerrar = 1;
			else
				cerrar = 0;
			
			if (selId.length<listUL[i].id.substring(0,(listUL[i].id.length-3)))
			document.getElementById(listUL[i].id.substring(0,(listUL[i].id.length-3))).parentNode.className='';
			document.getElementById(selId).parentNode.className='hasChildren selected';
			
		}else{
			listUL[i].style.display='block';
			if(selId.length <= listUL[i].id.substring(0,(listUL[i].id.length-3)).length){
			document.getElementById(selId).parentNode.className='selected';
			document.getElementById(listUL[i].id.substring(0,(listUL[i].id.length-3))).parentNode.className='';
				if(selId.length != listUL[i].id.substring(0,(listUL[i].id.length-3)).length){
				document.getElementById(listUL[i].id.substring(0,(listUL[i].id.length-3))).parentNode.className='';
				}
			}else if(selId.length > listUL[i].id.substring(0,(listUL[i].id.length-3)).length){
			document.getElementById(selId).parentNode.className='selected';
			document.getElementById(listUL[i].id.substring(0,(listUL[i].id.length-3))).parentNode.className='hasChildren selected';
			}
		}
	}	
	selectedId=selId;
	return cerrar;
}

function doClick(obj, catId){
	obj.parentNode.className = 'selected';
	var opcion = null;
	opcion = initMenu(obj.id);
	if (opcion == 0)
	{
		if(catId == 0)
			return false;
		else if (catId == 1)
			return true;
	}
	else if (opcion == 1)
	{
		if(catId == 0)
			return false;
		else if (catId == 1)
			return true;
	}
}