Event.onDOMReady(function() {
    var delegate = {
        storeLinkForStoreWithConciergeIdStateNamed: function(storeCode, stateName) {
            return 'http://www.applersvp.com/camps/jp/stores/'+storeCode;
        }
    }

    var initStoreSelector = function(requestedCountryName) {
        return (function(response) {
            var responseDocument = response.responseXML.documentElement;
            var countriesWithStores = responseDocument.getElementsByTagName('country');
            var requestedCountry = null;

            for (var i=0; i<countriesWithStores.length; i++) {
                var country = countriesWithStores[i];
                if (country.getAttribute('name') == requestedCountryName) {
                    requestedCountry = country;
                    break;
                }
            }

            new StoreSelector(requestedCountry, $('campsignup1-location'), $('campsignup1-store'), $('campsignup1-submit'), 'promo', delegate);
            new StoreSelector(requestedCountry, $('campsignup2-location'), $('campsignup2-store'), $('campsignup2-submit'), 'promo', delegate);
        });
    }

    new Ajax.Request('/jp/retail/camp/stores.xml', {
        method: 'get',
        onSuccess: initStoreSelector('Japan')
    });

});
