/*
$(document).ready(function(){
	 starter = '<div class="gb_head">'+
					'&nbsp;'+
				'</div>'+
				'<div class="gb_mida">'+
					'<div class="gb_middle">'+
						'&nbsp;'+
					'</div>';
	 ender = 	'</div>'+
	         	'<div class="gb_bottom">'+
	         		'&nbsp;'+
	         	'</div>';
		$("#wrap_img").before(starter);
		$("#wrap_img").after(ender);
		$("#wrap_img").wrap("<div>");
		$("#wrap_img").parent().addClass("bg_sitez");
		divan = $(".bg_sitez").html();
		$(".bg_sitez").empty();
		$(".gb_middle").after(divan);		
});
*/

function show_discount(){
	$('.discount_modal').show();
	$("input#name").select().focus();
}
function hide_discount(){
	$('.discount_modal').hide();
}
/*
function submit_discount(){
	$.ajax({
	  type: "POST",
	  url: "ajax.php",
	  data: "name=John&location=Boston"
	}).done(function( msg ) {
	  //alert( "Data Saved: " + msg );
	});
}
*/
	var wtfvar = 0 ;
$(function() {
  $('.error').hide();
  $('#discount_form input').css({backgroundColor:"#FFFFFF"});
  $('#discount_form input').focus(function(){
    $(this).css({backgroundColor:"#eff5f8"});
  });
  $('#discount_form input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".discount_m_btn").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
		
		var dataString = 'act=discount&name='+ name + '&email=' + email + '&phone=' + phone;
		//alert (dataString);return false;
		$('#discount_message').html("");
        $('#discount_message').append("<img id='checkmark' src='/img/loadingAnimation.gif' />");
if (wtfvar==0){
	wtfvar=1;
	$.ajax({
      type: "POST",
      url: "/form.php",
      data: dataString,
      success: function() {
        $('#discount_message').html("<h2>Сообщение отправлено!</h2>")
        .append("<p>Мы скоро с вами свяжемся.</p>");
        $('.discount_m_btn').remove();
      }
     });
 }
    return false;
	});
});




var check_ban = 0;
var seen_ban = 0;
$(function(){
	$('.top_line').bind('mouseenter mouseleave', function() {
		if(check_ban>2 && seen_ban==0){
			seen_ban = 1;
	  		show_discount();
			check_ban++;
	  		return false;
	  	}
		check_ban++;
	});
});
