/* Copyright 2009 Palm, Inc.  All rights reserved. */

var AccountsMojoService = Class.create( {
  initialize: function() {
  },
  
  getAllAccountsForCalendarService: function(callback, sceneController, subscribeParam) {
		
		var subscribe = true;
		if (subscribeParam != undefined) {
			subscribe = subscribeParam;
		}
		if(Mojo.Host.current === Mojo.Host.mojoHost) {
			// Mock service response... simulate failure.
			return;
		}
				
		if (sceneController == undefined) {
			return new Mojo.Service.Request(AccountsMojoService.identifier, {
				method: 'getAllAccountsForService',
				parameters: {
					service: AccountsMojoService.CALENDAR,
					includeName: true,
					subscribe: subscribe
				},
				onSuccess: callback
			});
		} else {
			return sceneController.serviceRequest(AccountsMojoService.identifier, {
				method: 'getAllAccountsForService',
				parameters: {
					service: AccountsMojoService.CALENDAR,
					includeHidden: true,
					subscribe: subscribe
				},
				onSuccess: callback
			});
		}
  },
  
	getAllAccountTypesForService: function(callback, sceneController) {
		if (sceneController == undefined) {
			return new Mojo.Service.Request(AccountsMojoService.identifier, {
	      method: 'getAllAccountTypesForService',
				parameters: {service: AccountsMojoService.CALENDAR, subscribe: true},
				onSuccess: callback
	    });
		} else {
			return sceneController.serviceRequest(AccountsMojoService.identifier, {
	      method: 'getAllAccountTypesForService',
				parameters: {service: AccountsMojoService.CALENDAR, subscribe: true},
				onSuccess: callback
	    });
		}
	},
	
	removeService: function(sceneController, accountId, callback) {
		return sceneController.serviceRequest(AccountsMojoService.identifier, {
	      method: 'removeService',
				parameters: {accountId: accountId, service: AccountsMojoService.CALENDAR},
				onSuccess: callback,
				onfailure: callback
	  });
	}
});

AccountsMojoService.identifier = 'palm://com.palm.accounts';
AccountsMojoService.CALENDAR = "CALENDAR";	// Do NOT Localize
