Using the new javascript function

Had to change a few things to switch to using the new javascript stuff
Pete introduced.