﻿///////////////////////////////////////////////////////////////////////////////////留言操作 begin

//////////////////////////////////////////////////////////////////////////个人主页上留言
function addcomment()
 {

    $("#commentsubmit_btn").attr("disabled",true); 
    
    var message = $("#comment_message").val() == "undefined" ? "": $("#comment_message").val();
    var id = $("#id").val() == "undefined" ? "": $("#id").val();
    var uid = $("#uid").val() == "undefined" ? "": $("#uid").val();
    var idtype = $("#idtype").val() == "undefined" ? "": $("#idtype").val();
    //var jsonData =  "{message :'"+message+"'}";
    
    message = valueReplace(message);
    
    
    var jsonData = "{message :'" + message + "', id :'" + id + "', uid :'" + uid + "', idtype :'" + idtype + "'}";

    $.ajax({
        type: "POST",
        url: "cp_comment.aspx/savecomment",
        data: jsonData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
        $("#commentsubmit_btn").removeAttr("disabled"); 

            if (msg == "nologin")
            {
                NewshowHintAutoClose("信息提示", "该操作需要登陆，请先登陆");

            }
            else
            {


                if (msg == "too_short_3") {
                      NewshowHintAutoClose("信息提示","对不起，你输入出的信息必须要多于3个字符");
                    return;


                }

               if (msg.indexOf("nopose")>=0)     
               { 
                 var interval = msg.substring(msg.indexOf("_")+1);
                   NewshowHintAutoClose("信息提示","你发言太快了,请等待 "+interval+"秒后再发言!");
               }
                else
                {

                    $(msg).appendTo($("#comment_ul"));

                    //                  var child =  $("#comment_ul li:first-child").length;
                    //                  
                    //                  //$(msg).appendTo(comment_ul);
                    //                  if (child==0) {
                    //                  
                    //                   $(msg).appendTo( $("#comment_ul"));
                    //                  
                    //                  }
                    //                  else
                    //                  {
                    //                     $("#comment_ul").children().eq(0).before($(msg));
                    //                  
                    //                  }

                    NewshowHintAutoClose("信息提示", "保存成功!!!!!");
                    $("#comment_message").val("");

                }


            }


        }

    });


}

function popupreply(cid, cdiv) {
    $("#append_parent").load("cp_comment.aspx?cid=" + cid + " #comment" + cid, {
        "cid": cid,
        "username": "syj"
    },
    function()
    {
//        setCenter("comment" + cid);
        
         setPopupPosition(cdiv,"comment"+cid,0);
        
        $(".popupmenu_centerbox").easydrag(true);
        $(".popupmenu_centerbox").setHandler('drag_title');
//       


//    setCenter("a_f_r_" + fuid + "_menu");
//        $("#a_f_r_" + fuid + "_menu").easydrag(true);
//        $("#a_f_r_" + fuid + "_menu").setHandler('hander');

    });



}
function popupdelete(cid, cdiv) {
    $("#append_parent").load("cp_comment.aspx?cid=" + cid + " #delete" + cid, {
        "cid": cid,
        "username": "syj"
    },
    function()
    {
        setPopupPosition(cdiv, "delete" + cid, 0);
        //setCenter("delete"+cid);
        $(".popupmenu_centerbox").easydrag(true);


    });

}
function popupedit(cid, cdiv) {
    $("#append_parent").load("cp_comment.aspx?cid=" + cid + " #edit" + cid, {
        "cid": cid,
        "username": "syj"
    },
    function()
    {
        setPopupPosition(cdiv,"edit"+cid,0);
        //setCenter("edit" + cid);
        $(".popupmenu_centerbox").easydrag(true);
        $(".popupmenu_centerbox").setHandler('drag_title');


    });

}





function EditComment(cid)
 {
    //showHintAutoClose("你发言太快了");
    var message = $("#message_" + cid).val() == "undefined" ? "": $("#message_" + cid).val();
    
    message = valueReplace(message);
    
    var ocid = cid;
    //var jsonData =  "{message :'"+message+"'}";
    var jsonData = "{message :'" + message + "', ocid :'" + ocid + "'}";
    $("#editsubmit_btn").attr("disabled",true); 



    $.ajax({
        type: "POST",
        url: "cp_comment.aspx/Editcomment",
        data: jsonData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
        
         
        
             $("#editsubmit_btn").removeAttr("disabled"); 

            if (msg == "nologin")
            {
                NewshowHintAutoClose("信息提示", "该操作需要登陆，请先登陆");

            }
            else
            {


                if (msg == "too_short_3") {
                    alert("对不起，你输入出的信息必须要多于3个字符");
                    return;


                }
                if (msg == "nopose")
                {
                    alert("你发言太快了");

                }
                else
                {
                     
                    NewshowHintAutoClose("信息提示", "修改成功!!!!!");
//                    window.location.reload();

                    $("#comment_"+cid).html(msg);
                    //location.href="space_wall.aspx?uid=<%=JJudge.uid %>"; 


                }


            }


        }

    });




}







function ReplyComment(cid)
 {
    //showHintAutoClose("你发言太快了");
    var message = $("#message_pop_" + cid).val() == "undefined" ? "": $("#message_pop_" + cid).val();
    
     message =  valueReplace(message);

    
    
    var ocid = cid;
    //var jsonData =  "{message :'"+message+"'}";
    var jsonData = "{message :'" + message + "', ocid :'" + ocid + "'}";
    
    $("#commentsubmit_btn").attr("disabled",true);

    $.ajax({
        type: "POST",
        url: "cp_comment.aspx/ReplyComment",
        data: jsonData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
         $("#commentsubmit_btn").removeAttr("disabled"); 

            if (msg == "nologin")
            {
                NewshowHintAutoClose("信息提示", "该操作需要登陆，请先登陆");

            }
            else
            {


                if (msg == "too_short_3") {
                    alert("对不起，你输入出的信息必须要多于3个字符");
                    return;


                }


               if (msg.indexOf("nopose")>=0)     
               { 
                 var interval = msg.substring(msg.indexOf("_")+1);
                 alert("你发言太快了,请等待 "+interval+"秒后再发言!");
               }
                else
                {
                    NewshowHintAutoClose("信息提示", "你已经成功给留言");
                    //为相册评论而加,不重新刷新看不到回复的内容 20091004 jwang
//                    window.location.reload();
                    //location.href="space_wall.aspx?uid=<%=JJudge.uid %>"; 
                    $("#comment_ul").append(msg);
                    
//                      $(msg).appendTo($("#comment_ul"));
                    


                }


            }


        }

    });




}


function DeleteComment(cid)
 {

    var ocid = cid;
    var jsonData = "{ocid :'" + ocid + "'}";


    $.ajax({
        type: "POST",
        url: "cp_comment.aspx/DeleteComment",
        data: jsonData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
       
            if (msg == "nologin")
            {
          
                NewshowHintAutoClose("信息提示", "该操作需要登陆，请先登陆");

            }
            else
            {
                NewshowHintAutoClose("信息提示", "删除成功!!!!!");
                
//                 $("#comment").remove("#comment_"+ocid+"_li");

 $("#comment_"+ocid+"_li").remove();
                     
             //   window.location.reload();
                // location.href="space_wall.aspx?uid=<%=JJudge.uid %>";


            }

        }

    });


}



///////////////////////////////////////////////////////////////////////////////////留言操作 end 
