﻿
var commentJS = {
    allCommentInit:function(){
        (function($){
            if(popProductSN=="")
        {
            checkData();
	        return false;
        }

        var indexID="0";var commentID="0";var isCommend="0";var title="0";var content="0";var time="0";var childCount="0";var availCount="0";
        var notAvailCount="0";var userID="0";var siteID="0";
        var listType = $("#hidCommentType").val();
        var meunpid= getmenupid();
        total_page=total_record=0;
        allComment="";
        
        $.get("/cpage/SendComment.aspx",{net4:Math.random(),rtype:1,list:listType,type:3,pageSize:pageSize,page:currentPage,productSN:popProductSN},function(rdata){
            try
            {
				if(rdata==null || rdata=="()")
	            {
	                checkData();
		            return false;
	            }

	            var data = 	eval('(' + rdata + ')');
	            $("lblzw").remove();
	            
                for(var i=0;i<data.list.length;i++)
                {
                    allComment="";
                    indexID = data.list[i].IndexID;
                    commentID=data.list[i].CommentID;
                    isCommend = data.list[i].IsCommend;
                    title = data.list[i].Title;
		            title = title.replace("泡泡网友点评","IT168网友点评");
                    content = data.list[i].Content;
                    time = data.list[i].Time;
                    childCount = data.list[i].ChildCount;
                    availCount = data.list[i].AvailCount;
                    notAvailCount = data.list[i].NotAvailCount;
                    userID=data.list[i].UserID;
                    siteID=data.list[i].SiteID;
                    
                    allComment+="<div class='w713'><div class='pl_l1'><img src='";
                    if(siteID=="1" && userID>0)
                    {
                        allComment+="http://my.it168.com/mycenter/avatar.php?uid=" + userID + "&size=small";
                        if(userID>0)
                        {
                            allComment+="' alt='进入个人空间' style='cursor:pointer'";
                            allComment+=" onclick='window.open(\"http://my.it168.com/home.php?uid=" + userID + "\");";
                        }
                    }
                    else
                    {
                        allComment+="/detail/images/ddp/112.gif";
                    }
                    
                    allComment+="' width='57' height='48'></div><div class='pl_r1'>";
                    allComment+="<div class='tit3'><a target='_self' href='" + targetURL + "indexId=" + indexID + "&productSN=" + popProductSN + "&topicId=" + commentID + "'>" + title + "</a></div><div class='w625'> <span>";
                    if(siteID=="1" && userID>0)
                    {
                        var nval="<a target='_black' href='http://my.it168.com/home.php?uid=" + userID + "' netfir='netfir' style='color:Blue' uid='" + userID + "' id='search_"+ getmenupid()+ "_" + userID + "'>IT168网友</a>";
                        allComment+=nval;
                    }
                    else
                    {                        
                        allComment+="IT168网友";
                    }
                    
                    for(var x=0;x<(isCommend+2);x++)
                    {
                        allComment+="<img src='/detail/images/ddp/xing.gif'>";
                    }
                    allComment+="</span>";
                    content=substr(content,200,"<a target='_self' href='" + targetURL + "indexId=" + indexID + "&productSN=" + popProductSN + "&topicId=" + commentID + "'>查看全部</a>");
                    allComment+="<p>" + content + "</p>";
                    allComment+="<span><div class='w310'>发表于 " + time + "　<a target='_self' href='" + targetURL + "indexId=" + indexID + "&productSN=" + popProductSN + "&topicId=" + commentID + "'>" + (Number(childCount)>0?childCount:'') + "回复</a></div><div class='w210'>此评论对我的购买：<a href='javascript:void(null);' onclick='abetTopic(this,1," + indexID + "," + commentID + "," + availCount + "," + notAvailCount + ")'><img src='/detail/images/ddp/youyong.gif' align='absmiddle'></a> <a href='javascript:void(null);' onclick='abetTopic(this,0," + indexID + "," + commentID + "," + availCount + "," + notAvailCount + ")'>没用</a></div><div id='topic_com' class='w105'>" + availCount + "/" + (availCount+notAvailCount) + "人有用</div></span></div></div><div class='clear'></div></div>";
                    
                    $("#tab5Cont"+meunpid).append(allComment);
                    $("#hidIndexID").val(indexID);
                    
                    getUserNames(i);
                }
                total_page =data.total_page;
                total_record = data.total_record;
            }
            catch(err)
            {
                allComment="";
            }
            
            if(total_page>0)
            {
                $("#tab5Cont"+meunpid).append(getPager(total_page,total_record,currentPage,listType));
            }
			var localURL=window.location.href;
			if(localURL.indexOf('ping')>0)
			{
				document.title="产品点评列表";
				window.location.href="#ping";
			}
　        });
　        
        return allComment;
        })(jQuery)        
    }
};


function checkData()
{
    var state="";
    var meunpid = getmenupid();

    switch(meunpid)
    {
        case 1:
            state="产品评论";
            break;
        case 2:
            state="精华评论";
            break;
        case 3:
            state="产品评论";
            break;
        case 4:
            state="优点评论";
            break;
        case 5:
            state="缺点评论";
            break;
    }
    
    (function($){
    $("#lblAjaxLoad").hide();
    allcomment="暂无"+pinfo+state;
    $("#tab5Cont"+meunpid).html("<div id=\"lblzw\" style=\"padding:20px;width:700px;color:gray;text-align:center\">" + allcomment + "</div>");
    })(jQuery)
}

$(function(){
(function($){
//popProductSN=$("#hidProductSN").val();

    $("#txt_title").val("");
    $("#textarea").val("");    
    
    $("#lblAjaxLoad").ajaxStop(function(){
       $(this).hide();   
    });
    $("#lblAjaxLoad").ajaxError(function(){
        $(this).hide();   
    });
    $("#lblAjaxLoad").ajaxComplete(function(){
        $(this).hide();   
    });
    $("#lblAjaxLoad").ajaxSuccess(function(){
        $(this).hide();   
    });

    if (window.navigator.userAgent.indexOf("Firefox")>=1)
    {
        //commentJS.allCommentInit();
    }
    
    $("#tab5_"+menuid).click();

    // 用户发表评论区块
    var currentUserId=$("#hidUserId").val();
    $("#pl_login").hide();
    $("#logginginSay").show();
    $("#atcdll").hide();

    if(Number(currentUserId)>1)
    {
        $("#currentUN").html($("#hidUserName").val());
        $("#currentUN").attr("href","http://my.it168.com/home.php?uid="+currentUserId);
        $("#currentUN").css("color","#0A61D7");
        $("#currentUN").css("text-decoration","underline");
        $("#logginginSay").hide();
        $("#aljzcc").hide();
        $("#atcdll").show();
        $("#currentUP").attr("src","http://my.it168.com/mycenter/avatar.php?uid=" + currentUserId + "&size=small");
        $("#currentUP").attr("alt","进入个人空间");
        $("#currentUP").css("cursor","pointer");
        
        $("#currentUP").click(function(){
            window.open("http://my.it168.com/home.php?uid="+currentUserId);
        });
    }

    $("[@class='price']").attr("target","_blank");
    $("[@class='r']").attr("target","_blank");
    $("[@class='blue']").attr("target","_blank");
    $("[@class='t3']").find("a").attr("target","_blank");
    $("[@class='pl_r2']").find("a").attr("target","_blank");
    $("[@class='pl_more']").find("a").attr("target","_blank");
    })(jQuery)
});
    
function getmenupid()
{
    var listType = "all";
    (function($){listType = $("#hidCommentType").val();})(jQuery)    
    var id=1;
    
    switch(listType)
    {
        case "all":
            id=1;                        
            break;
        case "best":
            id=2;
            break;
        case "new":
            id=3;
            break;
        case "good":
            id=4;
            break;
        case "bad":
            id=5;
            break;
        default:
            id=1;
    }

    return id;
}
    
function logginout()
{
    logout1();
    (function($){
    $("#pl_login").hide();
    $("#logginginSay").show();
    $("#aljzcc").show();
    $("#atcdll").hide();
    $("#currentUP").attr("src","/detail/images/ddp/112.gif");
    $("#currentUP").click(function(){return false;});
    $("#currentUN").attr("href","javascript:void(null)");
    $("#currentUN").css("color","gray");
    $("#currentUN").css("text-decoration","none");
    $("#currentUN").html("IT168网友");
    $("#currentUP").attr("alt","");
    })(jQuery)
}

function logout1() {
    (function($){
        $.getJSON("http://sso.it168.com/logout.php?net4=" + Math.random() + "&jsoncallback=?",function(data){
    
        });
    
        $("#itcp").attr("src","http://sso.it168.com/Cookie?a=clear&c=js");
    })(jQuery)
}

    
function abetTopic(obj,operateNum,indexId,commendId,ac,nac)
{
    (function($){
    $.get("/cpage/SendComment.aspx", { rtype:2,type: 1, operateNum: operateNum,indexId:indexId,commentId:commendId,net4:Math.random() }, function(data){
        $("#lblAjaxLoad").hide();
        var val = eval('(' + data + ')');
        
        if(val.state==1)
        {
            if(operateNum==1)
            {
                $(obj).parent().parent().find("[@id='topic_com']").html((ac+1)+"/"+(ac+1+nac)+"人有用");
            }
            else
            {
                $(obj).parent().parent().find("[@id='topic_com']").html(ac +"/"+(ac+1+nac)+"人有用");
            }

            alert("提交成功~");
        }
        else
        {
            alert("您不能重复评论~");
        }
    });
    })(jQuery)
}
    
function getPager(total_page,total_record,currentPage,listType)
{
    var pageString="";
    var leftNum=currentPage-1>0?currentPage-1:currentPage;
    var rightNum = currentPage+1>total_page?total_page:currentPage+1;

    if(currentPage==1)
    {
        pageString+="<div style='width: 100%;'><div class='page'><a href='#imgp' style='color:gray' class='up' onclick='pagerClick(" + leftNum + ")'>&lt;前页</a>";
    }
    else
    {
        pageString+="<div style='width: 100%;'><div class='page'><a href='#imgp' style='color:#0A61D7' class='up' onclick='pagerClick(" + leftNum + ")'>&lt;前页</a>";
    }
    
    var setPage=currentPage-4>0?currentPage-4:1;
    
    for(var i=setPage,j=1;i<=total_page;i++,j++)
    {
        if(j>8)
        {
            pageString+="<div>…</div>";
            pageString+="<a href='#imgp' onclick='pagerClick(" + (total_page-1) + ")'>" + (total_page-1) + "</a>";
            pageString+="<a href='#imgp' onclick='pagerClick(" + total_page + ")'>" + total_page + "</a>";
            break;
        }
        else
        {
            if(i==currentPage)
            {
                pageString+="<a class='here' href='#imgp' onclick='pagerClick(" + currentPage + ")'><font color='#ffffff'>" + currentPage + "</font></a>";
            }
            else
            {
                pageString+="<a href='#imgp' onclick='pagerClick(" + i + ")'>" + i + "</a>";
            }
        }
    }

    if(currentPage==total_page)
    {
        pageString+="<a href='#imgp' style='color:gray' class='next' onclick='pagerClick(" + rightNum + ")'>后页&gt;</a><div>(共" + total_record + "条)</div></div><div class='clear'></div></div>";
    }
    else
    {
        pageString+="<a href='#imgp' class='next' style='color:#0A61D7' onclick='pagerClick(" + rightNum + ")'>后页&gt;</a><div>(共" + total_record + "条)</div></div><div class='clear'></div></div>";
    }
    
    return pageString;
}
    
function getUserNames(currentNum)
{
    var id = getmenupid();
    (function($){
    $("#tab5Cont"+id).find("[@netfir='netfir']").each(function(){
        var uid = $(this).attr("uid");
        if(uid>0)
        {
            try
            {
                $.getJSON("http://my.it168.com/api/WebProxy.php/User.getUsernameByUid.json/?uid="+uid+"&jsoncallback=?",function(user){
                    // $("#search_"+ id +"_"+user.userid).html(user.username);
                    
                    $("[@id='search_" + id + "_" + user.userid + "']").html(user.username);
                });
            }catch(err)
            {
                //$("#search_"+ id +"_"+user.userid).html("IT168网友");
            }
        }
        $(this).attr("uid","");
    });
    })(jQuery)
}
    
function pagerClick(page)
{
    (function($){
    $("#lblAjaxLoad").show();
    var meunpid= getmenupid();
    $("#tab5Cont"+meunpid).html("");
    })(jQuery)
    currentPage = page;
    commentJS.allCommentInit();
}
    
function substr(str, len, addStr) 
{
    if(!str || !len) { return ''; } 
    var a = 0;
    var i = 0;
    var temp = '';

    for (i=0;i<str.length;i++)
    {
        if (str.charCodeAt(i)>255)
        {
            a+=2;
        }
        else
        {
            a++;
        }

        if(a > len)
        {
            return temp+"…… "+addStr;
        }

        temp += str.charAt(i);
    }
    
    return str;
}
    
function loggingSay_click(state)
{
    if(state)
    {
        (function($){
        $("#logginginSay").hide();
        $("#pl_login").show();
        $("#aljzcc").hide();
        $("#d_user").focus();
        })(jQuery)
        
    }
    else
    {
        (function($){
        $("#logginginSay").show();
        $("#pl_login").hide();
        $("#aljzcc").show();
        })(jQuery)
    }
}
    
function publishComment_click()
{
    var returnState=true;
    var evaluate = undefined;
    (function($){evaluate = $("input[@name='IsCommend'][@checked]").val();})(jQuery)    
    var title= "";
    (function($){title = $("#txt_title").val();})(jQuery)
    title = title.replace(/[ ]/g,"");
    var commmentStr = "";
    (function($){commmentStr = $("#textarea").val();})(jQuery)
    commmentStr = commmentStr.replace(/[ ]/g,"");
    commmentStr = commmentStr.replace(/[\r\n]/g,"");

    // CreateValidImg
    var code_v = "";
    (function($){code_v = $("#tbx_validate").val();})(jQuery)
    var val="";
    try
    {
        (function($){val = $.ajax({type: "POST",async:false,url: "/cpage/CreateValidImg.aspx",data:"code="+ code_v +"&net4="+Math.random()}).responseText;})(jQuery)
    }catch(err)
    {}

    if(getlen(title)<10)
    {
        alert("请输入标题，最少10个字符~");
        returnState=false;
        return false;
    }
    else
    {
        var title_len = getlen(title);
        
        if(title_len > 58)
        {
            alert("输入标题过长~");
            returnState=false;
            return false;
        }
        else
        {
            if(funcChina(title))
            {
                alert("标题请包含中文~");
                returnState=false;
                return false;
            }
        }
    }

    if(evaluate==undefined)
    {
        alert("请选择评价~");
        returnState=false;
        return false;
    }

    if(getlen(commmentStr)<10)
    {
        alert("请输入内容，最少10个字符~");
        returnState=false;
        return false;
    }
    else
    {
        if(funcChina(commmentStr))
        {
            alert("不包含中文~");
            returnState=false;
            return false;
        }
    }

    if(val!="true")
    {
        alert("验证码不正确~");
        returnState=false;
        (function($){$("#img_val").attr("src","/cpage/CreateValidImg.aspx?net4="+Math.random());})(jQuery)
        return false;
    }

    {
        (function($){
        $("#txt_title_2").val(escape(title));
        $("#textarea_2").val(escape(commmentStr));
        })(jQuery)
    }

    return returnState;
}
    
function funcChina(val){
    if(/.*[\u4e00-\u9fa5]+.*$/.test(val))    
    {
        return false;    
    }
     
    return true;    
}
    
function getlen(str)
{
    var len = str.length;
    var count=0;

    for(var i=0;i<len;i++)
    {
        if(str.charCodeAt(i)>126 || str.charCodeAt(i)<27)
        {
            count+=2;
        }
        else
        {
            count++;
        }
    }

    return count;
}


function loggingin()
{
    // var form = document.forms['form1'];
    // form.action="http://sso.it168.com/loginIt168.php?return_url="+window.location.href;
    //  form.target = "_parent";
    //执行SUBMIT 
    //  form.submit(); 
    (function($){
    var uname=$("#d_user").val();
    var upwd=$("#d_pass").val();
    document.domain='it168.com';

    $.getJSON("http://sso.it168.com/loginpcpop.php?login_name=" + uname + "&password=" + upwd + "&jsoncallback=?",function(data){
        if(data.message!=1)
        {
            alert("用户名或密码不正确!");
        }
        else
        {
            window.location.reload();
        }
    });
    })(jQuery)
}



$(function(){
 //   var popProductSN = $("#hidProductSN").val();
    if(popProductSN=="")
    return false;
    // 加载右侧排行

    try{
    (function($){
        $.getJSON(dataURL+"?net4="+Math.random()+"&list=best&type=3&pageSize=10&page=1&ProductSN=" + popProductSN + "&jsoncallback=?",function(data){
            var indexID="0";var commentID="0";var isCommend="0";var title="0";var content="0";var time="0";var childCount="0";var availCount="0";
            var notAvailCount="0";var userID="0";var siteID="0";
            if(data==null)
                return false;
            for(var i=0;i<data.list.length;i++)
            {
                indexID = data.list[i].IndexID;
                commentID=data.list[i].CommentID;
                isCommend = data.list[i].IsCommend;
                title = data.list[i].Title;
                title = title.replace("泡泡网友点评","IT168网友点评");
                content = data.list[i].Content;
                time = data.list[i].Time;
                childCount = data.list[i].ChildCount;
                availCount = data.list[i].AvailCount;
                notAvailCount = data.list[i].NotAvailCount;
                userID=data.list[i].UserID;
                siteID=data.list[i].SiteID;
                var str = "<li><a title='" + title + "' target='_self' href='/cpage/NewRevertComment.aspx?indexId=" + indexID + "&productSN=" + popProductSN + "&topicId=" + commentID + "'>";
                title = substr(title,28,"");
                str+= title + "</a></li>";
                $("#listBest").append(str);
            }
        });

        $.getJSON(dataURL+"?net4="+Math.random()+"&list=good&type=3&pageSize=10&page=1&ProductSN=" + popProductSN + "&jsoncallback=?",function(data){
            var indexID="0";var commentID="0";var isCommend="0";var title="0";var content="0";var time="0";var childCount="0";var availCount="0";
            var notAvailCount="0";var userID="0";var siteID="0";
            if(data==null)
                return false;
            for(var i=0;i<data.list.length;i++)
            {
                indexID = data.list[i].IndexID;
                commentID=data.list[i].CommentID;
                isCommend = data.list[i].IsCommend;
                title = data.list[i].Title;
                title = title.replace("泡泡网友点评","IT168网友点评");
                content = data.list[i].Content;
                time = data.list[i].Time;
                childCount = data.list[i].ChildCount;
                availCount = data.list[i].AvailCount;
                notAvailCount = data.list[i].NotAvailCount;
                userID=data.list[i].UserID;
                siteID=data.list[i].SiteID;

                var str = "<li><a title='" + title + "' target='_self' href='/cpage/NewRevertComment.aspx?indexId=" + indexID + "&productSN=" + popProductSN + "&topicId=" + commentID + "'>";
                title = substr(title,28,"");
                str+= title + "</a></li>";
                $("#listgood").append(str);
            }
        });

        $.getJSON(dataURL+"?net4="+Math.random()+"&list=bad&type=3&pageSize=10&page=1&ProductSN=" + popProductSN + "&jsoncallback=?",function(data){
            var indexID="0";var commentID="0";var isCommend="0";var title="0";var content="0";var time="0";var childCount="0";var availCount="0";
            var notAvailCount="0";var userID="0";var siteID="0";
            if(data==null)
                return false;
            for(var i=0;i<data.list.length;i++)
            {
                indexID = data.list[i].IndexID;
                commentID=data.list[i].CommentID;
                isCommend = data.list[i].IsCommend;
                title = data.list[i].Title;
                title = title.replace("泡泡网友点评","IT168网友点评");
                content = data.list[i].Content;
                time = data.list[i].Time;
                childCount = data.list[i].ChildCount;
                availCount = data.list[i].AvailCount;
                notAvailCount = data.list[i].NotAvailCount;
                userID=data.list[i].UserID;
                siteID=data.list[i].SiteID;

                var str = "<li><a title='" + title + "' target='_self' href='/cpage/NewRevertComment.aspx?indexId=" + indexID + "&productSN=" + popProductSN + "&topicId=" + commentID + "'>";
                title = substr(title,28,"");
                str+= title + "</a></li>";
                $("#listbad").append(str);
            }
        });
        })(jQuery)
    }catch(erre)
    {}

    getProductCommend(cSpace_Code, 0, 75);
    getPriceHtml(cSpace_Code,"","","1",_gObj("div_cityPrice"));
});