
$(function() {
  $('.error').hide();
  
  $("#loading").hide();

  $('input.text-input').css({backgroundColor:"#333"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#fff"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#fff"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
		$("#loading").show();
		
	  var firstname = $("input#firstname").val();
		if (firstname == "") {
			  $("#loading").hide();
      $("label#firstname_error").show();
      $("input#firstname").focus();
      return false;
    }
	
	var lname = $("input#lname").val();
		if (lname == "") {
			  $("#loading").hide();
      $("label#lname_error").show();
      $("input#lname").focus();
      return false;
    }
	
		var email = $("input#email").val();
		if (email == "") {
			  $("#loading").hide();
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		
	
	var message = $("input#message").val();
		if (message == "") {
			  $("#loading").hide();
      $("label#message_error").show();
      $("input#message").focus();
      return false;
    }
	
	var dataString = 'firstname='+ firstname + '&lname' + lname + '&email=' + email + '&message=' + message;
		
		$.ajax({
      type: "POST",
      url: "http://www.go-smri.com/php/process.php",
      data: dataString,
      success: function() {
  $("#loading").fadeOut(1000);
        $('#c2').html("<div id='update'></div>");
		
        $('#update').html("<p class='mainText2'>Your message was submitted to SMRI</p>")
        .hide()
        .fadeIn(500, function() {
          $('#update').append("<p class='mainText2'>We will be getting back to you soon.</p>");
		                 
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#firstname").select().focus();
});

