$(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 imie1 = $("input#imie1").val();
		if (imie1 == "") {
      $("label#imie_error1").show();
      $("input#imie1").focus();
      return false;
    }
	 
		var email1 = $("input#email1").val();
		if (email1 == "") {
      $("label#email_error1").show();
      $("input#email1").focus();
      return false;
    }
		
		var wiadomosc1 = $("textarea#wiadomosc1").val();
		if (wiadomosc1 == "") {
      $("label#wiadomosc_error1").show();
      $("textarea#wiadomosc1").focus();
      return false;
    }
		
		var dataString =  '&email1=' + email1 + '&wiadomosc1=' + wiadomosc1 + '&imie1=' + imie1;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process1.php",
      data: dataString,
      success: function() {
        $('#zamow_formularz1').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();
});

