$(document).ready(function () {
	$('#country_id').change(function () {
		var country_id = $(this).val();
		if (country_id == '0') {
			$('#category').html('');
			$('#category').attr('disabled', true);
			return(false);
		}
		$('#category').attr('disabled', true);
		$('#category').html('<option>загрузка...</option>');

		var url = 'get_regions.php';

		$.get(
			url,
			"country_id=" + country_id,
			function (result) {
				if (result.type == 'error') {
					alert('error');
					return(false);
				}
				else {
					var options = '';
					$(result.regions).each(function() {
						options += '<option value="' + $(this).attr('id') + '">' + $(this).attr('title') + '</option>';
					});
					$('#category').html(options);
					$('#category').attr('disabled', false);
				}
			},
			"json"
		);
	});
});

$(document).ready(function () {
	$('#country_ids').change(function () {
		var country_ids = $(this).val();
		if (country_ids == '0') {
			$('#category').html('');
			$('#category').attr('disabled', true);
			return(false);
		}
		$('#category').attr('disabled', true);
		$('#category').html('<option>загрузка...</option>');

		var url = 'get_regions2.php';

		$.get(
			url,
			"country_ids=" + country_ids,
			function (result) {
				if (result.type == 'error') {
					alert('error');
					return(false);
				}
				else {
					var options = '';
					$(result.regions).each(function() {
						options += '<option value="' + $(this).attr('id') + '">' + $(this).attr('title') + '</option>';
					});
					$('#category').html(options);
					$('#category').attr('disabled', false);
				}
			},
			"json"
		);
	});
});

