﻿function showLoginMessage(commentID) {
    $('#loginMsg' + commentID).fadeIn('slow');
}

function trackComment(commentID, tickbox) {

    trackCommentUpdate(commentID, tickbox.checked);
    $('#updated' + commentID).fadeOut('fast');
    $('#updated' + commentID).fadeIn('slow');
    $('#updated' + commentID).fadeIn('slow');

}

function trackCommentUpdate(commentID, trackReplies) {
    $.post('/Comment/TrackComment', { commentID: commentID, trackReplies: trackReplies });
}


function makeCommentHtmlEditor() {
    // Turning off tinymce

//    showLoading();
//    $('#txtCmt').tinymce({
//        // Location of TinyMCE script
//        script_url: '/Scripts/tiny_mce/tiny_mce.js',

//        // General options
//        theme: "simple",
//        plugins: "paste,directionality,noneditable,visualchars",

//        // Example content CSS (should be your site CSS)
//        content_css: "css/content.css",

//        convert_urls: false,
//        preformatted: false,

//        // Drop lists for link/image/media/template dialogs
//        template_external_list_url: "lists/template_list.js",
//        external_link_list_url: "lists/link_list.js",
//        external_image_list_url: "lists/image_list.js",
//        media_external_list_url: "lists/media_list.js",

//        // Replace values for the template plugin
//        template_replace_values: {
//            username: "Some User",
//            staffid: "991234"
//        }
//    });
//    hideLoading();

}


function showChangePublish(commentID) {
    $("#cpCommentID").val(commentID);
    $("#divChangePublish").dialog({ height: 205 }, { width: 420 }, { modal: true }, { title: "Update comment status" });
}

function showAddComment(parentCommentID,showTitle) {
    if (typeof tinyMCE != "undefined") {
        tinyMCE.execCommand('mceRemoveControl', false, 'txtCmt');
    }

    if (showTitle)
        $('#divCommentTitle').fadeIn();
    else
        $('#divCommentTitle').hide();

    // Reset the fields
    $("#txtCmt").val();
    $("#divCommentImg").html("");
    $("#imgIDfromUpload").val("");
    

    if (parentCommentID > 0)
        $("#ParentCommentID").val(parentCommentID);
    else {
        $("#ParentCommentID").val("null");
    }
    // $("#divNewComment").dialog({ modal: true }, { title: "Enter a comment" }, { resize: "auto" }, { width: "auto" });
    $("#divNewComment").center();
    $("#divNewComment").fadeIn('fast');

    makeCommentHtmlEditor();
}

function addCommentComplete(context) {

    hideLoading();
    // Check if the comment saved okay, if not show message.
    var json = context.get_response().get_object();
    if (json.Success) {
        
        //$("#divNewComment").dialog('close');
        $("#divNewComment").fadeOut('fast');

        var newCommentID = json.ItemID;
        var parentCommentID = json.ItemID2;
        $("#cmtTls" + parentCommentID).fadeOut('slow');
        if (parentCommentID != null) {
            $("#cmt" + parentCommentID).fadeIn('slow');
            //$("#cmt" + parentCommentID).append("<br /><hr /><span class='newCmt'>Your reply:</span><br /><br />" + $("#txtCmt").val() + "<br /><br />" + $("#divCommentImg").html());
            $("#cmt" + parentCommentID).append("<br /><hr /><span class='newCmt'>Your reply:</span><br /><br />" + json.Info + "<br /><br />" + $("#divCommentImg").html());
            $("#txtCmt").val("");
        }
        else {
            //$("#divTopCmt").prepend("<hr /><span class='newCmt'>Your comment:</span><br />" + $("#txtCmt").val() + "<br /><br />" + $("#divCommentImg").html());
            $("#divTopCmt").prepend("<hr /><span class='newCmt'>Your comment:</span><br />" + json.Info + "<br /><br />" + $("#divCommentImg").html());
            $("#divTopCmt").fadeIn("slow");
            $("#txtCmt").val("")
        }
    }
    else {

    }
}

function addForumCommentComplete(context) {

    hideLoading();
    // Check if the comment saved okay, if not show message.
    var json = context.get_response().get_object();
    if (json.Success) {
        $("#divNewComment").fadeOut('fast');

        var newCommentID = json.ItemID;
        var parentCommentID = json.ItemID2;

        location.reload();
        
    }
    else {

    }
}

function showReportAbuse(commentID) {
    $("#abuseCmtID").val(commentID);
    $("#divReportAbuse").dialog({ height: 270 }, { width: 420 }, { modal: true }, { title: "Report abuse or spam" });
}

function showDeleteComment(commentID) {
    $("#delCommentID").val(commentID);
    $("#divDeleteCmt").dialog({ height: 190 }, { width: 420 }, { modal: true }, { title: "Delete a comment" });
}

function addCommentBegin() {
    showLoading();
}

function deleteCmtBegin() {
    showLoading();
}

function changePublishBegin() {
    showLoading();
}

function reportAbuseBegin() {
    showLoading();
}




function reportAbuseComplete() {
    hideLoading();
    $("#divReportAbuse").dialog('close');
    alert('Your notification has been emailed to an administrator. The administrator will check this comment and rectify as soon as possible if it is deemed to be abusive.');
}

function deleteCmtComplete(context) {
    hideLoading();
    var json = context.get_response().get_object();
    if (json.Success) {
        location.reload(true);

    }
}

function changePublishComplete(context) {
    hideLoading();
    var json = context.get_response().get_object();
    if (json.Success) {
        $("#divChangePublish").dialog('close');
        if (json.ItemID2 == 1) //Published
        {
            // Hide the not published message.
            $("#divAdminNotPublished" + json.ItemID).fadeOut('slow');
        }
        else {
            // Show the not published message.
            $("#divAdminNotPublished" + json.ItemID).fadeIn('slow');
        }
    }
}



function cancelComment() {
    //$("#divNewComment").dialog('close');
    $("#divNewComment").fadeOut('fast');
}

function cancelReportAbuse() {
    $("#divReportAbuse").dialog('close');
}

function cancelDelete() {
    $("#divDeleteCmt").dialog('close');
}

   
