Improving JavaScript for popup forms

These changes make the behavior and js for popup opening/closing a little more consistent.