$(function() {
  $('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_orange#submit_btn").click(function() {
	// validate
		
	  	var name = $("input#name").val();
		if (name == "") {
      	$("input#name").focus();
      	return false;
    }

		var strValue  = $("input#email").val();
		var strFilter = /^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i;
		if (!strFilter.test(strValue ))
		{
      	$("input#email").focus();
      	return false;
    }
	// not validated
		var phone = $("input#phone").val();
		var details = $("textarea#details").val();
		var page = $("input#page").val();
	
			
		var dataString = $("#form").serialize();
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "http://www.hearthstonecommunities.com/forms/emailcontactsend-hob.php",
      data: dataString,
      success: function() {
        $('#form').html("<div id='message'></div>");
        $('#message').html("<h2>Thank you for contacting us.</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

