var comment_imgs = {
add: '/i/btn_send.gif',
edit: '/i/btn_save.gif',
answer: '/i/btn_answer.gif'
};

function createEditor(html){
    $('#cmt_body').val(html);
}
function edit(id)
{
header.html(((id > 0) ? 'Редактировать комментарий': 'Добавить комментарий'));
$('input#comment_add').attr('src', comment_imgs['edit']);
$('div#comment_user').css('display', 'none');
$('input#cid').val(id);
$('input#pid').val(0);
var cont = $('#cmt' + id) . html();
cont = strip_tags(cont,'<a>');
upForm(id);
createEditor(cont)
return false;
}

function all_cmt(uid)
{
	$('.comment.uid' + uid).toggleClass('border');
	return false;
}

function quote(id)
{
header.html('Ответить на комментарий');
$('input#comment_add').attr('src', comment_imgs['answer']);
$('div#comment_user').css('display', '');
var cont = "[b][user=" + $('#Com_' + id + ' span.author a').attr('href') + "]" + $('#Com_' + id + ' span.author a').text() + '[/user] пишет ' + $('#Com_' + id + ' span.date').text() + "[/b]";
cont = cont + "[qt]" + $('#cmt' + id).text() + "[/qt]";
upForm(id);
createEditor(cont)
$('input#cid').val(0);
$('input#pid').val(0);
return false;
}

function answer(id)
{
header.html('Ответить на комментарий');
$('input#comment_add').attr('src', comment_imgs['answer']);
$('div#comment_user').css('display', '');
upForm(id);
createEditor("")
$('input#cid').val(0);
$('input#pid').val(id);
return false;
}


function upForm(id){
if( id != 0 ) $("#Com_0 center").show();
else {
$("#Com_0 center").hide();
$('input#comment_add').attr('src', comment_imgs['add']);
}
$("#FCed"). appendTo($("#Com_" + id));
}

var url_hash = window.location.hash;
$(document).ready(function() {
    if(/^#cmt[\d]+/.test(url_hash)){
        $('#See_ComHidden').hide();
        $('#ComHidden').show();
        location.href = url_hash;
    }
})

$(function(){
	
    $('.comment .ans .goto').click(function() {
		var pid = $(this).attr('href').substring(1);
		if ($('#ComHidden #cmt' + pid).length > 0)
		{
			$('#See_ComHidden').remove();
			$('#ComHidden').show();
		}
	});

});
