// JavaScript Document
$(function() {
		   $('.error_lbl').hide();
		   $('#message').hide();
		   
		   $('input.pole_tekstowe').focus(function() {
    												$(this).css({backgroundColor:"#960"});
													});
		   $('input.pole_tekstowe').blur(function() {
												  $(this).css({backgroundColor: "#630"});
												  });
		   
		   $('textarea').focus(function() {
										$(this).css({backgroundColor:"#960"});
										});
		   $('textarea').blur(function() {
									   $(this).css({backgroundColor:"#630"});
									   });
		   
		   $('.send_btn').click(function() {
									   $('.error_lbl').hide();
									   
									   var nadawca = $('input#od').val();
									   if(nadawca == "") {
										   $('label#nadawca_er').show();
										   $('input#od').focus();
										   return false;
									   }
									   
									   var mail = $('input#mail').val();
									   if(mail == "") {
										   $('label#mail_er').show();
										   $('input#mail').focus();
										   return false;
									   }
									   
									   var temat = $('input#temat').val();
									   if(temat == "") {
										   $('label#temat_er').show();
										   $('input#temat').focus();
										   return false;
									   }
									   
									   var tresc = $('textarea').val();
									   if(tresc == "") {
										   $('label#tresc_er').show();
										   $('textarea#tresc').focus();
										   return false;
									   }
									   
									   
									   var dataString = 'od=' + nadawca + '&mail=' + mail + '&temat=' + temat + '&tresc=' + tresc;
									   
									   $.ajax({
											type: "POST",
											url: "bin/mail.php",
											data: dataString,
											success: function() {
												$('#formularz').hide();
												$('#message').fadeIn("slow");
											}
										});
									   
									   return false;
									   });
		   
		   $('.clear_btn').click(function() {
										  $('.error_lbl').hide();
										  });
		   
		   $('.backForm').click(function() {
										 $('#message').hide();
										 $('#formularz').fadeIn("slow");
										 $('.error_lbl').hide();
										 });
		   });