﻿var comments = {
    ShowInputComment: function(commentID, SenderObj) {
        (function($) {
            $(document).ready(function() {
                $("#btnAddComment" + commentID).show("slow");
                SenderObj.className = "ActiveTextArea";
                if (SenderObj.value == "Write a comment....") {
                    SenderObj.value = "";
                }
            });
        })(jQuery);
    },
    HideInputComment: function(commentID, SenderObj) {
        (function($) {
            $(document).ready(function() {
                if (SenderObj.value == "") {
                    $("#btnAddComment" + commentID).hide("slow");
                    SenderObj.className = "Inactivetextarea";
                    $(SenderObj).val("Write a comment....");
                }
            });
        })(jQuery);
    },
    SendComment: function(TargetID, TextBoxControl, VariVariable, AjaxPanel, CommentContainerID, InputContainerID) {
        (function($) {
            $(document).ready(function() {
                if ($("#" + TextBoxControl).val() == "")
                    return false;
                $("#" + AjaxPanel).css("display", "");
                var _text = $("#" + TextBoxControl).val();
                comments.SendGeneralComment(TargetID, VariVariable, _text, function(result, eventArgs) {
                    $("#" + AjaxPanel).css("display", "none");
                    $("#" + TextBoxControl).val("");
                    $("#" + CommentContainerID).html($("#" + CommentContainerID).html() + result);
                    comments.HideInputComment(InputContainerID, document.getElementById(TextBoxControl));
                    return false;
                });
                return false;
            });
        })(jQuery);
    },
    SendGeneralComment: function(TargetID, Variable, CommentText, CallBack) {
        (function($) {
        $(document).ready(function() {
            WPS.BLL.WPSWebService.SendComment(TargetID, Variable, CommentText, CallBack, function() { Notification.drawSuccessNotification("Unknown problem",false,false); });
            });
        })(jQuery);
    },
    cancelComment: function() {
        (function($) {
            $(document).ready(function() {
//                $("#" + reminder.commentPanel + " > div > .reminder_comment").html("");
//                reminder.commentPanel = "";
            });
        })(jQuery);
    },
    getComments: function(targetID, targetType, containerID) {
        (function($) {
            $(document).ready(function() {
//                if (reminder.commentPanel != "") {
//                    if (targetID == reminder.commentPanel) {
//                        comments.cancelComment();
//                        return;
//                    }
//                    else {
//                        comments.cancelComment();
//                    }
//                }
        //        reminder.commentPanel = targetID;
                WPS.BLL.WPSWebService.getComment(targetID, targetType, function(result) {
                    var _comment = eval(result);
                    $("#" + containerID).html(_comment.Content);
                }, function() { Notification.drawSuccessNotification("Unknown problem",false,false); });
            });
        })(jQuery);
    },
    deleteComment: function(commentID) {
        (function($) {
            $(document).ready(function() {
                if (confirm("Are you sure you want to delete this comment?")) {
                    $("#" + commentID).slideUp("slow");
                    WPS.BLL.WPSWebService.deleteComment(commentID, function() { }, function() { Notification.drawSuccessNotification("Unkonown problem",false,false); });
                }
            });
        })(jQuery);
    }
};