PhoneGap tutorial code, with my modification (add and modify some functions)