improved js code to show menus