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

