$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
	
	 var title = $("input#title").val();
		if (title == "") {
      $("label#title_error").show();
      $("input#title").focus();
      return false;
    }
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var useremail = $("input#useremail").val();
		if (useremail == "") {
      $("label#useremail_error").show();
      $("input#useremail").focus();
      return false;
    }
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
	
	var hometel = $("input#hometel").val();
	
	var passport = $("input#passport").val();
	
	var ic = $("input#ic").val();
	
	var address = $("textarea#address").val();
	
			var state = $("input#state").val();
		if (state == "") {
      $("label#state_error").show();
      $("input#state").focus();
      return false;
    }
	
	var postcode = $("input#postcode").val();
	
	var country = $("input#country").val();
		if (country == "") {
      $("label#country_error").show();
      $("input#country").focus();
      return false;
    }
		var arrival = $("input#arrival").val();
		if (arrival == "") {
      $("label#arrival_error").show();
      $("input#arrival").focus();
      return false;
    }
	var departure = $("input#departure").val();
		if (departure == "") {
      $("label#departure_error").show();
      $("input#departure").focus();
      return false;
    }
		var adult = $("input#adult").val();
		if (adult == "") {
      $("label#adult_error").show();
      $("input#adult").focus();
      return false;
    }
	var child = $("input#child").val();
		if (child == "") {
      $("label#child_error").show();
      $("input#child").focus();
      return false;
    }
	
	var notes = $("textarea#notes").val();
		
		var dataString = 'title='+ title + '&name='+ name + '&useremail=' + useremail + '&phone=' + phone + '&hometel=' + hometel + '&passport=' + passport + '&ic=' + ic + '&address=' + address + '&state=' + state +  '&postcode=' + postcode + '&country=' + country + '&arrival=' + arrival + '&departure=' + departure + '&adult=' + adult + '&child=' + child + '&notes=' + notes;
		//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>Request Form Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

