Javascript house cleaning

Formated javascript to make source somewhat more readable, also added
some small comments.