Comet, Comet on the Wall: Fix comets sent down via AJAX from within a comet

This fixes a few issues:
 - We centralize comet command generation into `S.jsToAppend`.
 - We fix when we look up `S.jsToAppend` during AJAX processing in comet contexts so we don't miss anything that might be added during the actual AJAX function execution.
 - We make sure not to trigger a second comet request when setting up new comets client-side from within a comet response.

Fixes issue #1645 .
Eh, wrong, no, importance, minimal for expressions that are this short IMO. I can put the onload on the same line as the case statement; both of these things are pretty scannable either way.