// JScript 文件
var CurrentPage = 1;//分页，默认为1，即为第一页 
var isLogin = $("#hidIslogin").val();//是否登录
var strImgDoMain = strFelissimo_ImgDomain;//图片站点域名
var strSort = "0";//排序
$(function(){
    AjaxMethod(); 
    //分页(点击序号)
    $("#divpage").find("div").live("click",function(){
       CurrentPage = $(this).attr("value");
       if(CurrentPage==null)
       {
            CurrentPage = $(this).attr("value");
       } 
       else
       {
           AjaxMethod();
           $("#top").ScrollTo(1200);
       }
    });
    //排序
    SortBy();
    //鼠标悬停小图时，弹出层
    $(".commuProductPic img").live("mouseover",
        function() {
            $("#loading").show();
            $("#imgMidPic").css("border","none")
            //商品的品牌、大类
//            var strBrandNo = $(this).attr("brand-no");
//            var strBreedNo = $(this).attr("breed-no");
//            if (String(strBrandNo) == "60"){ strBrandNo = "SUNNY CLOUDS";
//            } else if (String(strBrandNo) == "106") {  strBrandNo = "HARAPPA";
//            } else {
//                var _strBreedNo = String(strBreedNo);
//                if (_strBreedNo != "1" && _strBreedNo != "3" && _strBreedNo != "10" && _strBreedNo != "13") {
//                    strBrandNo = "kraso";
//                } else { strBrandNo = "FELISSIMO"; }
//            }
            //img的位置
            var currImgPos = $(this).position();
            $(".listMidPicSlide").css("left", currImgPos.left +100);
            $(".listMidPicSlide").css("top", currImgPos.top - 100);
            var midPicPath = $(this).attr("mid-pic");
            var loadingPicPaht = strImgDoMain+"/images_v7/NewIndex/loading.gif";
            $(".listMidPicSlide img:last").removeAttr("src");
            $(".listMidPicSlide").stop(true, true).fadeIn("normal");
            
            $(".listMidPicSlide img:last").attr("src", midPicPath);
            //$(".listMidPicSlide p:eq(0)").html(strBrandNo);
            $(".listMidPicSlide p:eq(2)").html($(this).parent().attr("title1"));
     });
     //评论回复
     CommentReply();
     //上月活跃会员
     $("#viewLastMonth").click(function(){
        var obj = $("#ActiveMem1_ulLastMonthActive");
        if( $.trim( obj.html() )!="" )
        {
            obj.slideToggle();
        }
    });
    //弹出登陆框
    popLogin();
});

/***************************/
//描述:显示会员秀列表			
/***************************/
function AjaxMethod()
{
   $("#divDiscussList").html("");
   $.ajax({
    type: "POST",
    url: "/AjaxRequest/AqCustomersDiscussList.aspx",
    data: "CurrentPage="+CurrentPage+"&PageSize=15&SortType="+strSort,
    dataType: "html",
    beforeSend:function(){
            $("#divCommentListLoading").show();
    },
    success: function(msg){
        if(msg == "nothing"){
            $("#divDiscussList").html("<p>暂时没有评论</p>");
        }
        else{
         $("#divDiscussList").html(msg);
         $("#divDiscussList").html($("#divDiscussList #tag").html());
         $("#divpage").attr("style","float:left;");
         $("#divPageHtml table:first").width("630px");
        }
        $("#divCommentListLoading").hide();
    }                  
});    
}	
/***************************/
//描述:鼠标悬停小图时，弹出层的loading			
/***************************/
function hideLoading() {
  $("#loading").hide();
  $("#imgMidPic").css("border","1px solid #ccc");
  $("#imgMidPic").show();
}
/***************************/
//描述:鼠标离开小图时，隐藏弹出层			
/***************************/
function HideMidPic()
{
  var obj = document.getElementById("PopMidPic");
  obj.style.display= "none";
}
/***************************/
//描述:评论回复相关		
/***************************/
var CommentReply =function(){

    if (isLogin == "1") //登陆状态下
    {
        $("#divReply tr:lt(3)").addClass("hide");
        //发表无关联商品评论
        $("#publishTopic").hide();
        $("#pulishEnter").show();
    }
    else
    {
        //发表无关联商品评论
        $("#publishTopic").show();
        $("#pulishEnter").hide();
    }
    //评论回复
    $("a[group='replyButton']").live("click",
    function() {
        var isNoReply = $.trim( $(this).attr("no-reply") );
        if(isNoReply!="1")
        {
            $(this).parent().next().html($("#divReply").html()).show();
            $(this).parent().next().find("p[class='commentGo fly'] a").attr("key", $(this).attr("key"));
        }
        else
        {
             $(this).parent().next().html("<p class=redAlert>此贴已被管理员设置为禁止回复</p>").show();
        }
    });
    //取消回复
    $(".commentCancle a").live("click",
    function() {
        //$(this).parent().parent().parent().parent().parent().slideUp("slow");
        $(this).parent().parent().parent().parent().parent().parent().hide();
    });
    //发表回复
    $("p[class^='commentGo'] a").live("click",
    function() {
        var strCommentId = $(this).attr("key");
        var strEmail = $.trim($(this).parent().parent().parent().parent().siblings().find("input[name='txtEmail']").val()); //邮箱
        var strName = $.trim($(this).parent().parent().parent().parent().siblings().find("input[name='txtName']").val()); //昵称
        var strContent = $.trim($(this).parent().parent().parent().parent().siblings().find("textarea[name='txtReplyContent']").val()); //回复内容

        if (isLogin == "1") //已登录
        {
            if (strContent == "") {
                alert("请填写回复内容!");
                return;
            }
        } else //未登录
        {
            if (strEmail == "") {
                alert("请填写您的邮箱地址!");
                return;
            } else {
                var myRegex = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
                if (!myRegex.test(strEmail)) {
                    alert("电子邮箱格式不正确!");
                    return;
                }
            }
            if (strName == "") {
                alert("请填写您的昵称!");
                return;
            }
            if (strContent == "") {
                alert("请填写回复内容!");
                return;
            }
        }
        if (strContent.length > 500 ) {
            alert("回复内容过长!");
            return;
        }

        $.ajax({
            type: "POST",
            url: "/AjaxRequest/AqProductCommentReply.aspx",
            data: "CommentId=" + escape(strCommentId) + "&IsLogin=" + escape(isLogin) + "&Email=" + escape(strEmail) + "&Name=" + escape(strName) + "&Content=" + escape(strContent),
            dataType: "html",
            success: function(msg) {
                if (msg == "error") {
                    alert("服务器正忙，请稍后再试!");
                } else if (msg == "ok") {
                    //alert("回复成功，将来会跳到具体的评论页");
                    document.location = "/Community/Topic_"+strCommentId+"/";
                } else {
                    alert(msg);
                }
            }
        });

    });
}

/***************************/
//描述:评论排序
/***************************/
var SortBy = function()
{
    $(".commuOrderBy a").live("click",function(){
        strSort = $(this).attr("sort");
        if(strSort=="0")
        {
            $(".commuOrderBy p").html("<span class='gray'>帖子排序: </span><span class='dateNum'>@</span> <span>最新发表 </span><span class='dateNum'>@</span> <a class='commuLinkS' sort='1' href='#here'>最新回复 </a><span class='dateNum'>@</span> <a class='commuLinkS' sort='2' href='#here'>最近热帖</a>");
        }
        else if(strSort=="1")
        {
            $(".commuOrderBy p").html("<span class='gray'>帖子排序: </span><span class='dateNum'>@</span> <a class='commuLinkS' sort='0' href='#here'>最新发表 </a><span class='dateNum'>@</span> <span>最新回复 </span><span class='dateNum'>@</span> <a class='commuLinkS' sort='2' href='#here'>最近热帖</a>");
        }
        else
        {
            $(".commuOrderBy p").html("<span class='gray'>帖子排序: </span><span class='dateNum'>@</span> <a class='commuLinkS' sort='0' href='#here'>最新发表 </a><span class='dateNum'>@</span> <a class='commuLinkS' sort='1' href='#here'>最新回复 </a><span class='dateNum'>@</span> <span>最近热帖</span>");
        }
        CurrentPage=1;
        AjaxMethod();
    });
}