Making javascript index pages slightly less terrible

This is only a step in the right direction. If we were to use handlebars or similar the code is now easier to read .