Freagarach noticed in an svn game earlier 'today', an error message can be triggered while the aiconfig page is opened.
```
ERROR: JavaScript error: gui/gamesetup/gamesetup.js line 2479
TypeError: ai is undefined
openAIConfig/<@gui/gamesetup/gamesetup.js:2479:8
updateGUIObjects@gui/gamesetup/gamesetup.js:2440:3
handlePlayerAssignmentMessage@gui/gamesetup/gamesetup.js:1698:2
g_NetMessageTypes.players@gui/gamesetup/gamesetup.js:145:20
handleNetMessages@gui/gamesetup/gamesetup.js:2115:4
onTick@gui/gamesetup/gamesetup.js:2087:3
__eventhandler18 (tick)@setupWindow tick:0:1
```
The error can be reproduced by opening the aiconfig dialog with a client, then having the host unassign the AI from that slot.
The error is caused by the behavior change in rP22676/D1684 that unified the two PopGUIPage calls - the one that does call the callback and the one that doesn't.
Now the callback is called in both cases, so `ai` will be undefined when that `PopGuiPage()` call is triggered and `g_LastViewedAIPlayer` will always be -1 when the page had been closed.
The early return in the function is added to close the page instead of showing 'no AI' data for that slot if the playercount had been reduced so that the playerslot doesnt exist anymore at the time its viewed.
The latter behavior was already present in a23b and should be fixed here as well.