// JavaScript Document
document.observe("dom:loaded", function() {
  activateCountrySelect();
  Scroller.setAll();
  new Ajax.Updater('location-select-city-holder', '/ajax/get-shop-city.php', {
				method: 'get',
				parameters: {'country': $F('location-select')},
				onComplete: function(transport){
					activateCitySelect();
				}
			});
			new Ajax.Updater('location-scroller', '/ajax/get-resellers.php', {
				method: 'get',
				parameters: {'country': $F('location-select')},
				onSuccess: function(transport){
				  //Scroller.setAll();
				},
				onComplete: function(transport){
				 if (navigator.appName=="Microsoft Internet Explorer") {
				 	Scroller.setAll();
				 }
				}
			});
});

function activateCountrySelect() {
	$('location-select').observe('change', function(event){
		if ($F('location-select') != '') {
			new Ajax.Updater('location-select-city-holder', '/ajax/get-shop-city.php', {
				method: 'get',
				parameters: {'country': $F('location-select')},
				onComplete: function(transport){
					activateCitySelect();
				}
			});
			new Ajax.Updater('location-scroller', '/ajax/get-resellers.php', {
				method: 'get',
				parameters: {'country': $F('location-select')},
				onSuccess: function(transport){
				  //Scroller.setAll();
				},
				onComplete: function(transport){
				  Scroller.setAll();
				}
			});
		} else {
			$('location-select-city-holder').innerHTML = '<br />City:<br /><select name="location-select-city" id="location-select-city" disabled="disabled"><option value="">Please select a country first</option></select>';
			new Ajax.Updater('location-scroller', '/ajax/get-resellers.php', {
				method: 'get',
				onSuccess: function(transport){
				  //Scroller.setAll();
				},
				onComplete: function(transport){
				  Scroller.setAll();
				}
			});
		}
	});
}
function activateCitySelect() {
	$('location-select-city').observe('change', function(event){
		if ($F('location-select-city') != '') {
			new Ajax.Updater('location-scroller', '/ajax/get-resellers.php', {
				method: 'get',
				parameters: {'country': $F('location-select'),'city': $F('location-select-city')},
				onSuccess: function(transport){
				 // alert(transport.responseText );
				},
				onComplete: function(transport){
				  Scroller.setAll();
				}
			});
		} else {
			new Ajax.Updater('location-scroller', '/ajax/get-resellers.php', {
				method: 'get',
				parameters: {'country': $F('location-select')},
				onSuccess: function(transport){
				 // alert(transport.responseText );
				},
				onComplete: function(transport){
				  Scroller.setAll();
				}
			});
		}
	});
	//Scroller.setAll();
}

