Improve performance & fix .contains bug. Bug 902697.

A more comprehensive fix than PR 1141. Enables focus outside of modal check for non-Fx browsers.

Should also improve performance, as event handlers are removed when modal is closed.