$(document).ready(function(){
	
	
	
	
	
	
	$(".zayav a").click(function(){
		$.post(
			"/tpl/php/console.php?ajax=Y",
			{
				"ACTION" : "GETZAYAVFORM"
			},
			function(data){
				$("#qmes").remove();
				$("body").append('<div id="qmes">'+data+'</div>');
				first_qmes_calc();
			}
		);
		return false;
	});
	
	
	$("#taxibackform1").live("submit", function(){
		
		
		
		var params = { "ACTION" : "SENDFORM1" };
		
		$("#taxibackform1 input").each(function(k, v){
			params[$(v).attr("name")] = $(v).val();
		});
		$("#taxibackform1 textarea").each(function(k, v){
			params[$(v).attr("name")] = $(v).val();
		});
		
		$.post(
			"/tpl/php/console.php?ajax=Y",
			params,
			function(data){
				$("#qmes").remove();
				if (/\#error\#/.test(data)) {
					data = data.replace(/\#error\#/, '');
					$("body").append('<div id="qmes">'+data+'</div>');
					first_qmes_calc();
				} else {
					$("body").append('<div id="qmes">'+data+'</div>');
					first_qmes_calc();
					$("#qmes").fadeOut(10000);
					setTimeout('$("#qmes").remove();', 10000) ;
				}
			}
		);
		
		return false;
	});

	
	
	
	
	$(".close_button a").live('click', function(){
		$("#qmes").remove();
		return false;
	});

	$(window).resize(function(){
		if ($("#qmes").size()) {
			next_qmes_calc();
		}
	});
	
	$(window).scroll(function(){
		if ($("#qmes").size()) {
			next_qmes_calc();
		}
	});

	
	
	$(".backform input[name=name]").live("focus", function(){
		if ($(this).val() == "Представьтесь") $(this).val("");
	});
	$(".backform input[name=name]").live("blur", function(){
		if ($(this).val() == "") $(this).val("Представьтесь");
	});
	
	$(".backform input[name=phone]").live("focus", function(){
		if ($(this).val() == "Телефон") $(this).val("");
	});
	$(".backform input[name=phone]").live("blur", function(){
		if ($(this).val() == "") $(this).val("Телефон");
	});
	
	$(".backform input[name=date]").live("focus", function(){
		if ($(this).val() == "Дата") $(this).val("");
	});
	$(".backform input[name=date]").live("blur", function(){
		if ($(this).val() == "") $(this).val("Дата");
	});
	
	$(".backform input[name=time]").live("focus", function(){
		if ($(this).val() == "Время") $(this).val("");
	});
	$(".backform input[name=time]").live("blur", function(){
		if ($(this).val() == "") $(this).val("Время");
	});
	
	$(".backform input[name=from]").live("focus", function(){
		if ($(this).val() == "Откуда") $(this).val("");
	});
	$(".backform input[name=from]").live("blur", function(){
		if ($(this).val() == "") $(this).val("Откуда");
	});
	
	$(".backform input[name=where]").live("focus", function(){
		if ($(this).val() == "Куда") $(this).val("");
	});
	$(".backform input[name=where]").live("blur", function(){
		if ($(this).val() == "") $(this).val("Куда");
	});
	
	$(".backform input[name=price]").live("focus", function(){
		if ($(this).val() == "Желаемая сумма оплаты") $(this).val("");
	});
	$(".backform input[name=price]").live("blur", function(){
		if ($(this).val() == "") $(this).val("Желаемая сумма оплаты");
	});
	
	$(".backform textarea[name=additionally]").live("focus", function(){
		if ($(this).val() == "Дополнительная информация: наличие багажа, животных, нужно ли детское кресло") $(this).val("");
		$(this).val("")
	});
	$(".backform textarea[name=additionally]").live("blur", function(){
		if ($(this).val() == "") $(this).val("Дополнительная информация: наличие багажа, животных, нужно ли детское кресло");
	});

});

function first_qmes_calc(){
	$("#qmes").css(
		{
			"left" : ($(window).width()-$("#qmes").width())/2,
			"top" : ($(window).height() - $("#qmes").height()) / 2 + $(window).scrollTop()
		}
	);
}

function next_qmes_calc(){
	$("#qmes").stop().animate(
		{
			"left" : ($(window).width()-$("#qmes").width())/2,
			"top" : ($(window).height() - $("#qmes").height()) / 2 + $(window).scrollTop()
		},
		"slow"
	);
}


