﻿if (typeof (window.ceemeagain) == "undefined") window.ceemeagain = new Object();
if (typeof (ceemeagain.TVComment) == "undefined") {
    ceemeagain.TVComment = {
        postTVComment: function(the) {
            setTimeout(function() {

                var txtName = $.trim($(the).find("input[name=txtName]").val());
                //var txtCaptcha = $(the).find("input[name=name]");
                var txtMessage = $.trim($(the).find("textarea[name=txtComment]").val());
                if (txtMessage === "") { alert("Ooops! Comment message cannot be empty."); return false; }

                $(the).block({ message: "Loading...", css: { border: "10px solid #EEE", color: "#999"} });
                var id = $.trim($(the).find("input[name=id]").val());
                $.post("/TVComment/PostComment/", { id: id, name: txtName, message: txtMessage }
                    , function(data) {
                        if (data.IsError) {
                            alert(data.Message);
                        } else {
                            $(".comment-container .section").html(data.Message);
                            $(the).find("textarea[name=txtComment]").val('');
                            postTVComment($(the).parent().parent().find('a')[0]);
                        }
                        $(the).unblock();
                    }
                , "json");
            }, 10);
            return false;
        }, loadTVComment: function(id, page) {
            $.post("/TVComment/Index/", { id: id, page: page }
                    , function(data) {
                        if (data !== "") $(".comment-container .section").html(data);
                    }
               );
        }, deleteTVComment: function(commentId) {
            if (confirm("Do you want to delete this comment?")) {
                $.blockUI({ message: "Loading...", css: { color: "#999", padding: "10px"} });
                $.post("/TVComment/DeleteComment/", { id: commentId }
                    , function(data) {
                        if (data.IsError) {
                            alert(data.Message);
                        } else {
                            $(".comment-container .section").html(data.Message);
                        }
                        $(document.body).unblock();
                    }
                , "json");
            }
        }
    };
}
