mv topics variable definition up to top of <script> tag

for readability
made tagmanager/typeahead functions work with any term field

This is in preparation to converting entity.facility field to
use tagmanager/typeahead.
use tagmanager/typeahead for entity.facility field
first draft of tagmngr prep func that preserves legacy terms