/* order forma */
jQuery(document).ready(function(){
	$(".order form").live("submit", function () {
		var error = 0;
		$(".order form input").each(function (i){
			if(!$(this).val()){
				$(this).parent().find("label").addClass("red");
				error = 1;
			} else {
				$(this).parent().find("label").removeClass("red");
			}
		});

		if(!error){
			$("#error").remove();
			var url = "/vodumne.p3";
			$(".order form").animate({ opacity: 0 }, 1000,  function(){
				var postdata="send=1";
				$(".order form :input").each(function (i){
					postdata = postdata+"&"+$(this).attr('id')+"="+$(this).val();
				});
/* replace questions */
				postdata = postdata.replace(/\?/g,"|Q|");
				postdata = postdata.replace(/%/g,"|perc|");
				postdata = postdata.replace(/</g,"|qo|");
				postdata = postdata.replace(/>/g,"|qc|");

//				alert(postdata);

//				$(".contacts").fadeOut(0);
				$(".order").prepend('<div class="load">&nbsp;</div>');
//				$(".order form").animate({ opacity: 1 }, 1000);
/* ajax post if succes done next */
				jQuery.ajax({
					type: "get",
					url: url,
					data: postdata,
					success: function(html){
						$(".order form :input").val("");
						$(".load").animate({ opacity: 0 }, 2000,  function(){
							$(".load").remove();
							$(".order form").animate({ opacity: 1 }, 2000,  function(){

							alert(html);
//							$(".hint").fadeOut(0);
//							$("body").animate({scrollTop: $('#sf').attr('offsetTop')}, 0);
//							$(".form > div:gt(1)").filter(".formstep").remove();

							});
						});
					}
				});
			});
		} else {
			if(!$("#error").html()){
				$(".order form ul > li:first").before('<li id="error" class="red">Заполните пожалуйста все поля формы!</li>');
			}
		}
		return false;
	});

	$(".order form #sel").live("change", function () {
		var bottle = $(this).val();
		var sum = getprice(bottle);
		$(".order span > b").html(sum);
	});
});

function getprice(cnt){
	if(cnt<=1){
		return cnt*130;
	}
	if(cnt>1 && cnt<10){
		return cnt*120;
	}
	if(cnt>=10 && cnt<=24){
		return cnt*110;
	}
	if(cnt>=25 && cnt<=34){
		return cnt*100;
	}
	if(cnt>=35){
		return cnt*90;
	}
}

