/* 
 * Change city on region select.
 *
 * Requires jQuery JavaScript framework to be included (@see www.jquery.com)
 *
 * id for region select has to be 'select-region'
 * id for city select has to be 'select-city'
 */

$(function() {
	$('#select-region').change(function() {

		var region_id = $('#select-region option:selected').val();

		$.ajax({
			type: "GET",
			url: "http://" + document.domain + "/api/city.php",
			data: {
				region: region_id
			},
			dataType: "xml",
			success: function(xml) {
				$('#select-city').empty();
				$('#select-city').append('<option value="0">Alle Orte</option>');
				$(xml).find('content node').each(function() {
					var id_text = $(this).find('id').text();
					var name_text = $(this).find('name').text();

					$('<option></option>')
					.html(name_text)
					.attr('value', id_text)
					.appendTo('#select-city');
				}); // close each(
			}
		}); // close $.ajax
	}); // close change
}); // close $(

