is there some way of detecting using javascript that a user has switched to a different tab in the same browser window. 
Additionally is there a way to detect a user has switched to a different window than the browser?
thank you
Most probably there is no standards javascript for this. Some browsers might support it but normally there is only a window.onblur event to find out the user has gone away from the current window.
Detect change of browser tabs with javascript