function _getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var scriptEle=document.getElementById("_comment_js");
    if(scriptEle == null) return null;
    src=scriptEle.src;
    var r = src.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}

var newsId = _getQueryString('newsId');
var channelId = _getQueryString('channelId');

            DWREngine.setMethod(DWREngine.ScriptTag);
            dwr.engine._defaultPath=$("#basePath").val()+"dwr";
            dwrDAO._path=$("#basePath").val()+"dwr";
            AddDingAction._path=$("#basePath").val()+"dwr";
            $.post("http://vote.ijjnews.com:9000/comment/comment/NewsCommentAction!listDoJTemplate.do?svo.channelId="+channelId+"&svo.newsId="+newsId,{},
                function (data) {
                // 附上模板
                $("#message").setTemplateElement("template");
                $("#message").setParam("repl",replace_em);
                // 给模板加载数据
                $("#message").processTemplate(data);
                $(".comment_count").text(data.allCmt);
            },"json");
        var $followdiv=$(".item-level2-li");
		// 跟帖楼层太多的话 则隐藏 只显示1楼 点击展开全部评论
        $(".follow").each(function (i,follow) {
            if ($(this).find($followdiv).length>5) {
                $($(this).find($followdiv)).hide();
                var floorCnt = $(this).find($followdiv).length-1;
                var floorId=$(this)[0].id;
                var $last = $(this).find($followdiv).last();
                var firstdiv = '<div class="item-level2-li" >'+$($last).html()+'</div>'
                var hidediv='<div class="item-level2-li" id="hide">'+firstdiv+'<a href="javascript:void(0);" onclick="showFloor('+floorId+',hide)">已隐藏'+floorCnt+'层盖楼 点击展开</a></div>';
                $(this).append(hidediv);
                $(firstdiv).prependTo(hidediv);
            }
        });

	// 判断是否登录
    var isLogin=true;
    function get_login_info_back(data){
        if(data.indexOf("login_fail")<0){
            $("#login").show();
            $("#no_login").hide();            
            isLogin=true;
            var str = data.split("|");
	    uid = str[0];
	    $(".userCenter").attr("href",'http://comment.haval.com.cn:8080/comment/regist.action?act=userCenter');
	    $(".logout").attr("href",'http://comment.haval.com.cn:8080/comment/regist.action?act=logout&url=' + window.location.href);
	    $(".headImg").attr("src",'http://121.42.28.136/uc_server/avatar.php?uid=' + uid + '&type=real&size=middle');
            name = str[1];
	    $(".userName").html(name);
	    script = str[2]; 
	    $("#script").html(script);
            $("#userId").val(str[3]);
            $("#userName").val(str[4]);
        } else {
            $("#login").hide();
            $("#no_login").show();
        }
    }
		// 展开全部评论
        function showFloor(floorId,firstid) {
        var $followdiv=$(".item-level2-li");
        $($(floorId).find($followdiv).get(0)).show();
        $(firstid).hide();
    }

    function changeImg(bathPath) {
        $(".kaptchaImage").hide().attr('src',bathPath+'kaptcha.jpg?' + Math.floor(Math.random() * 100)).fadeIn();
    }
        // 赞
    function add(cmtId) {
        AddDingAction.addDing(cmtId,dingCallBack(cmtId));
    }

    // 赞回调函数
    function dingCallBack(cmtId) {
        $("#ding"+cmtId).text(parseInt($("#ding"+cmtId).text())+1);
        dingjia1(cmtId);
        setTimeout('dingjia1('+cmtId+')', 800);
        $("#dingS"+cmtId).unwrap();
    }

    // 回复
    function replay(cmtId) {
        $("#replay"+cmtId).toggle('normal');
    }

    function dingjia1(cmtId){
        $("#dingjia1"+cmtId).toggle('normal');
    }

    function checkActive() {
        if($("#remerberI").hasClass("active")) {
            $("#remerberI").removeClass("active");
        } else {
            $("#remerberI").addClass("active");
        }
    }
	// 发布评论 判断是否登录 且输入字数大于等于5个字
    function addComment(cmtId,obj) {
        if (!isLogin) {
            if (cmtId!=null) {
                $(".LoginPopUP").css("top",$(document).scrollTop()+(window.screen.height/2)-50);
            }
            $(".PopLayout,.LoginPopUP").show();
            return;
        }
        if (cmtId!=null) {
            if ($("#content"+cmtId).val()=='' || $("#content"+cmtId).val()==null || $("#content"+cmtId).val().length<5) {
                alert("请至少输入5个字");
                return;
            }
            //if (data.showImgCode=='true' && ($("#imgText"+cmtId).val()==null || $("#imgText"+cmtId).val()=='')) {
                //alert("请填写验证码");
                //return;
            //}
            $("#cmt"+cmtId).val(encodeURI($("#content"+cmtId).val()));
            $("#deCodeUserId"+cmtId).val($("#userId").val());
            //$("#userType"+cmtId).val($("#userName").val());
            $("#newtitle"+cmtId).val(window.encodeURIComponent($("#newtitle"+cmtId).val()));
            $("#form"+cmtId).attr("action",$("#postUrl").val());
            $.ajax({
                type: 'post',
                url: $("#postUrl").val(),
                dataType:'json',
                async: false,
                data: $("#form"+cmtId).serialize(),
                success: function(data) {
                    if (data.audit!=null || data.audit!=undefined) {
                        alert(data.audit);
                    }
                   window.location.reload();
                }
            });
        } else {
            if ($("#content").val()=='' || $("#content").val()==null || $("#content").val().length<5) {
                alert("请至少输入5个字");
                return;
            }
            //if (data.showImgCode=='true' && ($("#imgText").val()==null || $("#imgText").val()=='')) {
                //alert("请填写验证码");
                //return;
            //}
            $("#cmt").val(encodeURI($("#content").val()));
            $("#deCodeUserId").val($("#userId").val());
            //$("#userType").val($("#userName").val());
            $("#newtitle").val(window.encodeURIComponent($("#newtitle").val()));
            $("#form").attr("action",$("#postUrl").val());
            $.ajax({
                type: 'post',
                url: $("#postUrl").val(),
                dataType:'json',
                async: false,
                data: $("#form").serialize(),
                success: function(data) {
                    if (data.audit!=null || data.audit!=undefined) {
                        alert(data.audit);
                    }
                   window.location.reload();
                }
            });
        }
    }

    function closePop() {
        $(".PopLayout,.LoginPopUP").hide();
    }

    //查看结果
    function replace_em(str){
        str = str.replace(/\</g,'<');
        str = str.replace(/\>/g,'>');
        str = str.replace(/\n/g,'<br/>');
        //str = str.replace(/\[em_([0-9]*)\]/g,'<img src="http://comment.haval.com.cn:8080/comment/js/QQFace/arclist/$1.gif" border="0" />');
        return decodeURIComponent(str);
    }

    function tip(cmtId) {
        var contentlen=5;
        if (cmtId==null) {
            if ($("#content").val().length>=5) {
                contentlen=0;
            } else {
                contentlen=contentlen-$("#content").val().length;
            }
            $("#tip").text(contentlen);
        } else {
            if ($("#content"+cmtId).val().length>=5) {
                contentlen=0;
            } else {
                contentlen=contentlen-$("#content"+cmtId).val().length;
            }
            $("#tip"+cmtId).text(contentlen);
        }
    }
     // 跳转到评论更多页
    function seeMoreCMT(path) {
        window.open(path+"comment/CommentAction!listDo.do?svo.channelId="+$('#channelIdOrign').val()+"&svo.newsId="+$('#newsIdOrign').val()+"&postString="+window.encodeURIComponent($(".crumb").html())+"&title="+window.encodeURIComponent($("#_news_title").val()));
    }
