$(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 friendName = $("input#txtFriendName").val();
		if (friendName == "") {
      $("label#friend_name_error").show();
      $("input#txtFriendName").focus();
      return false;
    }
		var friendEmail = $("input#txtFriendEmail").val();
		if (friendEmail == "") {
      $("label#friend_email_error").show();
      $("input#txtFriendEmail").focus();
      return false;
    }
	
	 var yourName = $("input#txtYourName").val();
		if (yourName == "") {
      $("label#your_name_error").show();
      $("input#txtYourName").focus();
      return false;
    }
		var yourEmail = $("input#txtYourEmail").val();
		if (yourEmail == "") {
      $("label#your_email_error").show();
      $("input#txtYourEmail").focus();
      return false;
    }
	
	var message = $("textarea#txtMessage").val();
	
	var productUrl = $("input#productUrl").val();
		
		var dataString = 'txtFriendName='+ friendName + '&txtFriendEmail=' + friendEmail + '&txtYourName=' + yourName
			+ '&txtYourEmail=' + yourEmail + '&txtMessage=' + message + '&productUrl=' + productUrl;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "sendproductemail.aspx",
      data: dataString,
      success: function() {
		/*
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>The product has ben sent!</h2>")
        //.append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          //$('#message').append("<img id='checkmark' src='images/check.png' />");
        });
		*/
      }
     });
	 
	 //$('#contact_form').append("<div id='message'></div>");
        $('#message').html("<h2>The product has ben sent!</h2>")
        //.append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          //$('#message').append("<img id='checkmark' src='images/check.png' />");
        });
	 
	
    return false;
	});
});

/*
runOnLoad(function(){
  $("input#name").select().focus();
});
*/
