This code is in global scope, which is a very bad idea. 

Put js into an app namespace so that the code you write does not have an opportunity to conflict with other js.