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

  	$(".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").css({backgroundColor:"#d92027"});
			$("input#name").css({color:"#fff"});
      		$("input#name").focus();
      		return false;
    	}
		var phone = $("input#phone").val();
			if (phone == "") {
      			$("label#phone_error").show();
				$("input#phone").css({backgroundColor:"#d92027"});
				$("input#phone").css({color:"#fff"});
      			$("input#phone").focus();
      			return false;
    		}
		var email = $("input#email").val();
			if (email == "") {
		  		$("label#email_error").show();
				$("input#email").css({backgroundColor:"#d92027"});
				$("input#email").css({color:"#fff"});
		  		$("input#email").focus();
		  		return false;
			}
		var company = $("input#company").val();
		var message = $("textarea#message").val();
		
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&company=' + company + '&message=' + message;
		//alert (dataString);return false;
		
		$.ajax({
			type: "POST",
			url: "bin/process_index.php",
			data: dataString,
			success: function() {
			/*	$('#contact_form').html("<div id='message'></div>");
				$('#message').html("<h2>Tack f&ouml;r din intresseanm&auml;lan!</h2>")
				.append("<p>Vi h&ouml;r av oss inom kort.</p>")
				.hide()
				.fadeIn(1500, function() {
					$('#message').append("<img id='checkmark' src='images/check.png' />");
				});
			*/      
			window.location.href = "http://www.unikgrafik.se/index-tack.html";
			}
     	});
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
