function getAjax(url, parm, callBack) {
    $.ajax({
        type: 'post',
        dataType: "text",
        url: url,
        data: parm,
        cache: false,
        async: false,
        success: function (msg) {
            callBack(msg);
        }
    });
}

///声明常用变量
var PageIndex = 1;
var PageSize = 5;
var Order = "Messige_Date";
var OrderType = "desc";
var status = 1;

///异步查询
function GetEvaluation() {

    var userid = $("#userid").val();
    var para = "sqlwhere=1" + "&&PageIndex=" + PageIndex + "&&PageSize=" + PageSize + "&&orderfile=" + Order + "&&ordertype=" + OrderType + "&&status=" + status;
    getAjax("/Training/UserMessige/GetMessige.ashx", para, function (data) {
        if (data != "1") {
            var obj = eval('(' + data + ')')
            var Mes = eval('(' + obj.Mes + ')')
            var Send = eval('(' + obj.Send + ')')
            strHtml(Mes, Send);
        } else {
            $("#messigehtml").html("<div style=\"border:1px #cccccc solid;background-color:#fff; padding-bottom:10px; \" ><center><img src=\"/Template/default/Images/nodata.gif\"></center><div>");
        }
    });
}

///异步查询
function GetEvaluation2() {
    var userid = $("#userid").val();
    var para = "sqlwhere=2" + "&&PageIndex=" + PageIndex + "&&PageSize=" + PageSize + "&&orderfile=" + Order + "&&ordertype=" + OrderType + "&&status=" + status;
    getAjax("/Training/UserMessige/GetMessige.ashx", para, function (data) {
        if (data != "1") {
            var obj = eval('(' + data + ')')
            var Mes = eval('(' + obj.Mes + ')')
            var Send = eval('(' + obj.Send + ')')
            strHtml(Mes, Send);
        } else {
            $("#messigehtml").html("<div style=\"border:1px #cccccc solid;background-color:#fff; padding-bottom:10px; \" ><center><img src=\"/Template/default/Images/nodata.gif\"></center><div>");
        }
    });
}

function strHtml(Mes, Send) {
    //循环所有
    var str = "";
    if (Mes.length > 0) {
        for (var i = 0; i < Mes.length; i++) {
            str += " <div class=\"center_m3\"> <img src=\"/Mall/User_Image.ashx?id=" + Mes[i].Messige_UserID + "\" class=\"avatar fl\"/>";
            str += " <div class=\"avatar_font\" style=\"margin-top:15px;\">" + Mes[i].Messige_UserName + "</div>";
            str += " <div class=\"avatar_font\">" + JsonDate(Mes[i].Messige_Date) + "</div>";
            str += " <div class=\"clear\"></div>";
            var fujian = "";
            if (Mes[i].Messige_FileName != null && Mes[i].Messige_FileName != "" && Mes[i].Messige_FilePoth != "" && Mes[i].Messige_FilePoth != null) {
                fujian = "<a target=\"_blank\"  href=\"" + Mes[i].Messige_FilePoth + "\">" + Mes[i].Messige_FileName + "</a>";
            }
            str += " <div class=\"avatar_font\">" + Mes[i].Messige_Content + " " + fujian + "</div>";
            str += " <div class=\"clear\"></div>";
            str += " <div class=\"comments\">";
            str += " <a class=\"in1 fl\" href=\"javascript:pl2('" + Mes[i].Messige_ID + "');\" ><span class=\"ince_center\" style=\" background-position:-388px -23px;\"></span>评论</a>";
            str += " <div id=\"sc" + Mes[i].Messige_ID + "\" ><script>shouchang('" + Mes[i].Messige_ID + "',1);</script></div>";
            str += " <div id=\"z" + Mes[i].Messige_ID + "\"><script>zan('" + Mes[i].Messige_ID + "',2);</script></div>";
            str += " <div class=\"clear\"></div>";
            //一级回复
            for (var k = 0; k < Send.length; k++) {
                if (Send[k].Send_FID == Mes[i].Messige_ID) {
                    //            style=\" border:1px solid red; \"
                    str += "  <div id=\"div" + Mes[i].Messige_ID + "\" ><img src=\"/Mall/User_Image.ashx?id=" + Send[k].Send_UserID + "\" class=\"avatar_reply fl\"/>";
                    str += "  <div class=\"a1\" style=\"margin-top:5px;\">" + Send[k].Send_UserName + "：<span class=\"a2\">" + Send[k].Send_Content + "</span></div>";
                    str += "  <div class=\"avatar_time fl\">" + JsonDate(Send[k].Send_Date) + "</div>";
                    str += "  <a href=\"#\" onclick=\"javascript:createDiv('" + Mes[i].Messige_ID + "','" + Send[k].Send_ID + "','" + Send[k].Send_UserName + "','" + Send[k].Send_UserID + "')\"><span class=\"ince_center\"  title=\"回复\" style=\" background-position:-438px 0px;margin-top:2px;\"></span></a>";
                    str += "  <div class=\"clear\"></div>";
                    //二级回复
                    for (var c = 0; c < Send.length; c++) {
                        if (Send[c].Send_FID == Send[k].Send_ID) {
                            str += "  <img src=\"/Mall/User_Image.ashx?id=" + Send[c].Send_UserID + "\" class=\"avatar_reply fl\" style=\"margin-left:50px;\"/>";
                            str += "  <div class=\"a1\" style=\"margin-top:5px;margin-top:2px;\">" + Send[c].Send_UserName + " <span class=\"a2\"> 回复 </span>" + Send[c].Send_GetUserName + "：<span class=\"a2\">" + Send[c].Send_Content + "</span></div>";
                            str += "  <div class=\"avatar_time fl\">" + JsonDate(Send[c].Send_Date) + "</div>";
                            str += " <a href=\"#\" onclick=\"javascript:createDiv('" + Mes[i].Messige_ID + "','" + Send[k].Send_ID + "','" + Send[c].Send_UserName + "','" + Send[c].Send_UserID + "')\"><span class=\"ince_center\" title=\"回复\" style=\" background-position:-438px 0px;\"></span></a>   <div class=\"clear\">";
                            
                            //                        str += " <div class=\"in3\"><input type=\"text\" id=\"pl" + Send[c].Send_ID + "\"  placeholder=\"我也说点儿什么\" class=\"fl\"/>";
                            //                        str += " <a href=\"#\" class=\"fabu fl\" onclick=\"javascript:pinglu('" + Send[c].Send_ID + "','" + Send[c].Send_GetUserName + "','" + Send[c].Send_GetUserID + "')\" ><span class=\"ince_center\" title=\"评论\" style=\" background-position:-388px -24px;margin-top:2px;margin-left:18px; \"></span></a>";
                            //                        str += " </div>";

                            str += "  <div class=\"clear\"></div>";
                        }
                    }
                    str += "</div>";
                }
            }
            str += " <div class=\"in2\" id=\"fb" + Mes[i].Messige_ID + "\">";
            str += " <input type=\"text\" id=\"pl" + Mes[i].Messige_ID + "\" placeholder=\"我也说点儿什么\" class=\"fl\"/>";
            str += " <a href=\"#\" class=\"fabu fl\" onclick=\"javascript:pinglu('" + Mes[i].Messige_ID + "','" + Mes[i].Messige_UserName + "','" + Mes[i].Messige_UserID + "')\" ><span class=\"ince_center\" title=\"评论\" style=\" background-position:-388px -24px;margin-top:2px;margin-left:18px; \"></span></a> </div>";
            str += " <div class=\"clear\"></div>";
            str += "</div></div>";
        }
    } else {
        if (window.location.href.indexOf("MyShare.aspx") >= 0) {
            str = "<div style=\"border:1px #cccccc solid;background-color:#fff; padding-bottom:10px; \" ><center><img src=\"/Template/default/Images/nodata.gif\"></center><div>";
        }
    }
    $("#messigehtml").html(str);
}


///时间转换日期
function JsonDate(obj) {
    var data = obj;
    var date = new Date(parseInt(data.replace("/Date(", "").replace(")/", ""), 10));
    return date.getFullYear() + "-" + (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-" + (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " " + (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":" + (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes());
}
//收藏
function shouchang(mid, typeid) {
    $.get("/Training/UserMessige/UserMsgCollect.ashx", { action: "getNum", miid: mid, typeid: typeid, r: Math.random() }, function (date) {
        var array = new Array();
        array = date.split(',');
        if (array[1] != 0) {
            $("#sc" + mid + "").html("<a class=\"in1 fl\"><span class=\"ince_center\" style=\" background-position:-388px -98px;\"></span> 已收藏 (" + array[0] + ")</a>");
        } else {
            $("#sc" + mid + "").html("<a class=\"in1 fl\" href=\"javascript:MsgCol('" + mid + "', 1);\" ><span class=\"ince_center\" style=\" background-position:-388px -99px;\"></span> 收藏 (" + array[0] + ")</a>");
        }
    });
}
//赞
function zan(mid, typeid) {
    $.get("/Training/UserMessige/UserMsgCollect.ashx", { action: "getNum", miid: mid, typeid: typeid, r: Math.random() }, function (date) {
        var array = new Array();
        array = date.split(',');
        if (array[1] != 0) {
            $("#z" + mid + "").html("<a class=\"in1 fl\"><span class=\"ince_center\" style=\" background-position:-362px -148px;\"></span> 已赞 (" + array[0] + ")</a>");
        } else {
            $("#z" + mid + "").html("<a class=\"in1 fl\"href=\"javascript:MsgCol('" + mid + "', 2);\" ><span class=\"ince_center\" style=\" background-position:-362px -148px;\"></span> 赞 (" + array[0] + ")</a>");
        }
    });
}


//创建评论内容
function createDiv(a, b, c, d) {
    var qetions = document.getElementById("div" + a + "");
    if (document.getElementById("cdiv" + a + "") == null) {
        var div = document.createElement("div");
        div.className = "f";
        div.id = "cdiv" + a + "";
        div.style.left = "10px";
        div.style.top = "10px";
        var ans = "";
        var str = " <div class=\"in3\"><input type=\"text\" id=\"pl" + b + "\"  placeholder=\"回复 " + c + "：\" class=\"fl\"/>";
        str += " <a href=\"#\" class=\"fabu fl\" onclick=\"javascript:pinglu('" + b + "','" + c + "','" + d + "')\" ><span class=\"ince_center\" title=\"评论\" style=\" background-position:-388px -24px;margin-top:2px;margin-left:18px; \"></span></a>";
        str += " </div>";
        div.innerHTML = str;
        qetions.appendChild(div);
        document.getElementById("fb" + a).style.display = "none";
        document.getElementById("pl" + b).focus();
    } else {
        //                var obj = document.getElementById("cdiv" + a + "");
        //                qetions.removeChild(obj);
        //                document.getElementById("fb" + a).style.display = "block";
    }
}

//收藏与赞表
function MsgCol(mid, typeid) {
    $.get("/Training/UserMessige/UserMsgCollect.ashx", { action: "add", miid: mid, typeid: typeid, r: Math.random() }, function (date) {
        if (date == "100") {
            if (typeid == "1") { shouchang(mid, typeid); }
            if (typeid == "2") { zan(mid, typeid); }
        } else if (date == "102") {
            showTipsMsg("操作失败！", 2000, 3);
        } else if (date == "103") {
            showTipsMsg("操作异常！", 2000, 3);
        } else {
            showTipsMsg("系统异常！", 2000, 3);
        }
    });
}
//点评评论按钮
function pl2(a) {
    var qetions = document.getElementById("div" + a + "");
    if (document.getElementById("cdiv" + a + "") != null) {
        var obj = document.getElementById("cdiv" + a + "");
        qetions.removeChild(obj);
        document.getElementById("fb" + a).style.display = "block";
    }
    document.getElementById("pl" + a).focus();
}