//#region 

Namespace.register("U.Reply");

U.Reply.Astart = function () {
    U.Reply.Load();
    U.Reply.content_box();
    U.Reply.Emoji();
}
var UploadImgSrc = [];
U.Reply.Load = function () {
    var comment = $$("div", { "className": "comment" }, $("body")[0]);

    var content = $$("div", { "className": "content" }, comment);
    var content_box = $$("div", { "className": "content_box" }, content);
    var head = $$("div", { "className": "head" }, content_box);
    //    head.style.background = 'url(http://fs.1473.cn/'+US.userInfo.UserThumbnailImageHead +')';
    if (US.userInfo.UserThumbnailImageHead != null) {
        head.style.background = 'url(http://fs.1473.cn/' + US.userInfo.UserThumbnailImageHead + ')'; //获取头像
    } else {
        head.style.background = 'url(/img/UserHead/UseHead.jpg) '; //获取头像
    }
    head.style.backgroundSize = '100% 100%';
    var frame = $$("div", { "className": "content_frame" }, content_box);
    var name = $$("div", { "innerHTML": US.userInfo.username }, frame);
    var input = $$("div", { "className": "content_input", "contenteditable": "true" }, frame);
    var bottom = $$("div", { "className": "content_top" }, frame);
    var emoji = $$("img", { "className": "content_emoji", "style": { "float": "left" } }, bottom);
    emoji.src = "../../img/reply/emoji.png";
    var div = $$("div", { "style": { "float": "left" } }, bottom);
    var picture = $$("img", { "className": "content_picture" }, div);
    picture.src = "../../img/reply/img.png";
    var upload = $$("input", { "id": "Files", "type": "file", "onchange": "U.Reply.Upload(this)", "style": { "position": "relative", "left": "-20px", "opacity": " 0" } }, div);
    var publish = $$("div", { "className": "content_publish", "innerHTML": "发表评论", "onclick": "U.Reply.release()" }, bottom);
    var emoji_frame = $$("div", { "className": "Reviews_emoji", "style": { "display": "none" } }, frame);
    var img = $$("div", { "className": "ImgLoad" }, frame);
    var box = $$("div", { "className": "content_bigbox" }, content);
}
/*
*函数作用:文件上传
*/
U.Reply.Upload = function (e) {

    U.UP.uploading([$("#Files")[0]],
        function (r) {
            var index = r.value[0].lastIndexOf(".");
            var str = r.value[0].substring(index + 1, r.value[0].length);
            var imgtype = /.*(jpg|png|gif|jpeg|JPG|PNG|GIF|JPEG)$/;
            if (str.match(imgtype)) {
                UploadImgSrc += "http://fs.1473.cn/" + r.value[0] + ",";
                U.Alert("上传成功");
                $(".ImgLoad")[0].innerHTML = "";
                U.Reply.ImgLoad();
            } else {
                U.Alert("请上传图片文件");
                return;
            }
        }, [], "http://disk.1473.cn/USupfile.ashx?iframename=UseStudioEditor");
}
U.Reply.ImgLoad = function () {
    if (UploadImgSrc != "") {
        var Imgsrc = UploadImgSrc.split(",");
        for (var i = 0; i < Imgsrc.length - 1; i++) {
            var img = $$("img", { "src": Imgsrc[i], "style": { "width": "100px", "height": "100px", "margin-right": "10px" } }, $(".ImgLoad")[0]);
        }
    }
}
//获取评论数据
U.Reply.content_box = function () {
    U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Reply", "Reply_SelectReply", "ad4e6deb-b40f-11e7-9fce-005056aa632a"], function (r) {
        var a = r.value;
        for (var i = 0; i < a.length; i++) {
            var rid = a[i].ReplyID;
            var content_box = $$("div", { "className": "content_box", "id": a[i].ReplyID }, $(".content_bigbox")[0]);
            var left = $$("div", { "className": "left", "style": { "height": "55px;", "float": "left" } }, content_box);
            var head = $$("div", { "className": "head" }, left);
            if (a[i].ReplyUserThumbnailImageHead == "null") {
                head.style.background = 'url(/img/UserHead/UseHead.jpg) '//获取头像
            } else if (a[i].ReplyUserThumbnailImageHead.substring(0, 4) == "http") {
                head.style.background = 'url( ' + a[i].ReplyUserThumbnailImageHead + ' ) '//获取头像
            } else {
                head.style.background = 'url(http://fs.1473.cn/' + a[i].ReplyUserThumbnailImageHead + ') '
            }
            head.style.backgroundSize = '100% 100%';
            var info = $$("div", { "className": "info" }, content_box);
            var right = $$("div", { "className": "right" }, info);
            var name = $$("p", { "className": "info_name", "innerHTML": a[i].UserName }, right);
            var time = $$("p", { "className": "info_time", "innerHTML": a[i].ReplyAddTime }, right);
            var clear = $$("div", { "style": { "clear": "both" } }, right);
            var substance = $$("div", { "className": "substance", "innerHTML": a[i].ReplyContent }, right);
            if (a[i].ReplyContentImgtype == 1) {
                var contentimg = $$("div", { "className": "content_img" }, right);
                var Imgsrc = a[i].ReplyContentImg.split(",");
                for (var j = 0; j < Imgsrc.length; j++) {
                    var img = $$("img", { "src": Imgsrc[j] }, contentimg);
                }
            }
            var bottom = $$("div", { "className": "bottom" }, right);
            var ul = $$("ul", { "className": "ul", "style": { "width": "500px", "margin-top": "10px" } }, bottom);
            var fabulous = $$("li", { "className": "fabulous" }, ul);
            var uid = "aa7146da-e67c-4b3d-91f7-1dcb92d9f7d1";
            U.Reply.f(rid, uid, i);
            var img = $$("img", { "className": "fabulous_img" }, fabulous);
            var number = $$("p", { "innerHTML": a[i].Fabulous }, fabulous);
            var reply = $$("li", { "className": "reply" }, ul);
            var reply_img = $$("img", { "src": "../../img/reply/reply.png" }, reply);
            var reply_p = $$("p", { "innerHTML": "回复" }, reply);
            var list = $$("li", { "className": "check" }, ul);
            var list_img = $$("img", { "className": "content_reply", "src": "../../img/reply/list.png" }, list);
            var list_p = $$("p", { "innerHTML": "查看对话", "onclick": "U.Reply.Reply()", "style": { "width": "100px;" } }, list);
            var clear = $$("div", { "style": { "clear": "both" } }, info);
            reply.addEventListener('click', function () {
                $(".content_input")[0].innerHTML = "";
                //alert(rid)
                if ($("#DetailInfo")[0] != undefined) {
                    //alert("a");
                    $("#dialogue")[0].remove();
                    U.Reply.content_box_a(this.parentNode.parentNode.parentNode.parentNode.parentNode.id);
                } else {
                    U.Reply.content_box_a(this.parentNode.parentNode.parentNode.parentNode.parentNode.id);
                }

            }, false);
            list.addEventListener('click', function () {
                $(".content_input")[0].innerHTML = "";
                //alert(rid)
                if ($("#DetailInfo")[0] != undefined) {
                    //alert("a");
                    $("#dialogue")[0].remove();
                    U.Reply.check(this.parentNode.parentNode.parentNode.parentNode.parentNode.id);
                } else {
                    U.Reply.check(this.parentNode.parentNode.parentNode.parentNode.parentNode.id);
                }

            }, false);
        }
    });
}
U.Reply.f = function (rid, uid, i) {
    U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Reply", "Reply_GetOnFabulousUserID", rid, uid], function (q) {
        var Fo = q.value["0"].data;
        if (Fo != 0) {
            $(".fabulous_img")[i].src = "../../img/reply/Fabulous.png";
            $(".fabulous_img")[i].onclick = function (rid, uid) { U.Reply.fabulous(this, '" + rid + "', '" + uid + "') }
            //var img = $$("img", { "src": "../../img/reply/Fabulous.png", "onclick": "U.Reply.fabulous(this,'" + rid + "','" + uid + "')" }, $(".fabulous")[i]);
        } else {
            $(".fabulous_img")[i].src = "../../img/reply/NOFabulous.png";
            $(".fabulous_img")[i].onclick = function (rid, uid) { U.Reply.fabulous(this, '" + rid + "', '" + uid + "') }
            //var img = $$("img", { "src": "../../img/reply/NOFabulous.png", "onclick": "U.Reply.fabulous(this,'" + rid + "','" + uid + "')" }, $(".fabulous")[i]);
        }
    });
}
//回复
U.Reply.content_box_a = function (ReplyID) {
    U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Reply", "Reply_Select_ReplyID", ReplyID], function (r) {
        var data = r.value;
        var dialogue = $$("div", { "className": "dialogue", "id": "dialogue", "style": { "display": "block" } }, $(".content")[0]);
        var content_box = $$("div", { "className": "content_box", "id": data[0].ReplyID }, dialogue);
        var left = $$("div", { "className": "left", "style": { "height": "55px;", "float": "left" } }, content_box);
        var head = $$("div", { "className": "head" }, left);
        if (data[0].ReplyUserThumbnailImageHead == "null") {
            head.style.background = 'url(/img/UserHead/UseHead.jpg) '//获取头像
        } else if (data[0].ReplyUserThumbnailImageHead.substring(0, 4) == "http") {
            head.style.background = 'url( ' + data[0].ReplyUserThumbnailImageHead + ' ) '//获取头像
        } else {
            head.style.background = 'url(http://fs.1473.cn/' + data[0].ReplyUserThumbnailImageHead + ') '
        }
        head.style.backgroundSize = '100% 100%';
        var info = $$("div", { "className": "info" }, content_box);
        var right = $$("div", { "className": "info_right" }, info);
        var name = $$("p", { "className": "info_name", "innerHTML": data[0].UserName }, right);
        var time = $$("p", { "className": "info_time", "innerHTML": data[0].ReplyAddTime }, right);
        var clear = $$("div", { "style": { "clear": "both" } }, right);
        var substance = $$("div", { "className": "substance", "innerHTML": data[0].ReplyContent }, right);
        var bottom = $$("div", { "className": "bottom" }, info);
        var clear = $$("div", { "style": { "clear": "both" } }, info);
        var setreply = $$("div", { "className": "setreply", "style": {} }, bottom);
        var dialogue_box = $$("div", { "className": "dialogue_box", "contenteditable": "true" }, setreply);
        //评论
        var publish = $$("span", { "className": "content_publishb", "id": ReplyID, "innerHTML": "评论" }, setreply);
        publish.onclick = function () {
            var FileID = "ad4e6deb-b40f-11e7-9fce-005056aa632a"; // 板块ID
            var UserID = "aa7146da-e67c-4b3d-91f7-1dcb92d9f7d1"; //用户id US.userInfo.userid
            var UserName = "13622333003"; //US.userInfo.username 
            var ReplyID = Guid.newGuid(); //评论id 自定义生成
            var ReplyContent = $(".dialogue_box")[0].innerHTML; //评论内容
            var ReplyIP = "10.3.13.77"; //ip地址US.userInfo.RegisterIP
            var ReplyAddress; "中国广东深圳"; //ip所在地址  US.userInfo.LoginAddress
            var ReplyDeep = 2; //深度
            var ReplyUserThumbnailImageHead = 'null'; //头像 UserImageHead
            var ReplyBindingID = this.id; //绑定id
            var ReplyParentId = '';
            var ReplyParentNickname = "江浩然"; //昵称 US.userInfo.UserNickName
            var Fabulous = 0; //点赞数
            U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Reply", "Reply_InsertReply", FileID, UserID, UserName, ReplyID, ReplyContent, ReplyIP, ReplyAddress, ReplyDeep, ReplyUserThumbnailImageHead, ReplyBindingID, ReplyParentId, ReplyParentNickname, Fabulous], function () {
                dialogue_box.innerHTML = "";
                dialogue.removeChild($(".content_container")[0]);
                LoadReply(data[0].ReplyID);
                U.Alert("评论发表成功")
            });
        }
        LoadReply(ReplyID);
        U.UI.From({
            "id": "DetailInfo", "style": { "width": "563px", "height": "385px", "border-radius": "5px;", "box-shadow": "none;" }, "content": $("#dialogue")[0], "title": "回复评论",
            "hst": { "style": { "padding": "0", "background-color": "#3f506a", "height": "32px", "line-height": "32px", "text-indent": "2.2em" } }
        })
    });
}
U.Reply.Close = function () {
    $("#dialogue")[0].style.display = 'none';
}
U.Reply.Close1 = function () {
    $(".dialogue")[0].style.display = 'none';
}
U.Reply.check = function (ReplyID) {
    U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Reply", "Reply_Select_ReplyID", ReplyID], function (r) {
        var data = r.value;
        var dialogue = $$("div", { "className": "dialogue", "id": "dialogue", "style": { "display": "block" } }, $(".content")[0]);
        var content_box = $$("div", { "className": "content_box", "id": data[0].ReplyID }, dialogue);
        var left = $$("div", { "className": "left", "style": { "height": "55px;", "float": "left" } }, content_box);
        var head = $$("div", { "className": "head" }, left);
        if (data[0].ReplyUserThumbnailImageHead == "null") {
            head.style.background = 'url(/img/UserHead/UseHead.jpg) '//获取头像
        } else if (data[0].ReplyUserThumbnailImageHead.substring(0, 4) == "http") {
            head.style.background = 'url( ' + data[0].ReplyUserThumbnailImageHead + ' ) '//获取头像
        } else {
            head.style.background = 'url(http://fs.1473.cn/' + data[0].ReplyUserThumbnailImageHead + ') '
        }
        head.style.backgroundSize = '100% 100%';
        var info = $$("div", { "className": "info" }, content_box);
        var right = $$("div", { "className": "info_right" }, info);
        var name = $$("p", { "className": "info_name", "innerHTML": data[0].UserName }, right);
        var time = $$("p", { "className": "info_time", "innerHTML": data[0].ReplyAddTime }, right);
        var clear = $$("div", { "style": { "clear": "both" } }, right);
        var substance = $$("div", { "className": "substance", "innerHTML": data[0].ReplyContent }, right);
        var bottom = $$("div", { "className": "bottom" }, info);
        var clear = $$("div", { "style": { "clear": "both" } }, info);
        LoadReply(ReplyID);
        U.UI.From({
            "id": "DetailInfo", "style": { "width": "563px", "height": "385px", "border-radius": "5px;", "box-shadow": "none;" }, "content": $("#dialogue")[0], "title": "回复评论",
            "hst": { "style": { "padding": "0", "background-color": "#3f506a", "height": "32px", "line-height": "32px", "text-indent": "2.2em" } }
        })
    });
}
LoadReply = function (ReplyID) {
    U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Reply", "Reply_SelectReplyDeep", ReplyID], function (r) {
        if (r.value.length != 0) {
            var data = r.value;
            var container = $$("div", { "className": "content_container" }, $(".dialogue")[0]);
            for (var i = 0; i < data.length; i++) {
                var content_box = $$("div", { "className": "content_box", "id": data[i].ReplyID }, container);
                var left = $$("div", { "className": "left", "style": { "height": "55px;", "float": "left" } }, content_box);
                var head = $$("div", { "className": "head" }, left);
                if (data[i].ReplyUserThumbnailImageHead == "null") {
                    head.style.background = 'url(/img/UserHead/UseHead.jpg) '//获取头像
                } else if (data[i].ReplyUserThumbnailImageHead.substring(0, 4) == "http") {
                    head.style.background = 'url( ' + data[i].ReplyUserThumbnailImageHead + ' ) '//获取头像
                } else {
                    head.style.background = 'url(http://fs.1473.cn/' + data[i].ReplyUserThumbnailImageHead + ') '
                }
                head.style.backgroundSize = '100% 100%';
                var info = $$("div", { "className": "info" }, content_box);
                var right = $$("div", { "className": "info_right", "style": { "width": "440px", "float": "right" } }, info);
                var name = $$("p", { "className": "info_name", "innerHTML": data[i].UserName }, right);
                var time = $$("p", { "className": "info_time", "innerHTML": data[i].ReplyAddTime }, right);
                var clear = $$("div", { "style": { "clear": "both" } }, right);
                var substance = $$("div", { "className": "substance", "innerHTML": data[i].ReplyContent }, right);
                if (data[i].ReplyContentImgtype == 1) {
                    var contentimg = $$("div", { "className": "content_img" }, right);
                    var Imgsrc = data[i].ReplyContentImg.split(",");
                    for (var j = 0; j < Imgsrc.length; j++) {
                        var img = $$("img", { "src": Imgsrc[j] }, contentimg);
                    }
                }
                var clear = $$("div", { "style": { "clear": "both" } }, info);
            }
        } else {
            var container = $$("div", { "className": "content_container" }, $(".dialogue")[0]);
            var none = $$("div", { "className": "container_none", "innerHTML": "暂无评论" }, container);
        }
    });

}
U.Reply.a = function (hfid) {
    //$("#content_publishb")[0].onclick = function () {
    var FileID = "ad4e6deb-b40f-11e7-9fce-005056aa632a"; // 板块ID
    var UserID = US.userInfo.userid; //用户id US.userInfo.userid
    var UserName = US.userInfo.username; //US.userInfo.username 
    var ReplyID = Guid.newGuid(); //评论id 自定义生成
    var ReplyContent = $(".dialogue_box")[0].innerHTML; //评论内容
    var ReplyIP = userinfo.RegisterIP; //ip地址US.userInfo.RegisterIP
    var ReplyAddress; US.userInfo.LoginAddress; //ip所在地址  US.userInfo.LoginAddress
    var ReplyDeep = 2; //深度
    var ReplyUserThumbnailImageHead = 'null'; //头像 UserImageHead
    var ReplyBindingID = hfid; //绑定id
    var ReplyParentId = '';
    var ReplyParentNickname = US.userInfo.UserNickName; //昵称 US.userInfo.UserNickName
    var Fabulous = 0; //点赞数
    U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Reply", "Reply_InsertReply", FileID, UserID, UserName, ReplyID, ReplyContent, ReplyIP, ReplyAddress, ReplyDeep, ReplyUserThumbnailImageHead, ReplyBindingID, ReplyParentId, ReplyParentNickname, Fabulous], function () {
        U.Alert("评论成功");
    });
}
U.Reply.release = function () {
    $(".content_publish")[0].onclick = function (e) {
        var pow = $(".content_input")[0].innerHTML.trim();
        if (pow.length > 0) {
            var FileID = "ad4e6deb-b40f-11e7-9fce-005056aa632a"; // 板块ID
            var UserID = "aa7146da-e67c-4b3d-91f7-1dcb92d9f7d1"; //用户id US.userInfo.userid
            var UserName = US.userInfo.username; //US.userInfo.username 
            var ReplyID = Guid.newGuid(); //评论id 自定义生成
            var ReplyContent = $(".content_input")[0].innerHTML; //评论内容
            var ReplyIP = US.userInfo.RegisterIP; //ip地址US.userInfo.RegisterIP
            var ReplyAddress; US.userInfo.LoginAddress; //ip所在地址  US.userInfo.LoginAddress
            var ReplyDeep = 1; //深度
            var ReplyUserThumbnailImageHead = US.userInfo.UserImageHead; //头像 UserImageHead
            //this.parentNode.parentNode.parentNode.;
            var ReplyBindingID = ''; //绑定id
            var ReplyParentId = '';
            var ReplyParentNickname = US.userInfo.UserNickName; //昵称 US.userInfo.UserNickName
            var Fabulous = ''; //点赞数
            if (UploadImgSrc.length != 0) {
                var ReplyContentImg = UploadImgSrc.substring(0, UploadImgSrc.length - 1);
                var ReplyContentImgtype = "1";
            } else {
                var ReplyContentImg = ''
                var ReplyContentImgtype = '';
            }
            U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Reply", "Reply_InsertReply", FileID, UserID, UserName, ReplyID, ReplyContent, ReplyIP, ReplyAddress, ReplyDeep, ReplyUserThumbnailImageHead, ReplyBindingID, ReplyParentId, ReplyParentNickname, Fabulous, ReplyContentImg, ReplyContentImgtype], function (r) {
                U.Alert("评论成功");
                $(".content_bigbox")[0].innerHTML = ''
                $(".ImgLoad")[0].innerHTML = '';
                $(".content_input")[0].innerHTML = '';
                U.Reply.content_box();
            });
        } else {
            U.Alert("请输入评论内容");
        }
    }
    //U.Reply.Range = U.D.E.GetSelectionRange(window, content_input, { "TF": "QL" });
}
//表情
U.Reply.Emoji = function () {
    $(".content_emoji")[0].addEventListener("click", function () {
        if ($(".Reviews_emoji")[0].style.display == "none") {
            $(".Reviews_emoji")[0].style.display = "block";
            $(".Reviews_emoji")[0].innerHTML = "";
            for (var i = 0; i < 104; i++) {
                var dz = "/img/ChatingFaceGif/[face](" + i + ").gif";
                var img = $$("img", { "src": dz, "alt": "Alternate Text" }, $(".Reviews_emoji")[0]);
                img.onclick = function () {
                    var src = this.src;
                    U.Reply.Range.CreateR();
                    U.Reply.Range.Replace($$("img", { "src": src, "alt": "Alternate Text" }
                    ));
                    //$$("img", { "src": src, "alt": "Alternate Text" }, $(".content_input")[0]);
                }
            }
        } else {
            $(".Reviews_emoji")[0].style.display = "none";
        }
    })
}
//点赞
U.Reply.fabulous = function (e, a, b) {
    if (e.src == "/img/reply/Fabulous.png") {
        U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Reply", "Replay_cancelFabulous", a, b], function (r) {
            e.src = "/img/reply/NOFabulous.png";
            e.parentNode.firstChild.innerHTML = parseInt(e.parentNode.firstChild.innerHTML) - 1;
        });
    } else {
        var str = e.parentNode.parentNode;
        var rid = str.parentNode.id;
        var uid = "aa7146da-e67c-4b3d-91f7-1dcb92d9f7d1"; //US.userInfo.id
        U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_Reply", "Reply_UpdateFabulous", a, b], function (r) {
            e.src = "/img/reply/Fabulous.png";
            e.parentNode.firstChild.innerHTML = parseInt(e.parentNode.firstChild.innerHTML) + 1
        });
    }
}