$(function() {
  $('.error').hide();
  $('.text-input').css({backgroundColor:"#FFFFFF"});
  $('.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  
  $('input.date-pick').css({backgroundColor:"#FFFFFF"});
  $('input.date-pick').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.date-pick').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  
  

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
	
		var przyjazd = $("input#przyjazd").val();
		if (przyjazd == "") {
      $("label#przyjazd_error").show();
      $("input#przyjazd").focus();
      return false;
    }
	
		var wyjazd = $("input#wyjazd").val();
		if (wyjazd == "") {
      $("label#wyjazd_error").show();
      $("input#wyjazd").focus();
      return false;
    }
	
	var room = $("select#room").val();
		if (room == "---choose---") {
      $("label#room_error").show();
      $("select#room").focus();
      return false;
    }
	
		
	  var nazwisko = $("input#nazwisko").val();
		if (nazwisko == "") {
      $("label#nazwisko_error").show();
      $("input#nazwisko").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 = 'nazwisko=' + nazwisko + '&room=' + room + '&email=' + email + '&phone=' + phone + '&przyjazd=' + przyjazd + '&wyjazd=' + wyjazd;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Reservations made successfully.</h2>")
        .append("<p>Reception worker will call you soon and it will confirm the reservation.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#przyjazd").select().focus();
});

