Add ondeactivate event for using in combination with onactivate.
Code:
panel.SetPanelEvent("onactivate", ...
panel.SetPanelEvent("ondeactivate ", ...