Moved document.ready otherwise global.rapi is not available.
Changed global.rapi to global.app.rapi