$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#dae8a7"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('textarea.text-comment').css({backgroundColor:"#FFFFFF"});
  $('textarea.text-comment').focus(function(){
    $(this).css({backgroundColor:"#dae8a7"});
  });
  $('textarea.text-comment').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 email = $("input#email").val();
		if (email == "") {
		  $("label#email_error").show();
		  $("input#email").focus();
		  return false;
		}
		
		var goodEmail = email.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.co.id)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
		if (!goodEmail) {
		  $("label#email_error2").show();
		  $("input#email").focus();
		  return false;
		}
		
		var comment = $("textarea#comment").val();
		if (comment == "") {
		  $("label#comment_error").show();
		  $("textarea#comment").focus();
		  return false;
		}
		var aid = $("input#aid").val();
		
		var dataString = 'name='+ name + '&email=' + email + '&comment=' + comment + '&aid=' + aid;
		//alert (dataString);return false;
		
	  $.ajax({
      type: "POST",
      url: "include/artist_comment.php",
      data: dataString,
      success: function() {
			$('#contact_form').html("<div id='message'></div>");
			$('#message').html("<h2>Comment Has Submitted!</h2>")
			.append("<p>Thank for your comment.</p>")
			.hide()
			.fadeIn(1500, function() {
			  $('#message').append("<img id='checkmark' src='images/check.png' />");
			});
		
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
