There is a way to check (by using JavaScript) if the modal panel is visible or not?
simplies thing is to set some JS variable on onshow and onhide events. :)