get rid of globals and combine javascript into a single place
fixes issue #2865