$(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 imie = $("input#imie").val();
		if (imie == "") {
      $("label#imie_error").show();
      $("input#imie").focus();
      return false;
    }
	 
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		
		var wiadomosc = $("textarea#wiadomosc").val();
		if (wiadomosc == "") {
      $("label#wiadomosc_error").show();
      $("textarea#wiadomosc").focus();
      return false;
    }
		
		var dataString =  '&email=' + email + '&wiadomosc=' + wiadomosc + '&imie=' + imie;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#zamow_formularz').html("<div id='message'></div>");
        $('#message').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();
});

