function addCommentForm(parent)
{
	$('#answer_div').remove();
		template="<div id='answer_div'><textarea id='answer_field' rows='3' cols='50'></textarea><br><input type='button' value='написать' id='answer_button' onclick='postComment("+parent+")'></div>";
	$("#comment"+parent).append(template);
	//$("#comment"+parent).remove();
	/*$(this).click(function(i){
						 
							 });*/

}

function postComment(parent)
{
document.getElementById("answer_button").disabled="false";
//alert($("#type_val").val());
jQuery.get('work.php',{type:$("#type_val").val(),action:"add_comment",page_id:$("#comment_page").val(),parent:parent,comment:$("#answer_field").val()}, function(ans) {
	    var a=ans;
		$("#comment"+parent).append("<i><b>Я: </b>"+$("#answer_field").val()+"</i>");
		$('#answer_div').remove();
		
		},'text');		
}

function editComment(id)
{
	text=$("#comment"+id).find(".comment_text").html();
	$("#comment"+id).find("td").eq(0).append("<br><textarea id='edit"+id+"' cols='45' rows='5'>"+text+"</textarea><br><input type='button' value='Сохранить' onClick='saveComment("+id+")'>");
	$("#comment"+id).find(".comment_text").remove();
}

function saveComment(id)
{
	jQuery.get('work.php',{id:id,action:"edit_comment",comment:$("#edit"+id).val()}, function(ans) {
	    var a=ans;
			$("#comment"+id).find("td").eq(0).append("<p class='comment_text'>"+$("#edit"+id).val()+"</p>");
			$("#comment"+id).find("td").eq(0).find("input[type=button]").remove();
			$("#comment"+id).find("#edit"+id).remove();
		},'text');	
}

function deleteComment(id)
{
	jQuery.get('work.php',{id:id,action:"delete_comment"}, function(ans) {
	    var a=ans;
			$("#comment"+id).find(".comment_text").html("<i>Комментарий был удален</i>");
		},'text');	
}
