switched to document.hasFocus() for detecting the active window