$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#ECF2F8"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#fff"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#ECF2F8"});
  });
	  $('textarea').css({backgroundColor:"#ECF2F8"});
  $('textarea').focus(function(){
    $(this).css({backgroundColor:"#fff"});
  });
  $('textarea').blur(function(){
    $(this).css({backgroundColor:"#ECF2F8"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
		
		var imie2 = $("input#imie2").val();
		if (imie2 == "") {
      $("label#imie_error2").show();
      $("input#imie2").focus();
      return false;
    }
	 
		var email2 = $("input#email2").val();
		if (email2 == "") {
      $("label#email_error2").show();
      $("input#email2").focus();
      return false;
    }
		
		var adresstrony = $("input#adresstrony").val();
		if (adresstrony == "") {
      $("label#adresstrony_error").show();
      $("input#adresstrony").focus();
      return false;
    }
	 var slowakluczowe = $("input#slowakluczowe").val();
		if (slowakluczowe == "") {
      $("label#slowakluczowe_error").show();
      $("input#slowakluczowe").focus();
      return false;
    }
		
		var dataString =  '&email2=' + email2 + '&adresstrony=' + adresstrony + '&slowakluczowe=' + slowakluczowe + '&imie2=' + imie2;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process2.php",
      data: dataString,
      success: function() {
        $('#zamow_formularz2').html("<div id='message2'></div>");
        $('#message2').html("<h2>Dziękujemy! Zgłoszenie zostało wysłane poprawnie.<br><br>W ciągu 12 godzin prześlemy pełną ofertę wraz z wyceną.</h2>")
        .append("<p></p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

