$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#ffff99"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#e2f0fd"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#ffff99"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var first_name = $("input#first_name").val();
		if (first_name == "") {
      $("label#first_name_error").show();
      $("input#first_name").focus();
      return false;
    }

	  var last_name = $("input#last_name").val();
		if (last_name == "") {
      $("label#last_name_error").show();
      $("input#last_name").focus();
      return false;
    }

var company = $("input#company").val();
 
	  var email = $("input#email").val();
		if (email == "") {
      $("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;
    }

  	  var address = $("input#address").val();
		if (address == "") {
      $("label#address_error").show();
      $("input#address").focus();
      return false;
    }
    
  	  var city = $("input#city").val();
		if (city == "") {
      $("label#city_error").show();
      $("input#city").focus();
      return false;
    }    

  	  var state = $("select#state").val();
		if (state == "") {
      $("label#state_error").show();
      $("select#state").focus();
      return false;
    }
    
  	  var zip = $("input#zip").val();
		if (zip == "") {
      $("label#zip_error").show();
      $("input#zip").focus();
      return false;
    }
		var dataString = 'first_name='+ first_name + '&last_name=' + last_name + '&company=' + company + '&email=' + email + '&address=' + address + '&city=' + city + '&state=' + state + '&zip=' + zip;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/INC/bin/process.php",
      data: dataString,
      success: function() {
        $('#register').html("<div id='message'></div>");
        $('#message').html("<b>Thank you for registering </b>")
        .append("<p>for more information about Inspired Magazine.<br> We will be contacting you soon. </p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#first_name").select().focus();
});

