Move most javascript from html templates to separate static js.

Change-Id: I91bc824911ec61949e63113168b056337fa933a1