﻿
function showDetailBox(B) { if (B == 1) { showDetailBoxEx(1, B); } else { showDetailBoxEx(0, B) } return false }


function showDetailBoxEx(E, C) {
    var D = null;
    var B = null;
    for (var A = 1; A <= 10; A++) {
        D = $("#id_boxnavimenu_" + String(A));
        B = $("#id_boxcontents_" + String(A));
        if ((D.length > 0) && (B.length > 0) && (A != C)) {
            D.attr("class", "");
            if (E == 0) {
                B.attr("class", "DetailInfoHidden")
            } else {
                B.attr("class", "DetailInfo")
            }
        } else {
            if (A == C) {
                D.attr("class", "MenuOn"); B.attr("class", "DetailInfo")
            }
        }
    }
}


$(document).ready(function() {
    var img = "";

    $("#spanProductColor  img").each(function(i) {
        if (i % 2 == 1) {
            img = "<img src='" + $(this).attr("src") + "' onclick=\"getSize('',this.id)\" id=\"" + $(this).attr("id") + "\"  width=15 height=15 class=\"img\" />&nbsp;";
            if (i == 1) {
                getSize("", $(this).attr("id"));
                $("#spanSelectColor").html("<img src='" + $(this).attr("src") + "' width=15 height=15 class=\"img\" />");
            }
            $("#AssembleBuyProductColor").append(img);
        }
    });


    $("#spanBaleProductColor img").each(function(i) {
        if (i == 0) {
            getSize("2", $(this).attr("id"));
            $("#spanSelectColor2").html("<img src='" + $(this).attr("src") + "' width=15 height=15 class=\"img\" />");
        }
        img = "<img src='" + $(this).attr("src") + "' onclick=\"getSize('2',this.id)\" id=\"" + $(this).attr("id") + "\"  width=15 height=15 class=\"img\" />&nbsp;";
        $("#AssembleBaleBuyProductColor").append(img);
    });

    //最佳组合
    $(".assembleBuy").click(function() {
        OpenMessageBox("control:divAssembleBuy" + $(this).attr("ID") + ";width:400;height:250;title:最佳组合");

    });




    //添加到藏夹  
    $("#butCollect").click(function() {
        if (isLogin()) {
            $.ajax({ type: "POST", url: "/Collect/Create.html", data: "product_id=" + product_id, success: function(xml) {
                alert(xml);
            }
            });
        }

    });


    //降价提醒  
    $("#btnDepreciateNotify").click(function() {

        if (isLogin()) {
            $.ajax({ type: "POST", url: "/DepreciateNotify/Create/" + product_id + ".html", data: "", success: function(xml) {
                alert(xml);
            }

            });
        }

    });


    $('#butQuestion').click(function() {
        var questionScore = $("#questionScore").attr("value");
        var product_id = $("#ProductID").attr("value");
        var questionContent = $("#questionContent").attr("value");
        if (questionScore >= 0 && questionContent != "") {
            if (isLogin()) {

                $.ajax({ type: "POST", url: "/Question/Create.html", data: "product_id=" + product_id + "&questionScore=" + questionScore + "&questionContent=" + questionContent, success: function(xml) {
                    alert(eval(xml));
                    $("#listAnswer").html("");
                    listQuestion();
                    $("#countQuestion").html(parseInt($("#countQuestion").html()) + 1);
                }
                });


            }


        }
        else {
            alert("请填写正确的数据");
        }

    });



    $('.linkfunction a').click(function() {
        this.href = "/Product/HomeFunction/" + this.id;

    });


    $.formValidator.initConfig({ alertmessage: false, onerror: function(msg) { alert(msg); return false; } });
    $("#ProductSize").formValidator({ onfocus: " ", onshow: " ", oncorrect: " " }).inputValidator({ min: 1, onerror: "请选择码数" });
    $("#txtAmount").formValidator({ onshow: " ", onfocus: " ", oncorrect: " " }).inputValidator({ min: 1 }).regexValidator({ regexp: "intege1", datatype: "enum", onerror: "你输入的数量不正确" }); ;


    $.formValidator.initConfig({ validatorgroup: "2", onerror: function() { return false; } });
    $("#slctSize").formValidator({ validatorgroup: "2", onshow: " ", onfocus: " ", oncorrect: " " }).inputValidator({ min: 1, onerror: "请选择码数" });
    $("#slctSize2").formValidator({ validatorgroup: "2", onshow: " ", onfocus: " ", oncorrect: " " }).inputValidator({ min: 1, onerror: "请选择码数" });




    listQuestion(); //加载问题


    $("#Pagination").pagination(TagUserCount, {
        num_edge_entries: 0,
        num_display_entries: 10,
        items_per_page: 28,
        callback: pageselectCallback
    });
    pageselectCallback(0, null);


    listReview();

});


function getSize(moduleName, id) {
    $("#spanSelectSize" + moduleName).html("");
    $("#spanSelectColor" + moduleName).html("<img src='" + $("#" + id).attr("src") + "' width=15 height=15 class=\"img\" />");
    $("#SelectProductColor" + moduleName).val(id);
    getSizeList("#CurGoodsSize" + moduleName, id);

}

function getSizeList(sizeListDrp, id) {
    if (id != "") {
        $.ajax({ type: "Post", url: "/Product/GetSize/" + id + ".html", data: "", success: function(xml) {
            var data = eval(xml);
            $(sizeListDrp).empty();
            // $(sizeListDrp).append('<span class="selected" >--请选择--</option>');
            $.each(data, function(i, n) {
                $(sizeListDrp).append('<span onclick="sizeClick(' + i + ')"  name="' + String(n.total - n.used) + '"  id="' + n.ID + '">' + n.SizeClass_Name + '</span>');
            });
            sizeClick(0);
        }
        });
    }
}


function sizeClick(num) {

    var id = "";
    $("#CurGoodsSize > span").each(function(i) {
        if (num == i) {
            $(this).addClass("selected");
            $(this).removeClass("img");
            $("#SizeName").html($(this).html());
            $("#spanProductSize").html($(this).attr("name"));
            id = $(this).attr("id");
        }
        else {
            $(this).removeClass("selected");
            $(this).addClass("img");
        }
    });
    $("#ProductSize").val(id);

}

function colorClick(num) {
    var id = "";
    $("#spanProductColor img").each(function(i) {
        if (i % 2 == 1) {
            j = (i - 1) / 2;
            if (num == j) {
                $(this).parent().addClass("zoomPicSelected");
                $(this).parent().removeClass("zoomPicNomarl");
                $("#ColorName").html($(this).attr("title"));
                id = $(this).attr("id");
            }
            else {
                $(this).parent().removeClass("zoomPicSelected");
                $(this).parent().addClass("zoomPicNomarl");
            }
        }
    });

    if (id != "") {

        $("#ProductColor").val(id); //给隐藏框设置颜色ID
        getSizeList("#CurGoodsSize", id);  // 修改尺寸下列框        
        //修改下面的各个图片
        $.ajax({ type: "Get", url: "/File/getImg/" + id + ".html", data: "", success: function(xml) {
            //     修改产品颜色
            var data = eval(xml);
            $("#availColors").empty();
            $.each(data, function(i, n) {

                if (i == 0) {
                    $('#zooeImage').attr('src', "" + n.FileBreviary + "");
                    $('#zooeImage').attr('jqimg', "" + n.FilePath + "");
                }
                $("#availColors").append("<img onclick=\" $('#zooeImage').attr('src','" + n.FileBreviary + "');$('#zooeImage').attr('jqimg','" + n.FilePath + "');\" src='" + n.FileBreviary + "' class='img' width=40 height=40/> ");
            });

        }
        });
    }

}


///添加想用与推荐
function commendClick(productid, productname, Classify) {

    if (isLogin()) {

        switch (Classify) {
            case 1:
                Openwould(productid, productname, "divcommend"); //打开有用
                OpenMessageBox("control:divcommend;width:400;height:250;title:想用");
                break;
            case 2:
                Opencommend(productid, productname, "divcommend"); //打开推荐
                OpenMessageBox("control:divcommend;width:400;height:250;title:推荐");
                break;
            case 3:
                OpewReview(productid, productname, "divcommend"); //打开评论
                OpenMessageBox("control:divcommend;width:400;height:250;title:评论");
                break;
        }
    }
}





//添加回答对话框

function addAnswer(QuestionId) {

    $("#addAnswerContent").remove();  //移去原来的回答框
    if (isLogin()) {
        var content = "<div id='addAnswerContent' style='margin-left:8px'>";
        content = content + "<textarea  name=\"answerContent\"  rows=\"4\"  cols=\"70\"  id=\"answerContent\"  ></textarea>";
        content = content + "   <input type=\"button\" value=\"提 交 答 案\" id=\"butAnswer\" onclick=\"createAnawer('" + QuestionId + "')\" name=\"butQuestion\">";
        content = content + " </div>"  //增加回答框内容

        $("#Quertion" + QuestionId).append(content);
        $("#answerContent").focus();
    }


}



function createAnawer(QuestionId) {
    var answerContent = $("#answerContent").attr("value");

    if (QuestionId != "" && answerContent != "") {
        if (isLogin()) {
            $.ajax({ type: "POST", url: "/Question/AnswerCreate.html", data: "QuestionId=" + QuestionId + "&answerContent=" + answerContent, success: function(xml) {
                alert(eval(xml));
                $("#Quertion" + QuestionId).children("div").remove();
                $("#addAnswerContent").remove();
                listAnswer(QuestionId, true);
            }

            });


        }

    }
    else {
        alert("请填写正确的数据");
    }

}



//显示商品问题
function listQuestion() {
    $.ajax({ type: "POST", url: "/Question/list/" + product_id + ".html?currPage=1", data: "", success: function(xml) {
        var data = eval(xml);
        $.each(data, function(i, n) {
            var content = "";
            content = content + "<DIV  style='margin: 10px 0px 10px 10px '";
            content = content + " id='Quertion" + n.questionId + "'";
            content = content + " ><STRONG><a href=\"/Friend/Detail/" + n.UserID + "\"><FONT ";
            content = content + "color=#006600>" + n.UserName + "</a>：</FONT></STRONG>" + n.questionContent + "？";
            content = content + "</div>";
            $("#listAnswer").append(content);
            listAnswer(n.questionId, !n.IsEnd);
        });



    }


    });

}



//显示商品答案
function listAnswer(QuestionId, IsEnd) {
    var content = "";
    $.ajax({ type: "POST", url: "/Question/ListAnswer/" + QuestionId + ".html", data: "", success: function(xml) {

        var data = eval(xml);
        $.each(data, function(i, n) {
            content = content + ' <DIV  style="PADDING-RIGHT: 0px; PADDING-LEFT: 10px; PADDING-BOTTOM: 8px; MARGIN: 10px 0px 15px; PADDING-TOP: 8px; BACKGROUND-COLOR: #eeeeee"><STRONG><FONT';
            content = content + "  color=#ff0000>" + n.UserName + "：</FONT></STRONG>" + n.AnswerContent;
            if (!IsEnd) {
                content = content + "&nbsp;问题得分:" + n.AnswerScore;
            }
            content = content + "</DIV>";

        });

        $("#Quertion" + QuestionId).append(content);

    }
    });

}




//显示商品评论
function listReview() {

    $.ajax({ type: "Post", url: "/Product/GetlistReview/" + product_id + ".html", data: "count=10", success: function(xml) {
        var data = eval(xml);
        if (data[0].Value.length > 0) {
            $("#prodSpecsNone").hide();
            $("#prodSpecs2").show();
            $.each(data[0].Value, function(i, n) {
                var temp = "<strong>品&nbsp; 质：</strong>";
                var count = n.counts;
                for (var i = 0; i < n.reviewLevel / count; i++) {
                    temp = temp + " <IMG height=12 src=\"..\/..\/img\/sts.gif\" width=12 \/>";
                }
                if (count != "0") {
                    temp += "  <span class=\"gray_12\">(" + Math.ceil(n.reviewLevel / count * 2) + ")</span>";
                }
                $("#sumreviewLevel").html(temp);

                temp = "<strong>外&nbsp; 观：</strong>";
                for (var i = 0; i < n.server / count; i++) {
                    temp = temp + " <IMG height=12 src=\"..\/..\/img\/sts.gif\" width=12 \/>";
                }
                if (count != "0") {
                    temp += "  <span class=\"gray_12\">(" + Math.ceil(n.server / count * 2) + ")</span>";
                }
                $("#sumserver").html(temp);
                temp = "<strong>性价比：</strong>";
                for (var i = 0; i < n.priceratio / count; i++) {
                    temp = temp + " <IMG height=12 src=\"..\/..\/img\/sts.gif\" width=12 \/>";
                }
                if (count != "0") {
                    temp += "  <span class=\"gray_12\">(" + Math.ceil(n.priceratio / count * 2) + ")</span>";
                }
                $("#sumpriceratio").html(temp);

            });


            var characteristic = "特点：";
            var vuse = "用途：";
            var receptive = "感受：";
            var server = "总评：";
            $.each(data[1].Value, function(i, n) {

                switch (n.tagType) {
                    case 3:

                        characteristic = characteristic + "<a href=\"/Product/ListTag/" + n.tagID + ".html?currPage=1&tagType=3\">" + n.tagName + "</a><span class=\"gray_12\">(" + n.counts + ")</span> ";
                        break;
                    case 4:
                        vuse = vuse + "<a href=\"/Product/ListTag/" + n.tagID + ".html?currPage=1&tagType=4\">" + n.tagName + "</a><span class=\"gray_12\">(" + n.counts + ")</span> ";
                        break;
                    case 5:
                        receptive = receptive + "<a href=\"/Product/ListTag/" + n.tagID + ".html?currPage=1&tagType=5\">" + n.tagName + "</a><span class=\"gray_12\">(" + n.counts + ")</span> ";
                        break;
                    case 6:
                        server = server + "<a href=\"/Product/ListTag/" + n.tagID + ".html?currPage=1&tagType=6\">" + n.tagName + "</a><span class=\"gray_12\">(" + n.counts + ")</span> ";
                        break;
                }

            });

            $("#sumusr").append("<p>" + characteristic + "<br \/><br \/>" + vuse + "<br \/><br \/>" + receptive + "<br \/><br \/>" + server + "<br \/><br \/><\/p>");



            $("#PaginationReview").pagination(listReviewCount, {
                num_edge_entries: 0,
                num_display_entries: 10,
                items_per_page: 10,
                callback: ListPageReview
            });
            ListPageReview(0, null);

        }
        else {
            $("#prodSpecsNone").show();
            $("#prodSpecs2").hide();
        }
    }
    });

}



function ListPageReview(page, jq) {
    $("#listReview").html("");
    $.ajax({ type: "POST", url: "/Product/GetlistPageReview/" + product_id + ".html", data: "pageCount=10&currPage=" + (page + 1), success: function(xml) {
        var data = eval(xml);
        $.each(data, function(i, n) {
            var content = "";

            content = content + " <TABLE cellSpacing=0 cellPadding=0 width=\"100%\" border=0>";
            content = content + "              <TBODY>";
            content = content + "              <TR>";
            content = content + "                <TD>";
            content = content + "                  <div style=\"margin-top:10px\" align=left>品质："

            for (var i = 0; i < n.ReviewLevel; i++) {
                content = content + "         <IMG height=12 src=\"..\/..\/img\/sts.gif\" width=12>";
            }

            content = content + "                  外观：";
            for (var i = 0; i < n.server; i++) {
                content = content + "         <IMG height=12 src=\"..\/..\/img\/sts.gif\" width=12>";
            }
            content = content + "  性价比： ";
            for (var i = 0; i < n.priceratio; i++) {
                content = content + "         <IMG height=12 src=\"..\/..\/img\/sts.gif\" width=12>";
            }
            if (n.IsBuyreview) {
                content = content + "<span align=\"center\"  style=\"margin-left:100px;padding:5px; background-color:#FFFFff; BORDER: #ccc 1px solid; width:100px; font-size:12px; line-height:10px; color:#999\">我已购买</span>";
            }
            content = content + "<\/div>";
            content = content + "                  <div  style=\"margin-top:10px\" align=left><SPAN><FONT><IMG height=19 ";
            content = content + "                  src=\""
            content = content + n.FileBreviary;
            content = content + "\" width=19> <A href=\"\/Friend\/Detail\/";
            content = content + n.UserID;
            content = content + "\">" + n.UserName;

            content = content + "<\/A> <span style=\"font-size:12px\">来自</span> <span id=\"span" + n.ID + "\"></span>";
            //content=content+n.bbsname;
            content = content + "<\/A><\/FONT><\/SPAN> ";
            content = content + n.AddDate + "<\/div>";
            content = content + "                  <div style=\"margin-top:10px\" align=left><STRONG>特点：<\/STRONG><span id='characteristic" + n.ID + "'\/><\/div>";
            content = content + "                  <div style=\"margin-top:10px\" align=left><STRONG>用途：<\/STRONG><span id='use" + n.ID + "'\/><\/div>";
            content = content + "                  <div style=\"margin-top:10px\" align=left><STRONG>你的感受：<\/STRONG><span id='receptive" + n.ID + "'\/><\/div>";
            content = content + "                  <div style=\"margin-top:10px\" align=left><STRONG>总评：<\/STRONG><span id='server" + n.ID + "'\/><\/div>";
            content = content + "                  <div style=\"margin-top:10px\" align=left>"
            content = content + n.ReviewContent
            content = content + "            <br />    <br />  ";
            content = content + "                  <span onclick=\"ReviewUseful('" + n.ID + "')\" class=\"red\" style=\"cursor:hand;text-decoration:none;\" >评价对我有用，给作者+10分<\/span>";



            content = content + "                  <\/div><div><br /><\/div><\/TD><\/TR><\/TBODY><\/TABLE>";
            $("#listReview").append(content);
            //取得总评等值
            GetBbsList(n.ID, n.UserID);
            listOther(n.ID)
        });
    }
    });
}

var listReviewCount = 0;




//取得总评等值
function listOther(id) {
    var content = "";
    var characteristic = "";
    var vuse = "";
    var receptive = "";
    var server = "";
    $.ajax({ type: "Get", url: "/Product/GetlistReviewOther/" + id + ".html", data: "", success: function(xml) {

        var data = eval(xml);
        $.each(data, function(i, n) {
            switch (n.tagType) {
                case 3:
                    characteristic = characteristic + "<a href=\"/Product/ListTag/" + n.tagID + "?currPage=1&tagType=3\">" + n.tagName + "</a> "
                    break;
                case 4:
                    vuse = vuse + "<a href=\"/Product/ListTag/" + n.tagID + "?currPage=1&tagType=4\">" + n.tagName + "</a> "
                    break;
                case 5:
                    receptive = receptive + "<a href=\"/Product/ListTag/" + n.tagID + "?currPage=1&tagType=5\">" + n.tagName + "</a> "
                    break;
                case 6:
                    server = server + "<a href=\"/Product/ListTag/" + n.tagID + "?currPage=1&tagType=6\">" + n.tagName + "</a> "
                    break;
            }

        });

        $("#characteristic" + id).append(characteristic);
        $("#use" + id).append(vuse);
        $("#receptive" + id).append(receptive);
        $("#server" + id).append(server);

    }
    });

}

function ReviewUseful(ReviewID) {
    if (isLogin()) {
        $.ajax({ type: "POST", url: "/ReviewUseful/Create", data: "ReviewID=" + ReviewID + "&isAjax=true", success: function(xml) {
            alert(xml);

        }

        });
    }


    return false;
}


function GetBbsList(ReviewID, UserID) {

    $.ajax({ type: "Get", url: "/BbsUser/GetBBsUser/" + UserID + ".html", data: "", success: function(xml) {
        var content = "";
        var data = eval(xml);
        $.each(data, function(i, n) {
            content = content + "<a href=\"" + n.webSite + "\"  target=\"_blank\">" + n.bbsName + "</a> &nbsp;";

        });

        $("#span" + ReviewID).html(content);


    }

    });


    return false;
}





//jquery 分页
function pageselectCallback(page_id, jq) {
    var content = "";

    $.ajax({ type: "Post", url: "/Product/getBuyProductUser/" + product_id + ".html", data: "topN=28" + "&currPage=" + (page_id + 1), success: function(xml) {
        var data = eval(xml);
        $.each(data, function(i, n) {
            content = content + "      <div class=\"zj\" style=\"width: 80px;\">";
            content = content + "            <div class=\"l50_s\">";
            content = content + "               <a href=\"/Friend/Detail/" + n.UserId + ".html\" >";
            content = content + "                    <img height='50' width='50' src='" + n.FileBreviary + "' alt=''/></a></div>";
            content = content + "          <div class=\"zj2 green_12\" style=\"margin-top: -7px;\">";
            content = content + "                <a ";
            content = content + "     class='green_12'     href=\"";
            content = content + "/Friend/Detail/" + n.UserId + ".html";
            content = content + "\">" + n.UserName + "<\/a>";
            content = content + "            </div>";
            content = content + "        </div>";

        });

        document.getElementById("Searchresult").innerHTML = content;
    }
    });
}


function Button1_onclick() {

    return jQuery.formValidator.pageIsValid('1');
}

function Submit1_onclick() {
    return jQuery.formValidator.pageIsValid("2");
}

function gotoTop() { window.scrollTo(0, 0); return false; }

function gotoClick() { }