function LoadFormComment(id,d) {
	if (d) {
		$('div#show-comment').empty().html('<img src="/js/ajloadline.gif" align="absmiddle" width="220" height="19" border="0" alt="Выполнение команды">');
		$.get('/index.php',{'c': 'comments', 'm': 'form_comment','id': id, 'rnd': Math.random()}, function(data) { $('div#show-comment').empty().append(data); });
	} else {
		$('div#show-comment').empty().html('<h5 class="title-05"><div class="commbgr"><a href="javascript:void(0);" onclick="LoadFormComment('+id+',true);"><img id="search_roll_img" width="16" height="16" border="0" align="absmiddle" src="/js/box_down.gif"> /Развернуть <b>добавить новый комментарий</b>&hellip;</a></div></h5>');
	}
}
function insertext(open, close, area){
    if(area=="short"){msgfield = document.addnews.body; }

    // IE support
    if (document.selection && document.selection.createRange){
        msgfield.focus();
        sel = document.selection.createRange();
        sel.text = open + sel.text + close;
        msgfield.focus();
    }

    // Moz support
    else if (msgfield.selectionStart || msgfield.selectionStart == "0"){
        var startPos = msgfield.selectionStart;
        var endPos = msgfield.selectionEnd;

        msgfield.value = msgfield.value.substring(0, startPos) + open + msgfield.value.substring(startPos, endPos) + close + msgfield.value.substring(endPos, msgfield.value.length);
        msgfield.selectionStart = msgfield.selectionEnd = endPos + open.length + close.length;
        msgfield.focus();
    }

    // Fallback support for other browsers
    else {
        msgfield.value += open + close;
        msgfield.focus();
    }

    return;
}
function QuoteComment(cid,art_id) {
	var is_form = $('*').is('#txtareabody');
	if (is_form) { } else { alert('Необходимо сначала кликнуть на "Развернуть добавить новый комментарий"'); }

	var bodytxt = $('#comment-body-'+cid).html();
	var autor = $('#comment-autor-'+cid).html();
	bodytxt = bodytxt.replace(/<span class\=\"quote\">Цитирую <span class\=\"comment-author\">([^\:]*)\:<\/span><\/span><blockquote>/g,"[quote name=\"$1\"]");
	bodytxt = bodytxt.replace(/<\/blockquote>/g,"[/quote]");
	bodytxt = bodytxt.replace(/\n/g,"");
	bodytxt = bodytxt.replace(/<br ?\/?>/gi,"\n");
	bodytxt = bodytxt.replace(/<img src\=\"\/images\/smilies\/([^\.]+)\.gif\" width\=\"[\d]{2}\" height\=\"[\d]{2}\" border=\"0\">/gi, function (indx,sos) {
		var sootv = {'ab' : ':-)','ac' : ':-(','ad' : ';-)','ap' : '{*JOKINGLY*}','ag' : '{*CMEX*}','ae' : ':-P','af' : '8-)','ai' : '-=O','ah' : ':-[','ak' : ':\'(','am' : '{*BAD*}','an' : ':-|','ao' : '{*WRONG*}','at' : ':-x','bd' : '{*ZLOY*}','py' : '{*PARTY*}'};
		return sootv[sos]; });
	bodytxt = bodytxt.replace(/<a href\=\"http:\/\/([^\"]+)\" target\=\"_blank\">[^<]+<\/a>/g,"[url=http://$1]");
	insss = '[quote name="'+autor+'"]'+bodytxt+'[/quote]';
	insertext(insss,'','short');
}
function SaveFormComment() {
	var indates = new Object();
	indates.body = $('#txtareabody').val();
	indates.name = $("input[name=name]").attr("value");
	indates.email= $("input[name=email]").attr("value");
	indates.article= $("input[name=article]").attr("value");
	var fidname = $("input#fhidden").attr("name");
	indates[fidname] = $("input#fhidden").attr("value");
	indates.rnd = Math.random();
	$('div#show-comment').empty().html('<img src="/js/ajloadline.gif" width="220" height="19" border="0" alt="Выполнение команды">');
	$.post('/index.php?c=comments&m=add_comment',indates,
			function(data) {
				$('div#show-comment').empty().html('<h5 class="title-05"><div class="commbgr"><a href="javascript:void(0);" onclick="LoadFormComment('+indates.article+',true);"><img id="search_roll_img" width="16" height="16" border="0" align="absmiddle" src="/js/box_down.gif"> /Развернуть <b>добавить новый комментарий</b>&hellip;</a></div></h5>');
				$('div#comments').empty().append(data);
			});
}
