﻿var gcmn_id = 0;
var gcmn_type_id = 0;
var gcmn_type_cd = '';
$(document).ready(function() {
    initDeleteComment();
    initDeleteCommentBoard();
    initDeleteSCommentBoard();
    //initPrivateCommentDialog();
    $('#btnCommentYes').click(function() {
        var respText = onDeleteComment(gcmn_id);
        //displayMessage(respText);
        $(this).oneTime(400, 'timer', function() {
            closeDeleteCommentDialogue();
            var comment_list = getCommentList(gcmn_type_id, gcmn_type_cd);
            $('#blogComment' + gcmn_type_id).html(comment_list);
            if ($('#blogComment' + gcmn_type_id).length > 0) {
                $('#blogComment' + gcmn_type_id).html(comment_list);
                if ($("#blogComment" + gcmn_type_id + ' .friendListPic a img').attr('title') != '') {
                    initThumnailToolTip("#blogComment" + gcmn_type_id);
                    if ($("#blogComment" + gcmn_type_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#blogComment" + gcmn_type_id); }
                }
            }
            if ($('#photoComment' + gcmn_type_id).length > 0) {
                $('#photoComment' + gcmn_type_id).html(comment_list);
                if ($("#photoComment" + gcmn_type_id + ' .friendListPic a img').attr('title') != '') {
                    initThumnailToolTip("#photoComment" + gcmn_type_id);
                    if ($("#photoComment" + gcmn_type_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#photoComment" + gcmn_type_id); }
                }
            }
            if ($('#vdoComment').length > 0)
                $('#vdoComment').html(comment_list);
            if ($('#boardComment' + gcmn_type_id).length > 0) {
                $('#boardComment' + gcmn_type_id).html(comment_list);
                if ($("#boardComment" + gcmn_type_id + ' .friendListPic a img').attr('title') != '') {
                    initThumnailToolTip("#boardComment" + gcmn_type_id);
                    if ($("#boardComment" + gcmn_type_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#boardComment" + gcmn_type_id); }
                }
            }
            var suffix = gcmn_type_cd + gcmn_type_id;            
            $('#charityComment' + suffix).html(comment_list);
            if ($('#charityComment' + suffix).length > 0) {
                $('#charityComment' + suffix).html(comment_list);
                if ($("#charityComment" + suffix + ' .friendListPic a img').attr('title') != '') {
                    initThumnailToolTip("#charityComment" + suffix);
                    if ($("#charityComment" + suffix + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#charityComment" + suffix); }
                }
            }
            $('#charityDonationComment' + suffix).html(comment_list);
            if ($('#charityDonationComment' + suffix).length > 0) {
                $('#charityDonationComment' + suffix).html(comment_list);
                if ($("#charityDonationComment" + suffix + ' .friendListPic a img').attr('title') != '') {
                    initThumnailToolTip("#charityDonationComment" + suffix);
                    if ($("#charityDonationComment" + suffix + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#charityDonationComment" + suffix); }
                }
            }
        });
    });
    $('#btnCommentBoardYes').click(function() {
        var respText = onDeleteComment(gcmn_id);
        //displayMessage(respText);
        $(this).oneTime(400, 'timer', function() {
            closeDeleteCommentBoardDialogue();
            var comment_list = getCommentBoardList(gcmn_type_id, gcmn_type_cd, false);
            if ($('#boardComment' + gcmn_type_id).length > 0) {
                $('#boardComment' + gcmn_type_id).html(comment_list);
                if ($("#boardComment" + gcmn_type_id + ' .friendListPic a img').attr('title') != '') {
                    initThumnailToolTip("#boardComment" + gcmn_type_id);
                    if ($("#boardComment" + gcmn_type_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#boardComment" + gcmn_type_id); }
                }
            }
            // TODO: Checking Count Comment
            if ($('#countCommentBoard' + gcmn_type_id).text() != '') {
                var countComment = parseInt(parseInt($('#countCommentBoard' + gcmn_type_id).text().substring(1, $('#countCommentBoard' + gcmn_type_id).text().indexOf(')')))) - 1;
                if (countComment > 0)
                    $('#countCommentBoard' + gcmn_type_id).text('(' + countComment + ')');
                else
                    $('#countCommentBoard' + gcmn_type_id).text('');
            }
        });
    });
    // TODO: Delete Sub Comment on Board
    $('#btnSCommentBoardYes').click(function() {
        var respText = onDeleteComment(gcmn_id);
        //displayMessage(respText);
        $(this).oneTime(400, 'timer', function() {
            closeDeleteSCommentBoardDialogue();
            var comment_list = getCommentBoardList(gcmn_type_id, gcmn_type_cd, true);
            if ($('#boardSComment' + gcmn_type_id).length > 0) {
                $('#boardSComment' + gcmn_type_id).html(comment_list);
                if ($("#boardSComment" + gcmn_type_id + ' .friendListPic a img').attr('title') != '') {
                    initThumnailToolTip("#boardSComment" + gcmn_type_id);
                    if ($("#boardSComment" + gcmn_type_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#boardSComment" + gcmn_type_id); }
                }
            }
            // TODO: Checking Count Comment
            if ($('#countSubCommentBoard' + gcmn_type_id).text() != '') {
                var countComment = parseInt(parseInt($('#countSubCommentBoard' + gcmn_type_id).text().substring(1, $('#countSubCommentBoard' + gcmn_type_id).text().indexOf(')')))) - 1;
                if (countComment > 0)
                    $('#countSCommentBoard' + gcmn_type_id).text('(' + countComment + ')');
                else
                    $('#countSubCommentBoard' + gcmn_type_id).text('');
            }
        });
    });
    // TODO: Delete Sub Comment on Public Board
    $('#btnCommentPublicBoardYes').click(function() {
        onDeleteCommentPublicBoard(gcmn_id, 'PBB');
        closeDeleteCommentPublicBoardDialogue();
        $(this).oneTime(400, 'timer', function() {
            var comment_list = getCommentPublicBoardList(gcmn_type_id, gcmn_type_cd);
            if ($('#boardComment' + gcmn_type_id).length > 0) {
                $('#boardComment' + gcmn_type_id).html(comment_list);
                if ($("#boardComment" + gcmn_type_id + ' .friendListPic a img').attr('title') != '') {
                    initThumnailToolTip("#boardComment" + gcmn_type_id);
                    if ($("#boardComment" + gcmn_type_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#boardComment" + gcmn_type_id); }
                }
            }
            // TODO: Checking Count Comment
            if ($('#countCommentBoard' + gcmn_type_id).text() != '') {
                var countComment = parseInt(parseInt($('#countCommentBoard' + gcmn_type_id).text().substring(1, $('#countCommentBoard' + gcmn_type_id).text().indexOf(')')))) - 1;
                if (countComment > 0)
                    $('#countCommentBoard' + gcmn_type_id).text('(' + countComment + ')');
                else
                    $('#countCommentBoard' + gcmn_type_id).text('');
            }
        });
    });
});
function profileRedirect(id) {
    var url = '';
    if (id == '0')
        url = server_root + '/profile.aspx';
    else
        url = server_root + '/profile.aspx?id=' + id;
    window.location.replace(url);
}
function onShowButton(id) {
    $('#btnSaveComment' + id).show();
    if ($('#commentButtonSave' + id).length > 0) {$('#commentButtonSave' + id).show(); }
}
function onTextLostFocus(mbb_id) {
    var cmn_content = $('#cmn_content' + mbb_id).val();
    cmn_content = cmn_content.trim();
    if (cmn_content.length == 0) {
        $('#btnSaveComment' + mbb_id).hide();
        if ($('#commentButtonSave' + mbb_id).length > 0) { $('#commentButtonSave' + mbb_id).hide(); }
    }
}
function onSaveComment(mbb_id, mbr_id, cmn_type_cd) {    
    var cmn_content = $('#cmn_content_val' + mbb_id).val();
    if (cmn_content.trim().length > 0) {
        var cmn_type_id = mbb_id;
        //var cmn_type_cd = 'BLG';  //Blog
        var cmn_mbr_id = mbr_id;
        var url = server_root + "/Processor/GeneralProcessPart3.aspx";
        var respText = $.ajax({
            url: url,
            type: 'POST',
            async: false,
            data: {
                proc_id: 30, //Save comment
                cmn_content: cmn_content,
                cmn_type_id: cmn_type_id,
                cmn_mbr_id: cmn_mbr_id,
                cmn_type_cd: cmn_type_cd
            }
        }).responseText;
        var comment_list = getCommentList(mbb_id, cmn_type_cd);
        if ($('#blogComment' + mbb_id).length > 0) {
            $('#blogComment' + mbb_id).html(comment_list);
            if ($("#blogComment" + mbb_id + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#blogComment" + mbb_id);
                if ($("#blogComment" + mbb_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#blogComment" + mbb_id); }
            }  
        }
        if ($('#photoComment' + mbb_id).length > 0) {
            $('#photoComment' + mbb_id).html(comment_list);
            if ($("#photoComment" + mbb_id + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#photoComment" + mbb_id);
                if ($("#photoComment" + mbb_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#photoComment" + mbb_id); }
            }  
        }
        if ($('#vdoComment').length > 0)
            $('#vdoComment').html(comment_list);
        if ($('#boardComment' + mbb_id).length > 0) {
            $('#boardComment' + mbb_id).html(comment_list);
            if ($("#boardComment" + mbb_id + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#boardComment" + mbb_id);
                if ($("#boardComment" + mbb_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#boardComment" + mbb_id); }
            }
        }
        if ($('#charityComment' + mbb_id).length > 0) {
            $('#charityComment' + mbb_id).html(comment_list);
            if ($("#charityComment" + mbb_id + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#charityComment" + mbb_id);
                if ($("#charityComment" + mbb_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#charityComment" + mbb_id); }
            }
        }
        if ($('#charityDonationComment' + mbb_id).length > 0) {
            $('#charityDonationComment' + mbb_id).html(comment_list);
            if ($("#charityDonationComment" + mbb_id + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#charityDonationComment" + mbb_id);
                if ($("#charityDonationComment" + mbb_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#charityDonationComment" + mbb_id); }
            }
        }           
    }
}
function onSaveCommentBoard(mbb_id, mbr_id, cmn_type_cd) {
    var cmn_content = $('#cmn_content_val' + mbb_id).val();
    if (cmn_content.trim().length > 0) {
        var cmn_type_id = mbb_id;
        //var cmn_type_cd = 'BLG';  //Blog
        var cmn_mbr_id = mbr_id;
        // Add new feature
        $("#cmn_content" + mbb_id).attr("disabled", "disabled"); 
        $("#btnSaveComment" + mbb_id).attr("class", "buttonGray");
        var url = server_root + "/Processor/GeneralProcessPart3.aspx";
        var respText = $.ajax({
            url: url,
            type: 'POST',
            async: false,
            data: {
                proc_id: 30, //Save comment
                cmn_content: cmn_content,
                cmn_type_id: cmn_type_id,
                cmn_mbr_id: cmn_mbr_id,
                cmn_type_cd: cmn_type_cd
            }
        }).responseText;
        var comment_list = getCommentBoardList(mbb_id, cmn_type_cd,false);
        if ($('#blogComment' + mbb_id).length > 0) {
            $('#blogComment' + mbb_id).html(comment_list);
            if ($("#blogComment" + mbb_id + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#blogComment" + mbb_id);
                if ($("#blogComment" + mbb_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#blogComment" + mbb_id); }
            }  
        }
        if ($('#photoComment').length > 0) {
            $('#photoComment').html(comment_list);
            if ($("#photoComment" + mbb_id + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#photoComment" + mbb_id);
                if ($("#photoComment" + mbb_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#photoComment" + mbb_id); }
            } 
        }
        if ($('#vdoComment').length > 0)
            $('#vdoComment').html(comment_list);
        if ($('#boardComment' + mbb_id).length > 0) {
            $('#boardComment' + mbb_id).html(comment_list);
            if ($("#boardComment" + mbb_id + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#boardComment" + mbb_id);
                if ($("#boardComment" + mbb_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#boardComment" + mbb_id); }
            } 
            // TODO: Update Count Comment
            if ($('#countCommentBoard' + mbb_id).text() != '') {
                var countComment = parseInt($('#countCommentBoard' + mbb_id).text().substring(1, $('#countCommentBoard' + mbb_id).text().indexOf(')'))) + 1;
                $('#countCommentBoard' + mbb_id).text('(' + countComment + ')');
            }
            else {
                $('#countCommentBoard' + mbb_id).text('(1)');
            }

        }
        if ($('#publicBoardComment' + mbb_id).length > 0) {
            $('#publicBoardComment' + mbb_id).html(comment_list);
            /*if ($("#publicBoardComment" + mbb_id + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#publicBoardComment" + mbb_id);
                if ($("#publicBoardComment" + mbb_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#boardComment" + mbb_id); }
            }*/
            // TODO: Update Count Comment
            if ($('#countCommentBoard' + mbb_id).text() != '') {
                var countComment = parseInt($('#countCommentBoard' + mbb_id).text().substring(1, $('#countCommentBoard' + mbb_id).text().indexOf(')'))) + 1;
                $('#countCommentBoard' + mbb_id).text('(' + countComment + ')');
            }
            else {
                $('#countCommentBoard' + mbb_id).text('(1)');
            }

        }
        // Add new feature
        $("#cmn_content" + mbb_id).removeAttr("disabled");
        $("#btnSaveComment" + mbb_id).attr("class","buttonBlue");
        /*if ($('#boardSComment' + mbb_id).length > 0) {
            var scomment_list = getCommentBoardList(mbb_id, cmn_type_cd, true);
            $('#boardSComment' + mbb_id).html(scomment_list);
            if ($("#boardSComment" + mbb_id + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#boardSComment" + mbb_id);
                if ($("#boardSComment" + mbb_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#boardSComment" + mbb_id); }
            } 

            // TODO: Update Count Comment
            if ($('#countSubCommentBoard' + mbb_id).text() != '') {
                var countComment = parseInt($('#countSubCommentBoard' + mbb_id).text().substring(1, $('#countSubCommentBoard' + mbb_id).text().indexOf(')'))) + 1;
                $('#countSubCommentBoard' + mbb_id).text('(' + countComment + ')');
            }
            else {
                $('#countSubCommentBoard' + mbb_id).text('(1)');
            }
        }*/
    }
}

function onSaveCommentPublicBoard(mbb_id, mbr_id, cmn_type_cd) {
    var cmn_content = "";
    if ($('#cmn_content' + mbb_id).val().indexOf("<object") > -1) {
        cmn_content = $('#cmn_content' + mbb_id).val();
    }
    else {
        cmn_content = StripHTMLAndTrim($('#cmn_content' + mbb_id).val());
    }
    $('#share_s_tmp').html(cmn_content);
    var str = "";
    var i = 0;
    var strRandomId = randomString();
    $('#share_s_tmp object').each(function() {
        var embed = $(this).find('embed').attr("src");
        str = "<a onclick=\"onShowEmbedMedia('" + strRandomId + "','" + embed + "', " + i + ");\">View Embedded Media</a>";
        $(str).insertAfter('#share_s_tmp object:eq(' + i + ')');
        i++;
    });
    $('#share_s_tmp object').remove();
    if (i > 0)
        $('#share_s_tmp').append('<span id=\"' + strRandomId + '\" style=\"display:none;\"></span>');

    $('#share_s_tmp').encHTML();
    cmn_content = $('#share_s_tmp').html();
    var shared_cat = $("#hdCat").val();

    var grp_id = ggrp_id != null ? ggrp_id : 0;
    if (cmn_content.trim().length > 0) {
        var cmn_type_id = mbb_id;
        var cmn_mbr_id = mbr_id;
        // Add new feature
        $("#cmn_content" + mbb_id).attr("disabled", "disabled");
        //$("#btnSaveComment" + mbb_id).attr("class", "buttonSGray");

        if ($('#commentButtonSave' + mbb_id).length > 0) {
            $("#btnSaveComment" + mbb_id).addClass("buttonSGray");
        } else {
            $("#btnSaveComment" + mbb_id).attr("class", "buttonGray");
        }

        var url = server_root + "/Processor/GeneralProcessPart3.aspx";
        var respText = $.ajax({
            url: url,
            type: 'POST',
            async: false,
            data: {
                proc_id: 30, //Save comment
                cmn_content: cmn_content,
                cmn_type_id: cmn_type_id,
                cmn_mbr_id: cmn_mbr_id,
                cmn_type_cd: cmn_type_cd,
                shared_cat: shared_cat,
                grp_id: grp_id
            }
        }).responseText;

        //$("#chkSubscribe" + cmn_type_cd + cmn_type_id).attr("checked", "checked");
        if (!$("#chkSubscribe" + cmn_type_cd + cmn_type_id).is(":checked")) {
            $("#chkSubscribe" + cmn_type_cd + cmn_type_id).trigger("click");
        }
        var comment_list = getCommentPublicBoardList(mbb_id, cmn_type_cd);
        if ($('#boardComment' + mbb_id).length > 0) {
            $('#boardComment' + mbb_id).html(comment_list);
            if ($("#boardComment" + mbb_id + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#boardComment" + mbb_id);
                if ($("#boardComment" + mbb_id + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#boardComment" + mbb_id); }
            }
            // TODO: Update Count Comment
            if ($('#countCommentBoard' + mbb_id).text() != '') {
                var countComment = parseInt($('#countCommentBoard' + mbb_id).text().substring(1, $('#countCommentBoard' + mbb_id).text().indexOf(')'))) + 1;
                $('#countCommentBoard' + mbb_id).text('(' + countComment + ')');
            }
            else {
                $('#countCommentBoard' + mbb_id).text('(1)');
            }

            var countReply = parseInt($("#replyCount" + shared_cat).text());
            $("#replyCount" + shared_cat).text(countReply + 1);
            var grandReply = $("#grandReply").text();
            if (grandReply.indexOf(',') > -1)
                grandReply = grandReply.replace(",", "");
            grandReply = formatNumber1000CommaStyle(parseInt(grandReply) + 1);
            $("#grandReply").text(grandReply);
        }

        // Add new feature
        $('#cmn_content' + mbb_id).removeClass("error");
        $("#cmn_content" + mbb_id).removeAttr("disabled");
        $("#btnSaveComment" + mbb_id).attr("class", "buttonSBlue leftButton");
    }
    else {
        $('#cmn_content' + mbb_id).addClass("error");
    }
}

function getCommentList(cmn_type_id, cmn_type_cd) {
    //var cmn_type_id = cmn_type_id;
    //var cmn_type_cd = 'BLG';  //Blog
    cmn_type_id = cmn_type_id == "" ? 0 : cmn_type_id;
    var url = server_root + "/Processor/GeneralProcessPart3.aspx";
    var respText = $.ajax({
        url: url,
        type: 'POST',
        async: false,
        data: {
            proc_id: 31, //Get comment list
            cmn_type_id: cmn_type_id,            
            cmn_type_cd: cmn_type_cd,
            client_dtime_offset: client_dtime_offset
        }  
    }).responseText;
    return respText;
}

function getCommentPhotoList(cmn_type_id, cmn_type_cd) {
    cmn_type_id = cmn_type_id == "" ? 0 : cmn_type_id;
    var url = server_root + "/Processor/GeneralProcessPart6.aspx";
    $.ajax({
        url: url,
        type: 'POST',
        async: true,
        data: {
            proc_id: 47, //Get comment list
            cmn_type_id: cmn_type_id,
            cmn_type_cd: cmn_type_cd
        },
        success: function(responseText) {
            if ($("#photoComment" + cmn_type_id).length == 0) {
                $("#appendComment").append(responseText);
            }
        }
    });
}

function getCommentPhotoListPre(cmn_type_id, cmn_type_cd) {
    cmn_type_id = cmn_type_id == "" ? 0 : cmn_type_id;
    var url = server_root + "/Processor/GeneralProcessPart6.aspx";
    $.ajax({
        url: url,
        type: 'POST',
        async: true,
        data: {
            proc_id: 47, //Get comment list
            cmn_type_id: cmn_type_id,
            cmn_type_cd: cmn_type_cd
        },
        success: function(responseText) {
            if ($("#photoComment" + cmn_type_id).length == 0) {
                $("#appendComment").append(responseText);
            }
        }
    });
}

function getCommentBoardList(cmn_type_id, cmn_type_cd, is_sub) {
    $("#divCommentLoading" + cmn_type_id).show();
    var url = server_root + "/Processor/GeneralProcessPart3.aspx";
    var respText = $.ajax({
        url: url,
        type: 'POST',
        async: false,
        data: {
            proc_id: 46, //Get comment board list
            cmn_type_id: cmn_type_id,
            cmn_type_cd: cmn_type_cd,
            mbr_id: mbr_id,
            frn_id: frn_id,
            is_sub: is_sub,
            client_dtime_offset: client_dtime_offset
        },
        success: function() {
            $("#divCommentLoading" + cmn_type_id).hide();
        }
    }).responseText;
    return respText;
}

function getCommentPublicBoardList(cmn_type_id, cmn_type_cd, idToScroll) {
    $("#divCommentLoading" + cmn_type_id).show();
    var all_cmn = gallow != null ? gallow : 0;
    var category = $("#hdCat").val();
    var url = server_root + "/Processor/GeneralProcessPart7.aspx";
    var respText = $.ajax({
        url: url,
        type: 'POST',
        async: false,
        data: {
            proc_id: 33, //Get comment board list
            cmn_type_id: cmn_type_id,
            cmn_type_cd: cmn_type_cd,
            client_dtime_offset: client_dtime_offset,
            shared_cat: category,
            all_cmn: all_cmn
        },
        success: function() {
            $("#divCommentLoading" + cmn_type_id).hide();
        }
    }).responseText;
    return respText;
}

function getCommentHighlightList(cmn_type_id, cmn_type_cd, is_sub) {
    $("#divCommentLoading" + cmn_type_id).show();
    var url = server_root + "/Processor/GeneralProcessPart6.aspx";
    var respText = $.ajax({
        url: url,
        type: 'POST',
        async: false,
        data: {
            proc_id: 48, //Get comment board list
            cmn_type_id: cmn_type_id,
            cmn_type_cd: cmn_type_cd,
            mbr_id: mbr_id,
            frn_id: frn_id,
            is_sub: is_sub,
            client_dtime_offset: client_dtime_offset
        },
        success: function() {
            $("#divCommentLoading" + cmn_type_id).hide();
        }
    }).responseText;
    return respText;
}

function onDeleteComment(cmn_id) {
    var url = server_root + "/Processor/GeneralProcessPart3.aspx";
    var respText = $.ajax({
        url: url,
        type: 'POST',
        async: false,
        data: {
            proc_id: 32, //Delete comment
            cmn_id: cmn_id            
        }
    }).responseText;
    return respText;
}

function onDeleteCommentPublicBoard(cmn_id, type_cd) {
    var url = server_root + "/Processor/GeneralProcessPart7.aspx";
    var category = $("#hdCat").val();
    $.ajax({
        url: url,
        type: 'POST',
        async: true,
        cache: false,
        data: {
            proc_id: 37, //Delete comment
            cmn_id: cmn_id,
            shared_cat: category,
            type_cd: type_cd
        },
        success: function(responseText) {
            if (responseText.indexOf("Your comment has been deleted.") > -1) {
                var value = parseInt($("#replyCount" + category).text());
                if (value > 0)
                    $("#replyCount" + category).text(value - 1);

                var grandReply = $("#grandReply").text();
                if (parseInt(grandReply) > 0) {
                    if (grandReply.indexOf(',') > -1)
                        grandReply = grandReply.replace(",", "");
                    grandReply = formatNumber1000CommaStyle(parseInt(grandReply) - 1);
                    $("#grandReply").text(grandReply);
                }
            }
        }
    });
}

function initDeleteComment() {
    var deleteDialog =  "                                        <!--Cancel Dialog--> " +
                        "                                        <div id=\"deleteComment_dialogue\" class=\"deleteComment_dialogue\" title=\"Delete Confirmation\" style=\"height:auto !important;display:none; padding:10px;\"> " +
                        "                                            <div class=\"centerAlign\">" +
                        "                                              <label>Do you wish to delete this comment?</label> " +
                        "                                              <div class=\"centerAlign topPadding\"><input type=\"button\" id=\"btnCommentYes\" name=\"btnCommentYes\" value=\"Yes\" class=\"buttonSBlue\" /> <input type=\"button\" id=\"btnCommentNo\" name=\"btnCommentNo\" value=\"No\" class=\"buttonSBlue\" onclick=\"closeDeleteCommentDialogue();\" /></div>                                                                                                                             " +
                        //"                                              <div id=\"comment_successMsg\" class=\"successMsg\" style=\"display:none;\"></div> " +
                        "                                            </div> " +
                        "                                        </div>";                        

    $('body').append(deleteDialog);

    $(function() {
        $('#deleteComment_dialogue').dialog({
            autoOpen: false,
            width: 400,
            height: 'auto',
            closeOnEscape: false,
            closeText: 'close',
            position: 'middle',
            draggable: true,
            modal: true
        });
    });
}

/*function initPrivateCommentDialog() {
    var dialog_result = "<!--End Choose Friend-->" +
                        "<div id=\"private_comment_dialog\" class=\"sendMsg_dialogue\" title=\"Private Reply\" style=\"display:none;\">" +
                        "<div class=\"beforeSendMsg centerAlign\">" +
                        "    <form id=\"composeMsg\">" +
                        "        <table class=\"composerField form\">  " +
                        "            <tbody>" +
                        "            <tr><td class=\"rightAlign\"><label>To:</label></td>" +
                        "            <td class=\"field\"><input id=\"ms_to_mbr_id_prv\" name=\"ms_to_mbr_id_prv\" type=\"text\" class=\"inputtext\" readonly=\"readonly\" /></td>" +
                        "            <tr><td class=\"rightAlign\"><label>Subject:</label></td>" +
                        "            <td class=\"field\"><div><input id=\"ms_subject_prv\" name=\"ms_subject_prv\" type=\"text\" class=\"inputtext\" maxlength=\"100\" readonly /></div></td></tr>" +
                        "            <tr><td class=\"rightAlign\"><label>Message:</label></td>" +
                        "            <td class=\"field\"><div><textarea id=\"ms_message_prv\" name=\"ms_message_prv\" rows=\"5\" cols=\"40\" onkeypress=\"return textareaMsgMaxLength(event,999,this);\"></textarea></div></td></tr>" +
                        "            <tr><td></td>" +
                        "            <td class=\"msgSubmit\"><input type=\"button\" onclick=\"\" id=\"btnMsgSendPrv\" name=\"btnMsgSendPrv\" value=\"Send\" class=\"buttonSBlue\" />&nbsp;<input type=\"button\" onclick=\"closeSendMsgDialogue();\" id=\"btnMsgCancelPrv\" name=\"btnMsgCancel\" value=\"Cancel\" class=\"buttonSBlue\" /></td></tr>" +
                        "            </tbody>      " +
                        "        </table>" +
                        "    </form>   " +
                        "    <div id=\"prvSuccessMsg\" class=\"successMsg\" style=\"display:none;\"></div> " +
                        "</div>" +
                        "</div>";
    $('body').append(dialog_result);

    $(function() {
        $('#private_comment_dialog').dialog({
            autoOpen: false,
            width: 500,
            height: 'auto',
            closeOnEscape: false,
            closeText: 'close',
            position: 'middle',
            draggable: true,
            modal: true
        });
    });
}*/

function closeDeleteCommentDialogue() {
    $('#deleteComment_dialogue').dialog('close');
}

function initDeleteCommentBoard() {
    var deleteDialog = "                                        <!--Cancel Dialog--> " +
                        "                                        <div id=\"deleteCommentBoard_dialogue\" class=\"deleteComment_dialogue\" title=\"Delete Confirmation\" style=\"height:auto !important;display:none;\"> " +
                        "                                            <div class=\"centerAlign\" style=\"padding-top:5px;\">" +
                        "                                              <label>Do you wish to delete this comment?</label> " +
                        "                                              <div class=\"centerAlign topPadding\"><input type=\"button\" id=\"btnCommentBoardYes\" name=\"btnCommentBoardYes\" value=\"Yes\" class=\"buttonSBlue\" /> <input type=\"button\" id=\"btnCommentBoardNo\" name=\"btnCommentBoardNo\" value=\"No\" class=\"buttonSBlue\" onclick=\"closeDeleteCommentBoardDialogue();\" /></div>                                                                                                                             " +
                        //"                                              <div id=\"comment_successMsg\" class=\"successMsg\" style=\"display:none;\"></div> " +
                        "                                            </div> " +
                        "                                        </div>";

    $('body').append(deleteDialog);

    $(function() {
        $('#deleteCommentBoard_dialogue').dialog({
            autoOpen: false,
            width: 400,
            height: 'auto',
            closeOnEscape: false,
            closeText: 'close',
            position: 'middle',
            draggable: true,
            modal: true
        });
    });
}

function closeDeleteCommentBoardDialogue() {
    $('#deleteCommentBoard_dialogue').dialog('close');
}

function initDeleteSCommentBoard() {
    var deleteDialog = "                                        <!--Cancel Dialog--> " +
                        "                                        <div id=\"deleteSCommentBoard_dialogue\" class=\"deleteComment_dialogue\" title=\"Delete Confirmation\" style=\"height:auto !important;display:none;\"> " +
                        "                                            <div class=\"centerAlign\" style=\"padding-top:5px;\">" +
                        "                                              <label>Do you wish to delete this comment?</label> " +
                        "                                              <div class=\"centerAlign topPadding\"><input type=\"button\" id=\"btnSCommentBoardYes\" name=\"btnSCommentBoardYes\" value=\"Yes\" class=\"buttonSBlue\" /> <input type=\"button\" id=\"btnSCommentBoardNo\" name=\"btnSCommentBoardNo\" value=\"No\" class=\"buttonSBlue\" onclick=\"closeDeleteSCommentBoardDialogue();\" /></div>                                                                                                                             " +
                       // "                                              <div id=\"scomment_successMsg\" class=\"successMsg\" style=\"display:none;\"></div> " +
                        "                                            </div> " +
                        "                                        </div>";

    $('body').append(deleteDialog);

    $(function() {
        $('#deleteSCommentBoard_dialogue').dialog({
            autoOpen: false,
            width: 400,
            height: 'auto',
            closeOnEscape: false,
            closeText: 'close',
            position: 'middle',
            draggable: true,
            modal: true
        });
    });
}

// TODO: Delete Sub Comment
function closeDeleteSCommentBoardDialogue() {
    $('#deleteSCommentBoard_dialogue').dialog('close');
}
// TODO: Delete Sub Comment
function openDeleteSCommentBoardDialogue(cmn_id, cmn_type_id, cmn_type_cd) {
    //$('#scomment_successMsg').html('');
    //$('#scomment_successMsg').hide();
    gcmn_id = cmn_id;
    gcmn_type_id = cmn_type_id;
    gcmn_type_cd = cmn_type_cd;
    $('#deleteSCommentBoard_dialogue').dialog('open');
}

function initDeleteCommentPublicBoard() {
    var deleteDialog = "                                        <!--Cancel Dialog--> " +
                        "                                        <div id=\"deleteCommentPublicBoard_dialogue\" class=\"deleteComment_dialogue\" title=\"Delete Confirmation\" style=\"height:auto !important;display:none;\"> " +
                        "                                            <div class=\"centerAlign\" style=\"padding-top:5px;\">" +
                        "                                              <label>Do you wish to delete this comment?</label> " +
                        "                                              <div class=\"centerAlign topPadding\"><input type=\"button\" id=\"btnCommentPublicBoardYes\" name=\"btnCommentPublicBoardYes\" value=\"Yes\" class=\"buttonSBlue\" /> <input type=\"button\" id=\"btnCommentPublicBoardNo\" name=\"btnCommentPublicBoardNo\" value=\"No\" class=\"buttonSBlue\" onclick=\"closeDeleteCommentPublicBoardDialogue();\" /></div>                                                                                                                             " +
    //"                                              <div id=\"comment_successMsg\" class=\"successMsg\" style=\"display:none;\"></div> " +
                        "                                            </div> " +
                        "                                        </div>";

    $('body').append(deleteDialog);

    $(function() {
        $('#deleteCommentPublicBoard_dialogue').dialog({
            autoOpen: false,
            width: 400,
            height: 'auto',
            closeOnEscape: false,
            closeText: 'close',
            position: 'middle',
            draggable: true,
            modal: true
        });
    });
}

function closeDeleteCommentPublicBoardDialogue() {
    $('#deleteCommentPublicBoard_dialogue').dialog('close');
}

// TODO: Delete Sub Comment
function openDeleteCommentPublicBoardDialogue(cmn_id, cmn_type_id, cmn_type_cd) {
    gcmn_id = cmn_id;
    gcmn_type_id = cmn_type_id;
    gcmn_type_cd = cmn_type_cd;
    $('#deleteCommentPublicBoard_dialogue').dialog('open');
}


function openDeleteCommentDialogue(cmn_id, cmn_type_id, cmn_type_cd) {
    //$('#comment_successMsg').html('');
    //$('#comment_successMsg').hide();
    gcmn_id = cmn_id;
    gcmn_type_id = cmn_type_id;
    gcmn_type_cd = cmn_type_cd;
    $('#deleteComment_dialogue').dialog('open');
}

function openDeleteCommentBoardDialogue(cmn_id, cmn_type_id, cmn_type_cd) {
    gcmn_id = cmn_id;
    gcmn_type_id = cmn_type_id;
    gcmn_type_cd = cmn_type_cd;
    $('#deleteCommentBoard_dialogue').dialog('open');
}

function onCommentKeyUp(id) {    
    $('#cmn_content_val' + id).val($('#cmn_content' + id).val());
}

function commentTextareaMaxLength(evt, MaxLen, Object) {
    if (evt != 'undefined') {
        var charCode = (evt.which) ? evt.which : window.event.keyCode;
        if (charCode != 8) {
            return (Object.value.length <= MaxLen);
        }
    }
}

function showCommentDelete(cmn_id) {
    $('#aCommentDelete' + cmn_id).show();
}
function hideCommentDelete(cmn_id) {
    $('#aCommentDelete' + cmn_id).hide();
}

function onSaveCommentForGeneral(mbb_id, mbr_id, cmn_type_cd) {
    var suffix_string = cmn_type_cd + mbb_id;
    var cmn_content = $('#cmn_content_val' + suffix_string).val();
    if (cmn_content.trim().length > 0) {
        var cmn_type_id = mbb_id;
        //var cmn_type_cd = 'BLG';  //Blog
        var cmn_mbr_id = mbr_id;

        var url = server_root + "/Processor/GeneralProcessPart3.aspx";
        var respText = $.ajax({
            url: url,
            type: 'POST',
            async: false,
            data: {
                proc_id: 30, //Save comment
                cmn_content: cmn_content,
                cmn_type_id: cmn_type_id,
                cmn_mbr_id: cmn_mbr_id,
                cmn_type_cd: cmn_type_cd
            }
        }).responseText;

        var comment_list = getCommentList(mbb_id, cmn_type_cd);
        if ($('#blogComment' + suffix_string).length > 0) {
            $('#blogComment' + suffix_string).html(comment_list);
            if ($("#blogComment" + suffix_string + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#blogComment" + suffix_string);
                if ($("#blogComment" + suffix_string + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#blogComment" + suffix_string); }
            }
        }

        if ($('#photoComment' + suffix_string).length > 0) {
            $('#photoComment' + suffix_string).html(comment_list);
            if ($("#photoComment" + suffix_string + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#photoComment" + suffix_string);
                if ($("#photoComment" + suffix_string + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#photoComment" + suffix_string); }
            }
        }

        if ($('#vdoComment').length > 0)
            $('#vdoComment').html(comment_list);

        if ($('#boardComment' + suffix_string).length > 0) {
            $('#boardComment' + suffix_string).html(comment_list);
            if ($("#boardComment" + suffix_string + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#boardComment" + suffix_string);
                if ($("#boardComment" + suffix_string + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#boardComment" + suffix_string); }
            }
        }

        if ($('#charityComment' + suffix_string).length > 0) {
            $('#charityComment' + suffix_string).html(comment_list);
            if ($("#charityComment" + suffix_string + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#charityComment" + suffix_string);
                if ($("#charityComment" + suffix_string + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#charityComment" + suffix_string); }
            }
        }

        if ($('#charityDonationComment' + suffix_string).length > 0) {
            $('#charityDonationComment' + suffix_string).html(comment_list);
            if ($("#charityDonationComment" + suffix_string + ' .friendListPic a img').attr('title') != '') {
                initThumnailToolTip("#charityDonationComment" + suffix_string);
                if ($("#charityDonationComment" + suffix_string + ' .blogTextarea').length > 0) { setTextBoxAutoResize("#charityDonationComment" + suffix_string); }
            }
        }
    }
}