Move more javascript out of the templates