﻿var upnews = "";

function SetUPID(upid) {
    upnews = upid;
}
function SendComment(id, e) {
    mainForm.StartUpdating();
    var content = document.getElementById(e).value;
    temp = 'commentBlock' + id;
    AKA.SCommonService.SaveCommentsForNews(id, content, e, OnSaveCommentsForNewsSucceeded);
    return false;
}

function OnSaveCommentsForNewsSucceeded(result) {
    mainForm.EndUpdating();
    if (result[1].toString() == "1") {
        __doPostBack(upnews, '');
        document.getElementById(result[0].toString()).value = "";
        var lk = "commentBlockToActiveMode" + result[0].toString();
        var bk = "commentBlock" + result[0].toString();
        jQuery('#' + lk.toString()).removeClass('hide');
        jQuery('#' + bk.toString()).addClass('hide');
    } else if (result[1].toString() == "-1") {
        document.getElementById(temp).innerHTML = "Вы не можете отправить сообщение в эту новостную ветку.";
    }
    return false;
}

function DeleteNews(id) {
    if (confirm('Хотите удалить комментарий?')) {
        mainForm.StartUpdating();
        AKA.SCommonService.DeleteNews(id, OnDeleteNewsSucceeded);
    }
}

function OnDeleteNewsSucceeded(result) {
    mainForm.EndUpdating();
    __doPostBack(upnews, '');
    
}

function showCommentBlock(id) {
    var lk = "commentBlockToActiveMode" + id;
    var bk = "commentBlock" + id;
    var tbx = "tbxComment" + id;
    jQuery('#' + lk.toString()).addClass('hide');
    jQuery('#' + bk.toString()).removeClass('hide');
    document.getElementById(tbx.toString()).focus();
}

function hideCommentBlock(id) {
    var tbx = "tbxComment" + id;
    var value = document.getElementById(tbx.toString()).value;
    if (value == "") {
        var lk = "commentBlockToActiveMode" + id;
        var bk = "commentBlock" + id;
        jQuery('#' + lk.toString()).removeClass('hide');
        jQuery('#' + bk.toString()).addClass('hide');
    }
}

