I am in the process of making a drop down menu. When the toggle button is clicked, the menu is displayed and when you click away from the menu, the menu disappears and when you click the menu, your menu item is selected and the menu disappears, but... I had one small problem. When I have the menu open, I was able to click another menu and have it displayed. I didn't want more than one menu displayed at a time. As a result, I added in another for loop to my onclick event that will search for all the divs that have a menu and it will close them which works, but now if I click on a menu, the menu won't close. For some my commented out remove and add class functions are killing my list.onclick = function(). I have no idea why.

Code:
allDivs[i].onclick = function()
				{
					var divIdFull 		= document.getElementById(this.id);
					var divId 			= this.id.substr(12);
					var img 			= this.getElementsByTagName('img');
					var img 			= img[0];
					var link 			= document.getElementById('goal_icon_'		+ divId);
					var item			= document.getElementById('goal_item_'		+ divId);
					var list 			= document.getElementById('identifier_' 	+ divId);
					var uncompleted 	= document.getElementById('uncompleted_' 	+ divId);
					var on_hold 		= document.getElementById('on_hold_' 		+ divId);
					var cancelled 		= document.getElementById('cancelled_' 		+ divId);
					var completed 		= document.getElementById('completed_' 		+ divId);
					var status_input	= document.getElementById('goal_status_' 	+ divId);
					var list2 			= list.getElementsByTagName('li');
					var list_length 	= list2.length;
					
					list.onclick = function()
					{
						removeClass(divIdFull, 'hover');
						removeClass(list, 'block');
					}
					
					var allDivs2 = document.getElementsByTagName('div');
					for (var i=0; i< allDivs2.length; i++)
					{
						if (allDivs2[i].className.indexOf('goal_icon_holder') != -1)
						{
							var newdivid 		= allDivs2[i].id.substr(12);
							var link_r 			= document.getElementById('goal_icon_'		+ newdivid );
							var list_r			= document.getElementById('identifier_' 	+ newdivid );
							
							//removeClass(link_r, 'hover');
							//removeClass(list_r, 'block');
							//addClass(list_r, 'dn');
						}
					}

					if (link.className == 'goal_icon_button')
					{
						addClass(link, 'hover');
						removeClass(list, 'dn');
						addClass(list, 'block');
					}
					else
					{
						removeClass(link, 'hover');
						removeClass(list, 'block');
						addClass(list, 'dn');
					}
					
					function clickHandler(node)
					{
						 for(var i=0;i<list_length;i++)
						{
							removeClass(list2[i], 'click');
						}
						
						return true;
					}
					
					uncompleted.onclick = function()
					{	
						clickHandler();
						toggleClass(this.parentNode, 'click');
						img.src = "/assets/img/icons/process.png";
						status_input.value = 0;
						removeClass(divIdFull, 'hover');
						removeClass(list, 'block');
						return false;
					}
					
					on_hold.onclick = function()
					{	
						clickHandler();
						toggleClass(this.parentNode, 'click');
						img.src = "/assets/img/icons/process_warning.png";
						status_input.value = 1;
						return false;
					}
					
					cancelled.onclick = function()
					{	
						clickHandler();
						toggleClass(this.parentNode, 'click');
						img.src = "/assets/img/icons/process_remove.png";
						status_input.value = 2;
						return false;
					}
					
					completed.onclick = function()
					{	
						clickHandler();
						toggleClass(this.parentNode, 'click');
						img.src = "/assets/img/icons/process_accept.png";
						status_input.value = 3;
						return false;
					}
					
					return false;
				}

				var closemenu = null;

				// for each appropriate div {
					allDivs[i].onmouseover = function() { closemenu = null; };
					allDivs[i].onmouseout = function() 
					{ 
						closemenu = this; 
					};
				// }

				document.onclick = function() {
					if (closemenu != null) 
					{
						var allDivs = document.getElementsByTagName('div');
						for (var i=0; i< allDivs.length; i++)
						{
							if (allDivs[i].className.indexOf('goal_icon_holder') != -1)
							{
								var divIdFull 		= document.getElementById(allDivs[i].id);
								var divId 			= allDivs[i].id.substr(12);
								var link 			= document.getElementById('goal_icon_'		+ divId);
								var list 			= document.getElementById('identifier_' 	+ divId);
								
								removeClass(link, 'hover');
								removeClass(list, 'block');
								addClass(list, 'dn');
							}
						}
						
						// closemenu is the <div> to hide
						closemenu = null;
					}
				};