/*
   Script name  : PHP and Ajax Comment
   File Name 	: script.js
   Developed By : Amit Patil (India)
   Email Id 	: amitpatil321@gmail.com
   Last Updated : 21 June 2009
   
         Have a fun with PHP.   
*/
$(document).ready(function(){
  $(".comment_table").find('textarea, input:text').blur(function () {
	if ($(this).val() != ''){
		$(this).removeClass("required");
	}
  });	
  $("#submit").click(function(){
	  var anyBlank = 0;
	  $(".comment_table").find('textarea, input:text').each(function () {
		if ($(this).val() == ''){
			$(this).addClass("required");
			anyBlank = 1;
		}
	  });	
	  if(anyBlank == "0")
	  {
		  var name    = $("#name").val();
		  
		  var comment = $("#comment").val();
		 var id = document.getElementById('pageid').value;

		  
		  $("#loading").css("visibility","visible");
			$.ajax({
			   type: "POST",
			   url: "http://www.urbanfishingshow.com/ajax_comment.php",
			   data: "name="+name+"&comment="+comment+"&id="+id,
			   success: function(date_added){
				  if(date_added != 0)
				   {
					    $("#commentform").css("visibility","hidden");
					   structure = '<div class="comment_holder">'+name+'</div><div id="comment_text"><div id="date_posted">'+date_added+'</div>'+comment+'</div></div>';				  	
					   $(".no_comments").fadeOut("slow");
					   $("#ajax_response").append(structure);
					   $(".comment_table").find('textarea, input:text').each(function () {
						   $(this).val("");
					   });
				   }
				  else
					  alert("Unexpected error...!");
  					  $("#loading").css("visibility","hidden");
			   }
			 });
	  }
  });
  $("#ajax_response").mouseover(function(){
	 $(this).find(".comment_holder").mouseover(function(){
		$(this).addClass("highlight");
	 });
  });
  $("#ajax_response").mouseout(function(){
	 $(this).find(".comment_holder").mouseout(function(){
		$(this).removeClass("highlight");
	 });
  });
});
