﻿//评论的公用事件，等有时间再把所有评论js整理一遍


/*=====================================新增=======================*/
/*ljj 2010-2-20*/
var id = new Array();
id[0] = 0;
var oFCKeditor = new Array();
var oFCKeditorF;
//创建FCK控件实例，i为实例ID
function createFCKeditor() {
    var sBasePath = "/fckeditor/editor/fckeditor.html?InstanceName=FCKeditor999&Toolbar=Comment";
    oFCKeditorF = new FCKeditor('FCKeditor999');
    oFCKeditorF.BasePath = sBasePath;
    oFCKeditorF.Width = "520px";//"100%"
    oFCKeditorF.Height = "200px";
    oFCKeditorF.ToolbarSet = "Comment"; // 工具条设置
    oFCKeditorF.Create();
}
/*ljj 2010-2-25*/
function createFCKeditorBig() {
    var sBasePath = "/fckeditor/editor/fckeditor.html?InstanceName=FCKeditor999&Toolbar=Comment";
    oFCKeditorF = new FCKeditor('FCKeditor999');
    oFCKeditorF.BasePath = sBasePath;
    oFCKeditorF.Width = "650";
    oFCKeditorF.Height = "250px";
    oFCKeditorF.ToolbarSet = "Comment"; // 工具条设置
    oFCKeditorF.Create();
}
/*ljj 2010-2-20*/
//提交成功后往页面添加内容，vid为rid的值，uid为回复人的userid,txt为回复的内容,id为返回来的close 事件 参数
function AddReplyContent(rid, recommentid, uid, txt, commentid) {
    var time = new Date().format("yyyy-MM-dd hh:mm:ss"); //当前时间
    var s = '<div recommentid="' + recommentid + '"><div class="reps_h"><div class="fl"><a href="../user/?uid=' + uid + '">我</a>的回复：</div><div class="fr hr">' + time + '<a class="mgl" href="javascript:void(0)" onclick="DelReply(' + recommentid + ');"><img src="/images/UI/btn_close1.gif" alt="关闭" /></a></div><div class="c"/></div><div class="reps_cntx my">' + txt + '</div></div>';
    var dom = $(".reps[rid='" + rid + "']");
    dom.show();
    dom.append(s);
}
/*ljj 2010-2-25*/
function AddReplyContentOverload(rid, id, uid, txt) {
    var time = new Date().format("yyyy-MM-dd hh:mm:ss"); //当前时间
    var s = '<div class="c_' + id + '"><div class="reps_h"><div class="fl"><a href="../user/?uid=' + uid + '">我</a>的回复：</div><div class="fr hr">' + time + '<a class="mgl" href="javascript:void(0)" onclick="DelHome(' + id + ');"><img src="/images/UI/btn_close1.gif" alt="关闭" /></a></div><div class="c"/></div><div class="reps_cntx my">' + txt + '</div></div>';
    var dom = $(".reps[rid='" + rid + "']");
    dom.show();
    dom.append(s);
}

/*ljj 2010-2-20*/
//单击链接“回复”后，生成FCK和“回复”，“取消”按钮vid为隐藏层的ID后缀，i为当前是第几个FCK
function _replyComment(rid, i) {
    oFCKeditor[id[i]] = new FCKeditor('FCKeditor' + id[i]);
    id[i + 1] = id[i] + 1;
    var strSrc = "/fckeditor/editor/fckeditor.html?InstanceName=FCKeditor" + id[i] + "&Toolbar=Comment";
    var inner = "<div><input type='text' id='FCKeditor" + id[i] + "' name='FCKeditor" + id[i] + "' value='' style='display:none' /> <input type='text' id='FCKeditor" + id[i] + "___Config' name='FCKeditor" + id[i] + "' value='' style='display:none' /><iframe name='FCKeditor' class='f' id='FCKeditor" + id[i] + "___Frame' src='' width='100%' height='120px' frameborder='0' scrolling='no' ></iframe></div>";
    var html = '<div class="editor">';
    html += inner;
    html += '</div>';
    html += '<div class="editor_bt">';
    html += '<div class="btn_n_box1"><span><input type="button" id="Button1" class="btns btn_n_s1"  onmouseout="this.className=\'btns btn_n_s1\';" onmouseover="this.className=\'btns btn_n_s2 \';"  value="取消" onclick="reply_cancel(' + rid + ')"/></span></div>';
    html += '<div class="btn_y_box1">';
    html += '<span><input type="button" id="CommentButton" class="btns btn_y_s1"  onmouseout="this.className=\'btns btn_y_s1\';" onmouseover="this.className=\'btns btn_y_s2 \';" value="回复" onclick="_reply_submit(' + rid + ',' + i + ',' + 0 + ',' + 2+ ');"/></span>';
    html += '</div>';
    html += '<div class="c"></div>';
    $(".rep_again[rid='" + rid + "']").html(html);
    setTimeout(function() {
        $("#FCKeditor" + id[i] + "___Frame").attr('src', strSrc);
    }, 10);
}
/*ljj 2010-2-25*/
function _replyCommentOverload(rid, i, cid) {
    oFCKeditor[id[i]] = new FCKeditor('FCKeditor' + id[i]);
    id[i + 1] = id[i] + 1;
    var strSrc = "/fckeditor/editor/fckeditor.html?InstanceName=FCKeditor" + id[i] + "&Toolbar=Comment";
    var inner = "<div><input type='text' id='FCKeditor" + id[i] + "' name='FCKeditor" + id[i] + "' value='' style='display:none' /> <input type='text' id='FCKeditor" + id[i] + "___Config' name='FCKeditor" + id[i] + "' value='' style='display:none' /><iframe name='FCKeditor' class='f' id='FCKeditor" + id[i] + "___Frame' src='' width='100%' height='120px' frameborder='0' scrolling='no' ></iframe></div>";
    var html = '<div class="editor">';
    html += inner;
    html += '</div>';
    html += '<div class="editor_bt">';
    html += '<div class="btn_n_box1"><span><input type="button" id="Button1" class="btns btn_n_s1"  onmouseout="this.className=\'btns btn_n_s1\';" onmouseover="this.className=\'btns btn_n_s2 \';"  value="取消" onclick="reply_cancel(' + rid + ')"/></span></div>';
    html += '<div class="btn_y_box1">';
    html += '<span><input type="button" id="CommentButton" class="btns btn_y_s1"  onmouseout="this.className=\'btns btn_y_s1\';" onmouseover="this.className=\'btns btn_y_s2 \';" value="回复" onclick="_reply_submit(' + rid + ',' + i + ',' + cid + ',' + 1+ ');"/></span>';
    html += '</div>';
    html += '<div class="c"></div>';
    $(".rep_again[rid='" + rid + "']").html(html);
    setTimeout(function() {
        $("#FCKeditor" + id[i] + "___Frame").attr('src', strSrc);
    }, 10);
}
/*ljj 2010-2-20*/
//评论列表内的取消按钮
function reply_cancel(rid) {
    $(".replylink[rid='" + rid + "']").css("color", "#999");  //回复链接颜色改回来
    $(".rep_again[rid='" + rid + "']").html("");  //回复点击后的层清空
}
/*ljj 2010-2-25*/
//评论按钮的click事件
function firstCommentClick() {
    if (!uid || uid == '0') {
        ChangeUrl();
        return;
    }
    firstCommentAdd();
}
/*ljj 2010-2-26*/
//评论按钮的click事件
function firstCommentClickOverload() {
    if (!lguid || lguid == '0') {
        ChangeUrl();
        return;
    }
    firstCommentAdd();
}
/*ljj 2010-2-26*/
function _reply_submit(rid, i, cid,type) {
    if(type==1)
    {
        if (!uid || uid == '0') 
        {
            ChangeUrl();
            return;
        }
        addComment(rid,i,cid);
    }
    if(type==2)
    {
        if (!lguid || lguid == '0') 
        {
            ChangeUrl();
            return;
         }
      addComment(rid, i);
       
    }
}
/*ljj 2010-2-26*/
//删除评论回复
function DelReplyChild(url,reviewid)
{
     var c = confirm("是否要删除该评论回复");
    if (c) {
        $.post(url, { ActionType: "delrecomment", ReCommentId: reviewid }, function(data) {
            $("div[recommentid=" + reviewid + "]").hide();
        });
    }
   
}
/*ljj 2010-2-26*/
//删除评论
function DelCommentChild(url,commentid)
{
     var c = confirm("你确认要删除这条评论和它的所有回复吗？");
    if (c) {
        $.post(url, { ActionType: "delcomment", CommentId: commentid }, function(data) {
            //alert(data);
            $(".ulist[commentid=" + commentid + "]").hide();
        });
    }
   
}
/*ljj 2010-2-26*/
///给编辑器赋值
function SetEditorContents(EditorName) {
    if (oFCKeditorF) {
        var oEditor = FCKeditorAPI.GetInstance(EditorName);
        var v = document.getElementById("ctl00_C_v").value;
        oEditor.SetHTML(v);
    }
}
/*ljj 2010-3-1*/
//单击输入框下的回复按钮,o为“回复”链接文字本身，i为FCK的序列号从0开始，是根据a里的rid获取,cid是这个评论的评论id
function CommentReply(o, i, cid) {
    var elId, divEl;
    //alert(o.attr("rid"));
    elId = o.attr("rid"); ;
    o.css("color", "#6b3"); //回复链接颜色改绿色
    divEl = $(".rep_again[rid='" + elId + "']");
    divEl.show();
    _replyCommentOverload(elId, i, cid);/*ljj 2010-2-25*/
}
/*ljj 2010-3-1*/
//单击输入框下的回复按钮,o为“回复”链接文字本身，
function CommentReplyOverload(o, i) {
    var elId, divEl;
    //alert(o.attr("rid"));
    elId = o.attr("rid"); ;
    o.css("color", "#6b3"); //回复链接颜色改绿色
    divEl = $(".rep_again[rid='" + elId + "']");
    divEl.show();
    _replyComment(elId, i);
}



/*ljj 2010-2-24*/
//页面内的评论按钮
function firstCommentAdd_common(url,value,typeString) {
    //var pid = phid;
   var content;
    var cpage = 0;
    var iSteal = 0;
    oEditor = FCKeditorAPI.GetInstance(oFCKeditorF.InstanceName);
    content = oEditor.GetXHTML(true);
    //过滤空格和<P>标签判断内容是否为空
    if (TrimCommentContent(content) == "") {
        alert("请输入内容!");
        return;
    }
    //过滤img和p标签判断内容长度
    if (DelHtmlCommentContent(content).length > 1500) {
        alert("内容不能超过1500个字符！");
        return;
    }
     if ($(".steal input").attr("checked") == true) {
        iSteal = 1;
    }
    $("#CommentButton").hide();
    oEditor.SetHTML("");
    content = ChangeCommentContent(content);
    if(typeString=='event')
    {
        $.post(url, { ActionType: "comment", CommentContent: content, eventid: value }, function(data) {
            PostData(data);
        });
    }
     if(typeString=='interest')
    {
        $.post(url, { ActionType: "comment", CommentContent: content, PhotoId: value }, function(data) {
            PostData(data);
        });
    }
    if(typeString=='group')
    {
        $.post(url, { ActionType: "comment", CommentContent: content, PhotoId: value }, function(data) {
            PostData(data);
        });
    }
     if(typeString=='location')
    {
        $.post(url, { ActionType: "comment", CommentContent: content, PhotoId: value }, function(data) {
            PostData(data);
        });
    }
    if(typeString=='photo')
    {
        $.post(url, { ActionType: "comment", CommentContent: content, PhotoId: value, steal: iSteal }, function(data) {
            PostData(data);
        });
    }

    $("#CommentButton").show();
}
  
    function PostData(data)
    {
         //alert("1");
        //alert(data);
        if (data) {
            //GetComments(pid, cpage);
            $("#CommentList").html(data);

            $(".replylink").click(function() {
                var obj = $(this);
                var n = parseInt(obj.attr("rid"));
                var cid = parseInt(obj.attr("commentid"));
                CommentReply(obj, n, cid);
            });
            $(".dellink").click(function() {
                var obj = $(this);
                var cid = obj.attr("commentid");
                DelComment(cid);
            });
        }
        else {
            alert("数据库繁忙，请稍候再试！");
        }
        //alert("111");
    }
 



/*===================================================*/









































/*//页面的评论按钮事件
function firstCommentClick() {
    firstCommentAdd();
}

//页面的评论按钮事件具体操作
function firstCommentAdd() {
    var did = $("#ctl00_C_txt_HostID").val();
    var uid = $("#ctl00_C_txt_ID").val();
    var iSteal = 0;
    oEditor = FCKeditorAPI.GetInstance(oFCKeditorF.InstanceName);
    var content = oEditor.GetXHTML(true);
    //过滤空格和<P>标签判断内容是否为空
    if (TrimCommentContent(content) == "") {
        alert("请输入内容!");
        return;
    }
    //过滤img和p标签判断内容长度
    if (DelHtmlCommentContent(content).length > 1500) {
        alert("内容不能超过1500个字符！");
        return;
    }
    //隐藏评论按钮，防止重复提交
    $("#firstComment").hide();
    //清空编辑器
    oEditor.SetHTML("");
    content = ChangeCommentContent(content);
    //alert(content);
    if ($(".steal input").attr("checked") == true) {
        iSteal = 1;
    }
    //提交内容
    $.post("/Ajax/user/reviews.ashx", { mode: "addhome", did: did, text: content, uid: uid, steal: iSteal }, function(data) {
        GetComments();
    });
    $("#firstComment").show();
}
*/