$(function() {
  $('.error').hide();

  $("#submit_btn").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#cb_name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#cb_name").focus();
      return false;
    }
		var contact_no = $("input#cb_contact_no").val();
		if (contact_no == "") {
      $("label#contact_error").show();
      $("input#cb_contact_no").focus();
      return false;
    }
		var subject = $("input#cb_subject").val();
		if (subject == "") {
      $("label#subject_error").show();
      $("input#cb_subject").focus();
      return false;
    }
		
		var dataString = 'cb_name='+ name + '&cb_contact_no=' + contact_no + '&cb_subject=' + subject;
		//alert (dataString);return false;
		$.ajax({
      type: "POST",
      url: "includes/process.php",
      data: dataString,
      success: function() {
        $('#data').html("<div id='message'></div>");
        $('#message').html("<h2>Thank you for your request</h2>")
        .append("<p>We will be in touch very shortly.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message');
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#cb_name").select().focus();
});

