﻿
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")
            }
        }
    }
}

function show_goods_image(url, bigUrl) {
    $('#productImage').attr('src', url);
    $('#BigViewImage').attr('href', bigUrl);
}
$(document).ready(function () {
    $("#mycarousel").jcarousel({ initCallback: mycarousel_initCallback });
    $(".jqzoom").jqueryzoom({
        xzoom: 320,
        yzoom: 320,
        offset: 10,
        position: "right",
        preload: 1,
        lens: 1
    });
    function mycarousel_initCallback(carousel) {
        $("#mycarousel li").mouseover(function () {
            var JQ_img = $("img", this);
            var image_name = JQ_img.attr("name");

            $("#_middleImage").attr("src", JQ_img.attr("src")).attr("longdesc", JQ_img.attr("bigurl"));
            $(this).siblings().each(function () {
                $("img", this).removeClass().addClass("curr_base");
            })
            JQ_img.addClass("cur_on");
        })
    };

    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);
        }
    });


    //添加到藏夹  
    $("#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(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: "你输入的数量不正确" }); ;


    $.ajax({ type: "Get", url: "/Product/ilkProduct/" + product_id + ".html?ClassID=" + ClassID + "&Design=" + Design, data: "", success: function (xml) {
        var data1 = eval(xml)
        var content1 = "";
        $.each(data1, function (i, n) {
            content1 += ' <div class="l" style="width: 80; height: 80; padding: 5px;">';
            content1 += '<a href="/Product/HomeDetail/' + n.Product_id + '.html">';
            content1 += '<img class="img" alt="' + n.brandClass_Name + " " + n.Product_Number + " " + n.Product_Name + '" src="http://www.oyego.com' + n.filebreviary + '"';
            content1 += 'width="80px" height="80px" /></a></div>';
        });
       
        $("#ilkProduct").html(content1);
    }
    });


    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);

}

function getSizeList(sizeListDrp, id) {
    if (id != "") {
        $.ajax({ type: "Post", url: "/Product/GetSize/" + id + ".html", data: "", success: function (xml) {

            var data = eval(xml);
            $(sizeListDrp).empty();
            $.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");
            $("#spanProductSize").html($(this).attr("name"));
            id = $(this).attr("id");
        }
        else {
            $(this).removeClass("selected");
            $(this).addClass("img");
        }
    });
    $("#ProductSize").val(id);
}

function colorClick(num) {
    var id = "";
    var smallsrc = "";
    var bigsrc = "";
    $("#spanProductColor img").each(function (i) {

        if (num == i) {
            $(this).parent().parent().addClass("zoomPicSelected");
            $(this).parent().parent().removeClass("zoomPicNomarl");
            id = $(this).attr("id");
            smallsrc = $(this).attr("src");
            bigsrc = $(this).attr("zoomsrc");
        }
        else {
            $(this).parent().parent().removeClass("zoomPicSelected");
            $(this).parent().parent().addClass("zoomPicNomarl");
        }
    });
    if (id != "") {
        $("#ProductColor").val(id); //给隐藏框设置颜色ID
        getSizeList("#CurGoodsSize", id);  // 修改尺寸下列框
        $('#_middleImage').attr('src', smallsrc);
        $('#_middleImage').attr('longdesc', bigsrc);
    }

}

///添加想用与推荐
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(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 + "？";
            $.each(n.T_Oyego_Answers, function (j, t) {
                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>" + t.UserName + "：</FONT></STRONG>" + t.AnswerContent;
                if (n.IsEnd) {
                    content = content + "&nbsp;问题得分:" + t.AnswerScore;
                }
                content = content + "</DIV>";
            });

            content = content + "</div>";
            $("#listAnswer").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 = "";
            var characteristic = "";
            var vuse = "";
            var receptive = "";
            var server = "";
            $.each(n.ReviewOther, function (j, t) {
                switch (t.tagType) {
                    case 3:
                        characteristic = characteristic + "<a href=\"/Product/ListTag/" + t.tagID + "?currPage=1&tagType=3\">" + t.tagName + "</a> "
                        break;
                    case 4:
                        vuse = vuse + "<a href=\"/Product/ListTag/" + t.tagID + "?currPage=1&tagType=4\">" + t.tagName + "</a> "
                        break;
                    case 5:
                        receptive = receptive + "<a href=\"/Product/ListTag/" + t.tagID + "?currPage=1&tagType=5\">" + t.tagName + "</a> "
                        break;
                    case 6:
                        server = server + "<a href=\"/Product/ListTag/" + t.tagID + "?currPage=1&tagType=6\">" + t.tagName + "</a> "
                        break;
                }
            });


            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;
            var bbsUsers = "";
            $.each(n.T_Oyego_BbsUsers, function (j, t) {
                bbsUsers += "<a href=\"" + t.webSite + "\"  target=\"_blank\">" + t.bbsName + "</a> &nbsp;";
            });

            content = content + "<\/A> <span style=\"font-size:12px\">来自</span> <span>" + bbsUsers + "<\/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>" + characteristic + "<\/div>";
            content = content + "                  <div style=\"margin-top:10px\" align=left><STRONG>用途：<\/STRONG>" + vuse + "<\/div>";
            content = content + "                  <div style=\"margin-top:10px\" align=left><STRONG>你的感受：<\/STRONG>" + receptive + "<\/div>";
            content = content + "                  <div style=\"margin-top:10px\" align=left><STRONG>总评：<\/STRONG>" + server + "<\/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);
        });
    }
    });
}

var listReviewCount = 0;

function ReviewUseful(ReviewID) {
    if (isLogin()) {
        $.ajax({ type: "POST", url: "/ReviewUseful/Create", data: "ReviewID=" + ReviewID + "&isAjax=true", success: function (xml) {
            alert(xml);

        }

        });
    }


    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 gotoTop() { window.scrollTo(0, 0); return false; }

function gotoClick() { }
