jQuery(document).ready(function($){
	jQuery(".topicadd").click(function () {
		jQuery("#addtopic").addClass("displaynone");
		jQuery("#formtopic").removeClass("displaynone");
	});

	jQuery("#canceladd").click(function () {
		jQuery("#addtopic").removeClass("displaynone");
		jQuery("#formtopic").addClass("displaynone");
	});
	
	jQuery(".btnComment").click(function() {
		var obj = jQuery(this).parent().parent().find(".comment");
		var info = jQuery(this).attr("info");
		ShowComment(obj,info); 
		jQuery(obj).toggleClass("displaynone");
	});

	function ShowComment(obj, info) {		
		jQuery.post("./comment.ajax.php", {tbid: info} , function(data){
			jQuery("#comment"+info).find(".comment").html(data);
			
			jQuery("a.btn09").click(function() {
				var keyid = jQuery(this).parent().parent().attr("title");
				var content = jQuery(this).parent().parent().find(".ta-comment").val();
				content = content.replace(/^[\s]+/,'').replace(/[\s]+jQuery/,'').replace(/[\s]{2,}/,' ');

				if(content==''){
					alert("Please write your comment!!");
				} else {
					jQuery.post("./comment_write.ajax.php", {tbid: keyid, comment: content} , function(data){});
					ShowComment(obj,info);
				}
			});

			jQuery("a.commentDel").click(function() {
				var keyid = jQuery(this).parent().parent().attr("title");
				jQuery.post("./comment_delete.ajax.php", {tbrid: keyid}, function(data){});
				ShowComment(obj,info);
			});

		});		
	}

});