Working document object in JS UI code