function go_to(url)
{
	if(url)
		location.href=url;
	else
		location.refresh();
}
function add_comment(id,by)
{
	var msg;
	msg=$("#new_comment").val();
	//msg=tinyMCE.get('new_comment').getBody().innerHTML;
	if(msg)
	{
		$.post("/ajax/ajaxComments.php",{mode:"comments_timeout"},function(comments_timeout)
														{
															if(comments_timeout=="0")
		$.post(
			   	"/ajax/ajaxComments.php",
				{
					mode:"add_comment",
					mode_2:"new",
					id:id,
					by:by,
					comment:enter_to_br(msg)
				},
				function(data)
				{
					go_to(data);
				}
			   )
															else
															{
																$('#comments_error').html("Вы сможете добавить следующий комментарий через "+comments_timeout+" сек");
																go_to(window.location+"#comments");
															}
															 })
	}
	else
	{
		$.post("/ajax/ajaxComments.php",{mode:"verify"},function(data){
																 if(data=="1")
																	$('#comments_error').html("Введите текст комментария");
																else
																	$('#comments_error').html("Вы не авторизованы. Для добавления комментария <a href='/people_test/index.php' style='color:#F00'><u>войдите</u></a>, пожалуйста, в сообщество");
																 })
	}
	//alert(enter_to_br(msg));
}
function delete_comment(id,mode_2)
{
	if(confirm("Удалить комментарий?"))
	{
		$.post("/ajax/ajaxComments.php",{mode:"delete_comment",id:id},function(){
															  $("#comment"+mode_2+id).html("Комментарий удален");
															  })
	}
}
function edit_comment(id)
{
	var msg,edit,buff;
	msg=$('#comment_area'+id).html();
	//msg=tinyMCE.get('comment_area'+id).getBody().innerHTML;
	//alert(msg);
	$('#comment_area'+id).html("<textarea style='width:600px;height:400px' id='textarea_buff"+id+"' name='textarea_buff"+id+"'>"+enter_to_br(msg)+"</textarea>");
	$('#editing_edit'+id).css('display','none');
	$('#editing_save'+id).css('display','');
	//tinyMCE.execCommand('mceToggleEditor',true,'textarea_buff'+id);
}
function send_editted_comment(id)
{
	var msg,preg;
	msg=$('#textarea_buff'+id).val();
	//msg=tinyMCE.get('textarea_buff'+id).getBody().innerHTML;
	if(msg)
	$.post("/ajax/ajaxComments.php",{mode:"edit_comment",id:id,comment:enter_to_br(msg)},
		   function(){
			   $('#comment_area'+id).html(enter_to_br(msg));
			   $('#editing_edit'+id).css('display','');
			   $('#editing_save'+id).css('display','none');
			   })

}
function answer_show(id)
{
	if(id)
	{
		$('#show_answer'+id).css('display','none');
		$('#hidden_answer'+id).css('display','');
		//tinyMCE.execCommand('mceToggleEditor',false,'answer'+id);
		//tinyMCE.execCommand('mceToggleEditor',true,'answer'+id);
	}
}
function answer_post(id)
{
	var msg;
	msg=$("#answer"+id).val();
	//msg=tinyMCE.get('answer'+id).getBody().innerHTML;
	if(msg)
	{
		$.post("/ajax/ajaxComments.php",{mode:"comments_timeout"},function(comments_timeout)
															 {
																if(comments_timeout=="0")
		$.post(
			   	"/ajax/ajaxComments.php",
				{
					mode:"add_comment",
					mode_2:"answer",
					id:id,
					comment:msg
				},
				function(data)
				{
					$('#show_answer'+id).css('display','');
					$('#hidden_answer'+id).css('display','none');
					go_to(data);
				}
			   )
		else
		{
			$('#comments_error').html("Вы сможете добавить следующий комментарий через "+comments_timeout+" сек");
			go_to(window.location+"#comments");
		}
															 })
	}
	else
	{
		$.post("/ajax/ajaxComments.php",{mode:"verify"},function(data){
																 if(data=="1")
																	$('#comments_error').html("Введите текст комментария");
																else
																	$('#comments_error').html("Вы не авторизованы. Для добавления комментария <a href='/people_test/index.php' style='color:#F00'><u>войдите</u></a>, пожалуйста, в сообщество");
																 })
	}
}
function enter_to_br(msg)
{
	var preg;
	preg=/\n|(<BR>)|(<br>)/g;
	return msg.replace(preg,'<br />');
}
