load_models = function () {
	$("#h_loader").html('<img src="/images/loader_ajax.gif">');
	$.ajax({
		type: "POST",
		url: "/menu.php",
		data: "vendor="+$('select[name="ajax_vendor"]').val()+'&ajax_n=1',
		dataType: "html",
		timeout: 30000,
		success: function (data) {
			$('#i_models').html(data);
			$('#big_madd').css('background', 'url(/images/cars/'+$('select[name="ajax_vendor"]').val()+') no-repeat 100% 0%');
			$("#h_loader").html('<img src="/images/loader_white.gif">');
		},
		error: function () {
			$("#h_loader").html('<img src="/images/loader_white.gif">');
		}
	});
	
	return false;
};

load_models_2 = function () {
	$("#i_loader_2").html('<img src="/images/loader_ajax.gif">');
	$.ajax({
		type: "POST",
		url: "/menu.php",
		data: "vendor="+$('select[name="ajax_vendor_2"]').val()+'&ajax_n=2',
		dataType: "html",
		timeout: 30000,
		success: function (data) {
			$('#i_models_2').html(data);
			$("#i_loader_2").html('<img src="/images/loader_white.gif">');
		},
		error: function () {
			$("#i_loader_2").html('<img src="/images/loader_white.gif">');
		}
	});
	
	return false;
};

load_models_3 = function () {
	$("#i_loader_3").html('<img src="/images/loader_ajax.gif">');
	$.ajax({
		type: "POST",
		url: "/menu.php",
		data: "vendor="+$('select[name="ajax_vendor_3"]').val()+'&ajax_n=3',
		dataType: "html",
		timeout: 30000,
		success: function (data) {
			$('#i_models_3').html(data);
			$("#i_loader_3").html('<img src="/images/loader_white.gif">');
		},
		error: function () {
			$("#i_loader_3").html('<img src="/images/loader_white.gif">');
		}
	});
	
	return false;
};

load_cars_2 = function () {
	$("#i_loader_2").html('<img src="/images/loader_ajax.gif">');
	$.ajax({
		type: "POST",
		url: "/cars_select.php",
		data: "vendor="+$('select[name="ajax_vendor_2"]').val()+"&model="+$('select[name="ajax_model_2"]').val()+'&ajax_n=2',
		dataType: "html",
		timeout: 30000,
		success: function (data) {
			$('#i_cars_2').html(data);
			$("#i_loader_2").html('<img src="/images/loader_white.gif">');
		},
		error: function () {
			$("#i_loader_2").html('<img src="/images/loader_white.gif">');
		}
	});
	
	return false;
};

load_cars_3 = function () {
	$("#i_loader_3").html('<img src="/images/loader_ajax.gif">');
	$.ajax({
		type: "POST",
		url: "/cars_select.php",
		data: "vendor="+$('select[name="ajax_vendor_3"]').val()+"&model="+$('select[name="ajax_model_3"]').val()+'&ajax_n=3',
		dataType: "html",
		timeout: 30000,
		success: function (data) {
			$('#i_cars_3').html(data);
			$("#i_loader_3").html('<img src="/images/loader_white.gif">');
		},
		error: function () {
			$("#i_loader_3").html('<img src="/images/loader_white.gif">');
		}
	});
	
	return false;
};

in_selected = function (ben) {
	$("#i_sel_"+ben).html(
		$('select[name="ajax_cars_'+ben+'"]').find('option:selected').text()
	);
	
	return false;
};

check_form_valid = function () {
	if ($('input[name="c_email"]').val() == '') {
		alert ('Вы забыли указать E-mail!');
		return false;
	} else if ($('textarea[name="c_message"]').val() == '') {
		alert ('Вы забыли написать сообщение!');
		return false;
	} else if ($('input[name="c_defense"]').val() == '') {
		alert ('Вы не ввели защитный код!');
		return false;
	} else {
		$("#form_loader").html('<img src="/images/loader_ajax.gif">');
		var info_str = '123';
		$.ajax({
			type: "POST",
			url: "/contact_redirect.php",
			data: "c_email="+$('input[name="c_email"]').val()+"&c_message="+$('textarea[name="c_message"]').val()+'&c_defense='+$('input[name="c_defense"]').val()+'&c_ajax=1',
			dataType: "html",
			timeout: 30000,
			success: function (data) {
				if (data == 'email') info_str = 'Не правильный E-mail!';
				else if (data == 'message') info_str = 'Не ввели сообщение!';
				else if (data == 'defense') info_str = 'Не ввели защитный код!';
				else if (data == 'error') info_str = 'Отправить сообщение не удалось!';
				else if (data == 'ok') info_str = 'Сообщение отправлено!';
				
				$("#form_loader").html('<img src="/images/loader_white.gif"> '+info_str);
			},
			error: function () {
				$("#form_loader").html('<img src="/images/loader_white.gif">');
			}
		});
		return false;
	}
};
