$(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 name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }

		if (/^[A-Za-z ]+$/.test(name)) {
		} else {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }

		var email = $("input#email").val();
		if (email == "" ) {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
	} else {
      $("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;
    }

		if (/\d/.test(phone)) {
		} else {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }

		var day = $("select#day").val();
		var month = $("select#month").val();
		var year = $("select#year").val();
		if (day == "") {
      return false;
    }
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&dob=' + day + ' ' + month + ', ' + year;
		//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>Thank you for your interest in Rayz. We shall soon be there to serve you.</h2>")
        .append("<p>Team Rayz Entertainment.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message');
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

