function postCommentClose()
{$('#ddownPostComment').html('');$('#ddownPostComment').hide();}
function postCommentForm(post_id, comment_id, anchor)
{var offset=$(anchor).offset();var ddown=$('body>#ddownPostComment');var height=$(anchor).height();var top=Math.ceil(offset.top+height - (THEME_VERSION=='new_header'?0:TOP_OFFSET));var left=Math.ceil(offset.left);if (!ddown.length){ddown=$('#ddownPostComment');$('body').prepend(ddown);}
ddown.css({'left':left,'top':top,'z-index':'100'});var params=new Object;params.action='PostCommentForm';params.post_id=post_id;params.comment_id=comment_id;params.type='popup';$.post(script_url, params, function(response){postCommentFormCallback(response, post_id, comment_id)});}
function postCommentFormCallback(response, post_id, comment_id)
{$('#ddownPostComment').html(response).show();$('#ddownPostCommentText_'+post_id+'_'+comment_id).focus();}
function postCommentFormExpand(post_id, comment_id)
{var html='<div class="postCommentExpand ml30 lightgreen" id="expandPostComment_'+comment_id+'" style="display: none"></div>';$('#postCommentDiv_'+comment_id).append(html);var params=new Object;params.action='PostCommentForm';params.post_id=post_id;params.comment_id=comment_id;params.type='expand';$.post(script_url, params, function(response){postCommentFormExpandCallback(response, post_id, comment_id);});}
function postCommentFormExpandCallback(response, post_id, comment_id)
{$('#expandPostComment_'+comment_id).html(response).fadeIn();$('#ddownPostCommentText_'+post_id+'_'+comment_id).focus();}
function postComment(post_id, parent_comment_id, text, get_amount)
{var params=new Object;params.action='PostComment';params.post_id=post_id;params.parent_comment_id=parent_comment_id;params.text_comment=text;params.get_amount=(get_amount)?1:0;$.post(script_url, params, function(response){postCommentCallback(response, post_id, parent_comment_id, get_amount)});}
function _postCommentCallback(url)
{if (url=='') return;window.location.href=url;window.location.reload(true);}
function postCommentCallback(response, post_id, parent_comment_id, get_amount)
{if (get_amount)
{response=parseInt(response);$('#postCommentsLink_'+post_id+' a').html(response+' '+getCountName(response,'комментарий','комментария','комментариев'));$('#postCommentsLink_'+post_id).show();postCommentClose();}else{if (parent_comment_id)
{$('#expandPostComment_'+parent_comment_id).remove();$('#postCommentChildsDiv_'+parent_comment_id).append(response);}else{$('#postCommentFormText').val('');$('#postCommentFormSubmit')
.attr('disabled', false)
.val('Отправить');$('#postCommentForm').fadeTo(0.1, 1);$('#postCommentChildsDiv_'+post_id).append(response);}
$('#postCommentsAmount_'+post_id).show();}}
function postCommentStatus(post_id, status)
{switch (status)
{case'deleted':var confirm_text='Вы уверены, что хотите удалить свой комментарий?'
break;case'declined_by_owner':var confirm_text='Вы уверены, что хотите заблокировать этот комментарий?'
break;}
if (confirm(confirm_text))
{var params=new Object;params.action='PostCommentStatus';params.post_id=post_id;params.status=status;$.post(script_url, params, postCommentStatusCallback,'json');}}
function postCommentStatusCallback(response)
{if (response.status=='ok')
{window.location.href='#'+response.post.post_id;window.location.reload(true);}else if (response.message){alert(response.message);}}
function showCommentEdit(comment, comment_id, link)
{if (removeIfExpired(link, userMessage.editCommentExpired)) return;area_id=$(comment).attr("id")+"_edit";var text=$(comment).html();$(comment).after('<div id="'+area_id+'">'+'<textarea rows="3" class="text" style="width:95%" id="'+area_id+'">'+str_replace_reg(str_replace_reg(text,"\n",""),"<br>","\n")+'</textarea>'+'</div>');div=$("div#"+area_id);area=$("#"+area_id+"> textarea");if ($(comment).height()<=75)
$(area).height('75px');else
$(area).height($(comment).height());$(link).hide();$(link).after('<a class="mr10 grayajax" onClick="postCommentEdit(\''+area_id+'\','+comment_id+',\''+$(comment).attr("id")+'\',\''+$(link).attr("id")+'\')"><strong>Сохранить</strong></a>');$(link).after('<a class="mr10 grayajax" onClick="hideCommentEdit(\''+area_id+'\',\''+$(comment).attr("id")+'\',\''+$(link).attr("id")+'\')"><strong>Отменить</strong></a>');$(comment).hide();}
function str_replace_reg(haystack, needle, replacement){var r=new RegExp(needle,'gi');return haystack.replace(r, replacement);}
function postCommentEdit(area_id, comment_id, comment_tag_id, editlink_id)
{area=$("#"+area_id+"> textarea");if ($(area).val())
{var params=new Object;params.action='PostCommentEdit';params.post_id=comment_id;params.text_comment=$(area).val();$.post(script_url, params, function(data){postCommentEditCallback(data, area_id, comment_tag_id, editlink_id)},'json');}}
function postCommentEditCallback(result, area_id, comment_tag_id, editlink_id)
{breakTag='<br />';if (result.success=='1')
{$("#"+comment_tag_id).html($("#"+area_id+"> textarea").val().replace(/([^>]?)\n/g,'$1'+breakTag+'\n'));$("#"+comment_tag_id+"_last_modified").remove();$("#"+comment_tag_id).after(result.last_modified_tag);hideCommentEdit(area_id, comment_tag_id, editlink_id);}
else if (result.error_message)
alert(result.error_message);else
alert('Произошла ошибка при изменении комментария');}
function hideCommentEdit(area_id, comment_tag_id, editlink_id)
{$("#"+comment_tag_id).show();$("div#"+area_id).remove();$("#"+editlink_id).next().remove();$("#"+editlink_id).next().remove();$("#"+editlink_id).show();}
function loadBlockedCommentCallback(response)
{var stat=response.split(/\|\|/);if (!stat[0]) return;$("#comment_"+stat[0]).html(stat[1]);$("#load_comment_"+stat[0]).hide();$("#comment_wrap_"+stat[0]).removeClass();$("#comment_pane_"+stat[0]).show();}
function loadBlockedComment(post_id)
{var params=new Object;params.action='LoadBlockedComment';params.post_id=post_id;$.post(script_url, params, loadBlockedCommentCallback);}
function isObjectExpired(obj)
{var now=new Date;var isExpired=obj.attr("class").replace(/^.*expire(\d+).*$/,'$1') - (now.getTime() - timestamp.getTime())/1000<HTTP_REQUEST_WORSE_TIME;return isExpired;}
function removeIfExpired(obj, msg)
{if (isObjectExpired(obj))
{obj.remove();if (msg!==undefined)
alert(msg);return true;}
return false;}
function checkDeleteComment(link)
{return!removeIfExpired(link, userMessage.deleteCommentExpired)&&confirm(userMessage.deleteCommentConfirm);}
function postPostRatingCallback(response)
{var stat=response.split(/\|\|/);if (stat[0])
{if (stat[1]>0)
{var user_rating='+'+stat[1];var src=HOST_BASE+'img/goodphoto.gif';}
else if (stat[1]<0)
{var user_rating='–'+Math.abs(stat[1]);var src=HOST_BASE+'img/badphoto.gif';}
else
{var user_rating=stat[1];var src=HOST_BASE+'img/goodphoto.gif';}
if (stat[2]>0)
{var rating='(+'+stat[2]+')';var class_name='green fs90 fsi';}else if (stat[2]<0){var rating='(–'+Math.abs(stat[2])+')';var class_name='red fs90 fsi';}else if (stat[3]>0){var rating='('+stat[2]+')';var class_name='fs90 fsi';}else{var rating='('+stat[2]+')';var class_name='fs90 fsi';}
var title='Рейтинг: '+stat[2]+' (оценок пользователей: '+stat[3]+')';if (stat[1]>0||stat[1]<0)
{$("#postRatingUser_"+stat[0]).attr('title','Удалить свою оценку: '+user_rating);$("#postRatingUserImg_"+stat[0]).attr('title','Ваша оценка '+user_rating);$("#postRatingNew_"+stat[0]).hide();$("#postRatingExist_"+stat[0]).show();}else{$("#postRatingExist_"+stat[0]).hide();$("#postRatingNew_"+stat[0]).show();}
$("#postRatingValue_"+stat[0])
.html(rating)
.attr('class', class_name)
.attr('title', title);$("#postRatingUserImg_"+stat[0]).attr('src', src)
$("#postRatingCount_"+stat[0])
.html('('+stat[3]+')')
.attr('title', title);$('.postView_'+stat[0]).fadeOut();$('#postTitle_'+stat[0]).css('fontWeight','normal');}}
function postPostRating(post_id, value)
{var params=new Object;params.action='PostRating';params.post_id=post_id;params.value=value;$.post(script_url, params, postPostRatingCallback);}