More work on the templates to get the javascript stuff working smoothly between page changes.