﻿var EditorView = "Short";

var editorCommentData = function(data) {

    var BottomLink = "";
    var Title = "";

    $('#EditorComments').empty();

    if (EditorView == "Short")
        BottomLink = '<div id="BottomLink"><a href="#EditorCommentsTop">^ Top</a></div>';
    else
        BottomLink = '<div id="BottomLink"><a href="#" class="ReadMoreLink">READ MORE...</a></div>';

    if (data != undefined) {
        for (var i = 0; i < data.AuthorComments.AuthorComment.length; i++) {

            if (i == 0)
                Title = '<div id="TitleFirst">';
            else
                Title = '<div id="Title">';
                
            $('#EditorComments').append('<div id="EditorComment">' +
            Title + data.AuthorComments.AuthorComment[i].Subject + '</div>' +
            '<div id="Date">' + data.AuthorComments.AuthorComment[i].Date + '</div>' +
            '<div id="Comment">' + data.AuthorComments.AuthorComment[i].Comment + '</div>' +
            BottomLink);
        }

        if (EditorView == "Full")
            $('.ReadMoreLink').click(function() {
                renderEditorText(false);
                return false;
            });

        $('#editor').css('display', 'block');
    }

    else
        $('#editor').css('display', 'none');
};



var renderEditorText = function(init) {

    $.ajax({ url: 'editorcomments.aspx?&Text=' + EditorView, success: editorCommentData, dataType: 'jsonp' });

    if (EditorView == "Full")
    {
        $('#editortoggleView').text("Collapse View");
        EditorView = "Short";
        if(!init)
            ntptEventTag('ev=expand1');
    }

    else
    {
        $('#editortoggleView').text("Expand View");
        EditorView = "Full";
        if (!init)
            ntptEventTag('ev=collapse1');
    }
};

var recordAnchor = function(sText) {
    ntptEventTag(sText);
    return true;
};

