document.observe("dom:loaded", function() {

	$('profile_select_country').observe('change', function(event) {
		var element = event.element();

		if (element.options[element.selectedIndex].value) {

			new Ajax.Request($('profile_register_field_sid').getValue(), {
				method: 'post',
				parameters: {
					country_id: element.options[element.selectedIndex].value
				},
				onSuccess: function(transport) {
					var json = transport.responseText.evalJSON();
					var i = 0;
                    $('profile_select_city').options.length = 0;
					for (k in json) {
						$('profile_select_city').options[i] = new Option(json[k], k);
						i++;
					}
				}
			});
		}
	});

});

