re-factor js script to works with cordova 3.0.0
separate callbacks for background and foreground