Refactored js code and merged to the master

https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Code_formatting