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

  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('textarea.text-input').focus(function(){
    $(this).css({backgroundColor:"#D9ECFF"});
  });
   $('textarea.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var title = $("input#title").val();
		if (title == "") {
      $("label#title_error").show();
      $("input#title").focus();
      return false;
    }
		var subject = $("textarea#subject").val();
		if (subject == "") {
      $("label#subject_error").show();
      $("textarea#subject").focus();
      return false;
    }
	var id_sender = $("input#id_sender").val();
	var id_to = $("input#id_to").val();
	var to_email = $("input#to_email").val();
	var id_product = $("input#id_product").val();
		
		
var dataString = 'title='+ title + '&subject=' + subject + '&id_sender=' + id_sender + '&id_to=' + id_to + '&to_email=' + to_email + '&id_product=' + id_product ;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "pages/send_message.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2></h2>")

        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#title").select().focus();
});

