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

    	var list = $("select#list").val();
		if (list == "Emne") {
      $("label#list_error").show();
      $("select#list").focus();
      return false;
    }
    
    
		
		var dataString = 'name='+ name + '&phone=' + phone + '&email=' + email + '&list=' + list;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div style='height:75px;' id='message'>");
        $('#message').html("<h3 style='float:left;font-size:16px;font-weight:bold;'>Din besked er sendt!</h3>")
        .append("<p style='text-align:left;float:left;'>Vi vender tilbage indenfor 48 timer..</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img style='margin-top:-15px;float:right;' id='checkmark' src='images/check.png' /></div>");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
