$(document).ready(function() {
	$('#model0').replaceWith('<select id="model0" name="model0" class="common select"></select>');
	var make = $('#make0');
	var model = $('#model0');
	var model_id = $('#model0_value_holder').val();

	model.attr('disabled', 1);
	model.change(function() {
		$('#model0_value_holder').val($(this).val());
	})

	var last_val = '';//$('#make0').val();
	make.change(function() {
			var val = make.val();
			if (val == last_val)
			{
				return;
			}
			else if (val == 'all')
			{
				model.attr('disabled', 1);
				model.html('<option>&nbsp;</option>');
			}
			else
			{
				model.attr('disabled', 1);
				model.html('<option>Betöltés...</option>');
				setTimeout(function() {
					$.get("retrieve_models.php",
						{make: val, model: model_id},
						function(data){
							model.html(data);
							model.attr('disabled', 0);
						});
					}, 50);
			}
			last_val = val;
		});
	make.change();

	$('#link_to_vehicle_detailed_car_search').click(function() {
			$('#pid').val('search');
			$('#vehicle_quicksearch').submit();
			return false;
		});
});

