Extract in template javascript to central JS file

Moves nasty inlined javascript out of templates to a central file mangaged by
the asset pipeline.