This is just a guess because I don't really know much about Dojo...
I think putting your dojo.require() calls inside a dojo.addOnLoad() call delays them until the actual page content has finished loading.
The dijit.byId() call could be running earlier, at which point "dijit" might not have been created yet.
You could try either:
- In the javascript in the page source, move those dojo.require() outside the addOnLoad() call; or
- Instead of entering dojo.require() calls manually, add the required Dojo Modules as Resources in the xpage (or custom control) properties.