TRUNK-3818 - updated Javascript to make it a little more efficient