var CountryStateOptionsServiceClient = {

  addLocationOptions: function(countrycode, selectid, selectedvalue, alloptiontext) {
    CountryStateOptionsService.getProvincesMap(countrycode, {
      callback:function(response) {
         CountryStateOptionsServiceClient._addLocationOptionsCallback(response, selectid, selectedvalue, alloptiontext);
      },
      errorHandler:function(selectid, alloptiontext) {
        CountryStateOptionsServiceClient._handleError(selectid, alloptiontext);
      }
    });
  },

  _handleError: function(id, alloptiontext) {
    dwr.util.removeAllOptions(id);
    dwr.util.addOptions(id, {' ':alloptiontext});
  },

  _addLocationOptionsCallback: function(response, id, selectedvalue, alloptiontext) {
    dwr.util.removeAllOptions(id);
    if (alloptiontext) dwr.util.addOptions(id, {' ':alloptiontext});
    dwr.util.addOptions(id, response.map, true);
    dwr.util.setValue(id, selectedvalue);
  },

  addBooksellerCountryOptions: function(languageCode, selectid, alloptiontext) {
    CountryStateOptionsService.getBooksellerCountries(languageCode, {
      callback:function(response) {
         CountryStateOptionsServiceClient._addLocationOptionsCallback(response, selectid);
      },
      errorHandler:function(selectid, alloptiontext) {
        CountryStateOptionsServiceClient.handleError(selectid, alloptiontext);
      }
    });
  }
}