refactored javascript to single BuildMenu()