﻿function deleteComment(obj) {
    if (!confirm('Комментарий со всеми ответами на него будет удален.')) return false;
    exec(obj.id);
}

function exec(id) {
    $.ajax({
        type: "POST",
        url: $("#hAjaxUrl").val(),
        data: "{id : '" + id + "', aId : '" + $("input[id$=hCurrentArticleId]").val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(response) { confirmCommand(response); },
        error: function(response) { alert("Error"); }
    });
}
function confirmCommand(response) {
    var result = eval('(' + response.d + ')');
    if (result.IsSuccess) {
        $("#" + result.Command).parent().parent().parent().parent().remove();
        $("span[id$=spanCommentCount]").html('(' + result.Message + ')');
    }
    else {
        $.notifier(result.Message, "error");
    }
}
function answerComment(obj) {
    $("input[id$=hParentCommentId]").val(obj.id.split('_')[1]);
    $("input[id$=hEditMode]").val("0");
    $("#hTextToEdit").val("");
    $("input[id$=bSaveComment]").val("Написать");
    var objToMove = $("div[id$=divEditor]")[0];
    var objAfterInsert = $(obj).parent().parent();
    objAfterInsert.after(objToMove); //.appendChild(elem);
    $("span[id=spanNewComment]").show();
}

function NewComment() {
    $("input[id$=hParentCommentId]").val("");
    $("input[id$=hEditMode]").val("0");
    $("#hTextToEdit").val("");
    $("input[id$=bSaveComment]").val("Написать");
    var objToMove = $("div[id$=divEditor]")[0];
    var objAfterInsert = $("span[id=spanNewComment]");
    objAfterInsert.hide();
    objAfterInsert.after(objToMove); //.appendChild(elem);
}