﻿function gsComments()
{
    this.oCurrentCommentBox = null;
    this.oCurrentCommentBoxOwnerPost = null;
    this.oLastCommentBoxPlaceHolder = null;
}

gsComments.prototype = 
{
    getItemComments: function (nContentID, nContentType) 
    {
        var sComments = "";

        if (nContentID > 0 && nContentType > 0) 
        {
            var params = new Array();
            params[0] = "ContentID=" + nContentID;
            params[1] = "ContentType=" + nContentType;

            sComments = oAjaxTools.getData(26, params, false, null);
        }

        return sComments;
    },

    CreateComment: function (nContentID, nContentType)
    {
        var oMe = this;

        if (document.getElementById("CommentBox_Textarea").value != "" && nContentID > 0 && nContentType > 0) 
        {
            var oSubmitBtn = document.getElementById("CommentBox_CommentBtn");

            oSubmitBtn.disabled = true;

            document.getElementById("CommentBox_LoadStatus").style.display = "block";

            var params = new Array();
            params[0] = "Comment=" + document.getElementById("CommentBox_Textarea").value;
            params[1] = "ContentID=" + nContentID;
            params[2] = "ContentType=" + nContentType;

            var func = function () 
            {
                if (arguments[0] != null) 
                {
                    if (arguments[0].readyState == 4) 
                    {
                        if (arguments[0].status == 200) 
                        {
                            if (arguments[0].responseText.indexOf("True") == 0) 
                            {
                                var sComments = oMe.getItemComments(nContentID, nContentType);

                                if (sComments != "") 
                                {
                                    document.getElementById("_comments_list").innerHTML = sComments;
                                }

                                document.getElementById("CommentBox_Textarea").value = "";

                                document.getElementById("CommentBox_LoadStatus").style.display = "none";
                                oSubmitBtn.disabled = false;
                            }
                            else 
                            {
                                alert("An error occured, please try again later.\n\n" + arguments[0].responseText);

                                document.getElementById("CommentBox_LoadStatus").style.display = "none";
                                oSubmitBtn.disabled = false;
                            }
                        }
                        else 
                        {
                            alert("An error occured, please try again later.\n\n" + arguments[0].status);
                        }
                    }
                    else 
                    {
                    }
                }
            };
        }
        else 
        {
            alert("An error occured, please try again later.");

            document.getElementById("CommentBox_LoadStatus").style.display = "none";
            oSubmitBtn.disabled = false;
        }

        var oReq = oAjaxTools.getData(24, params, false, func);
    },

    SubmitComment: function (nContentID, nContentType) 
    {
        var oMe = this;

        oMe.CreateComment(nContentID, nContentType);
    },

    RemoveComment: function (commentid, itemid) 
    {
        var oMe = oPoster;

        if (commentid != null && commentid != "" && isNaN(commentid) == false && parseInt(commentid) > 0) 
        {
            if (confirm("Are you sure you want to remove this comment?") == true) 
            {
                var params = new Array();
                params[0] = "cid=" + parseInt(commentid);

                var func = function () {
                    if (arguments[0] != null) {
                        if (arguments[0].readyState == 4) 
                        {
                            if (arguments[0].status == 200) {
                                if (arguments[0].responseText == "True") 
                                {
                                    setTimeout(function () {
                                        document.getElementById("_comment_" + commentid).style.display = "none";
                                        //alert("Comment Removed");                          

                                    }, 0);
                                }
                                else {
                                    setTimeout(function () {
                                        alert("This comment could not be removed at this time. Please try again a little bit later.");
                                    }, 0);
                                }
                            }
                        }
                        else {
                        }
                    }
                };

                var oRemoveCommentReq = oAjaxTools.getData(32, params, true, func);
            }
        }
    }
}

var oComments = new gsComments();

/*

getItemPostComments : function(nContentID, nContentType, nPostID)
    {
        var sComments = "";

        if (nContentID > 0 && nContentType > 0 && nPostID > 0)
        {
            if (oBootLoader.ready == true)
            {
                var params = new Array();
                    params[0] = "ContentID=" + nContentID;
                    params[1] = "ContentType=" + nContentType;
                    params[2] = "PostID=" + nPostID;

                sComments = oAjaxTools.getData(26, params, false, null);
            }
        }

        return sComments;
    },

    CreatePostComment : function(nContentID, nContentType, nPostID)
    {
        if (document.getElementById("CommentBox_Textarea").value != "" && nContentID > 0 && nContentType > 0)
        {
            var oSubmitBtn = document.getElementById("CommentBox_CommentBtn");

                oSubmitBtn.disabled = true;

                document.getElementById("CommentBox_LoadStatus").style.display = "block";

            var params = new Array();
                params[0] = "Comment=" + document.getElementById("CommentBox_Textarea").value;
                params[1] = "ContentID=" + nContentID;
                params[2] = "ContentType=" + nContentType;
                params[3] = "PostID=" + nPostID;

            var func = function ()
            {
                if (arguments[0] != null)
                {
                    if (arguments[0].readyState == 4)
                    {
                        if (arguments[0].status == 200)
                        {
                            if (arguments[0].responseText.indexOf("True") == 0)
                            {
                                document.body.appendChild(document.getElementById("CommentBox"));

                                var sComments = getItemPostComments(nContentID, nContentType, nPostID);

                                CommentBoxBlur();

                                if (sComments != "")
                                {
                                    document.getElementById("_post_" + nPostID + "_comments").innerHTML = sComments;
                                }

                                showPostCommentArea(nPostID);

                                document.getElementById("CommentBox_LoadStatus").style.display = "none";
                                oSubmitBtn.disabled = false;
                            }
                            else
                            {
                                alert("An error occured, please try again later.\n\n" + arguments[0].responseText);
                                
                                document.getElementById("CommentBox_LoadStatus").style.display = "none";
                                oSubmitBtn.disabled = false;
                            }
                        }
                        else
                        {
                            alert("An error occured, please try again later.\n\n" + arguments[0].status);
                        }
                    }
                    else
                    {
                    }
                }
            };
        }
        else
        {
            alert("An error occured, please try again later.");

            document.getElementById("CommentBox_LoadStatus").style.display = "none";
            oSubmitBtn.disabled = false;
        }

        var oReq = oAjaxTools.getData(24, params, false, func);
    },

    SubmitPostComment: function ()
    {
        var oMe = this;

        if (oMe.oCurrentCommentBoxOwnerPost != null)
        {
            var arrCommentData = document.getElementById("_post_" + oMe.oCurrentCommentBoxOwnerPost + "_comments_data").value.split(',');

            PostComment(arrCommentData[0], arrCommentData[1], oMe.oCurrentCommentBoxOwnerPost);
        }
    },

    RemovePostComment : function(commentid, itemid)
    {
        var oMe = oPoster;
            
        if (commentid != null && commentid != "" && isNaN(commentid) == false && parseInt(commentid) > 0)
        {
            if(confirm("Are you sure you want to remove this comment?") == true)
            {            
                var params = new Array();
                    params[0] = "cid=" + parseInt(commentid);
                    
                var func = function()
                {
                    if (arguments[0] != null) 
                    {
                        if (arguments[0].readyState == 4)
                        {
                            if (arguments[0].status == 200) 
                            {
                                if (arguments[0].responseText == "True") 
                                {   
                                    setTimeout(function() 
                                    {
                                        document.getElementById("_post_" + commentid).style.display = "none";
                                        //alert("Comment Removed");                          

                                    }, 0);
                                }
                                else 
                                {
                                    setTimeout(function() 
                                    {
                                        alert("This comment could not be removed at this time. Please try again a little bit later.");   
                                    }, 0);
                                }
                            }
                        }
                        else 
                        {
                        }
                    }
                };
                    
                var oRemovePostReq = oAjaxTools.getData(13, params, true, func);
            }
        }
    },


*/
