Detect if Window open

I have a page that opens a DHTMLX Window. If I then open another window from the newly opened DHTMLX Window I want the 2nd window to open from the parent page. I can accomplish this with parent.dhxWins.createWindow(… and this works perfectly.

However I want to open from the parent only if the window is being opened from another window. So how do I detect whether the call to open the window is coming from an existing DHTMLX window.

While experimenting with parent window opening using parent.dhxWins.createWindow I discovered a problem.

I open a window using dhxWins.createWindow
From this new window I open a 2nd window using parent.dhxWins.createWindow
From this 2nd window I open a 3rd window using parent.dhxWins.createWindow
The 3rd window opens behind the 2nd window and the 2nd window is now locked in position. Can no longer drag it.