Agreed, we need to rethink the usage of JavaScript through out the solution and use it in a generic way.