﻿/// <reference path="jquery-1.2.6.js" />
var Exmenu = {
    _width: 192,
    _speed: 300,
    _path: "",
    initialize: function(cell, id) {
        $.scrollTo.defaults.axis = 'x';

        $("#menu_wrap").scrollTo('+=' + Exmenu._width * cell, 0);
        $("#right_menu_wrap").scrollTo('+=' + Exmenu._width * (2 - cell), 0);

        $("#menu_wrap").append('<div class="seriescontrol" style="position:absolute; left: 550px; top: 50px; width: 15px; color: #ffffff; display: none;"><a href="javascript:void(0)" onmouseover="Exmenu.scrollSeries(1);"><img src="images/upward.gif" border="0" /></a><div style="height: 220px;"></div><a href="javascript:void(0)" onmouseover="Exmenu.scrollSeries(0);"><img src="images/adown.gif" border="0" /></a></div>');
        $("#right_menu_wrap").append('<div class="seriescontrol2" style="position:absolute; left: 15px; top: 50px; width: 15px; color: #ffffff; display: none;"><a href="javascript:void(0)" onmouseover="Exmenu.scrollSeries(1);"><img src="images/upward.gif" border="0" /></a><div style="height: 220px;"></div><a href="javascript:void(0)" onmouseover="Exmenu.scrollSeries(0);"><img src="images/adown.gif" border="0" /></a></div>');

        Exmenu.showMenu(arguments);

        $("#menu_main").show();
    },
    showMenu: function() {
        var args = typeof (arguments[0]) == "object" ? arguments[0] : arguments;
        var cell = args[0], id = args[1], type = args[2], pid = args[3];

        $("#first_menu .menu_up, #right_first_menu .menu_up").text("");
        var firststr = "";
        $.each(menus, function(i, item) {
            if (item.Depth == 0) {
                if (i > 0) firststr += '</div>';

                if (id == item.Id)
                    firststr += '<p><a href="' + Exmenu._path + 'BrandTypeList.aspx?typeid=' + item.Id + '" class="shop_nav_c">' + item.Name + '</a></p>';
                else
                    firststr += '<p><a href="' + Exmenu._path + 'BrandTypeList.aspx?typeid=' + item.Id + '" class="shop_nav">' + item.Name + '</a></p>';

                firststr += '<div class="subpanel" style="display: none;">';
            } else {
                if (id == item.Id)
                    firststr += '<p>　　<a href="' + Exmenu._path + 'BrandTypeList.aspx?typeid=' + item.Id + '" class="shop_nav_c">' + item.Name + '</a></p>';
                else
                    firststr += '<p>　　<a href="' + Exmenu._path + 'BrandTypeList.aspx?typeid=' + item.Id + '" class="shop_nav">' + item.Name + '</a></p>';
            }
        });
        firststr += '</div>';
        $("#first_menu .menu_up, #right_first_menu .menu_up").append(firststr);
        $("#first_menu .menu_up, #right_first_menu .menu_up").find("a.shop_nav_c").parents("div.subpanel").show();

        $("#first_menu .menu_up, #right_first_menu .menu_up").append('<br>');
        $("#first_menu .menu_up, #right_first_menu .menu_up").append('<p><a href="http://style.exmrw.com/" target="_blank" class="shop_nav">美容时尚杂志</a> <span style="color: Red;">New!</span></p>');
        $("#first_menu .menu_up, #right_first_menu .menu_up").append('<p><a href="http://bbs.exmrw.com/" target="_blank" class="shop_nav">专业美容论坛</a></p>');
        $("#first_menu .menu_up, #right_first_menu .menu_up").append('<p><a href="#" onclick="Ex.showSelectBrand(); return false;" class="shop_nav">品牌导购</a> <span style="color: Red;">New!</span></p>');
        $("#first_menu .menu_up, #right_first_menu .menu_up").append('<p><a href="http://job.exmrw.com/" target="_blank" class="shop_nav">美容人才招聘</a></p>');
        $("#first_menu .menu_up, #right_first_menu .menu_up").append('<p><a href="http://www.exmrw.com/supplier/default.aspx" target="_blank" class="shop_nav">供应商服务中心</a></p>');
        //$("#first_menu .menu_up, #right_first_menu .menu_up").append('<p><a href="' + Exmenu._path + 'MallDefault.aspx" id="mall" class="shop_nav">美容院用品商城</a></p>');
        //$("#first_menu .menu_up, #right_first_menu .menu_up").append('<p><a href="' + Exmenu._path + 'newweb.aspx" class="shop_nav newweb">建站服务</a></p>');

        if (location.href.toLowerCase().indexOf("/default.aspx") == -1 && location.href.substring(location.href.length - 1) != "/") {
            $("#first_menu .menu_down, #right_first_menu .menu_down").show();
        }

        if (cell == 1) {
            $("#second_menu .menu_up, #right_second_menu .menu_up").text("");
            $.each(menus, function(i, item) {
                if (item.Id == pid[0]) {
                    $.each(item.Item, function(j, item1) {
                        if (item1.Id == pid[1]) {
                            //$("#second_menu .menu_up, #right_second_menu .menu_up").append('<p>' + item1.Name + '</p><br>');

                            $.each(item1.Item, function(k, item2) {
                                if (item2.Url != "") {
                                    if (id == item2.Id)
                                        $("#second_menu .menu_up, #right_second_menu .menu_up").append('<div>　<a href="' + item2.Url + '" class="shop_nav_c">' + item2.Name + '</a></div>');
                                    else
                                        $("#second_menu .menu_up, #right_second_menu .menu_up").append('<div>　<a href="' + item2.Url + '" class="shop_nav">' + item2.Name + '</a></div>');
                                } else {
                                    if (k != 0)
                                        $("#second_menu .menu_up, #right_second_menu .menu_up").append('<div style="margin: 0;">&nbsp;</div>');

                                    if (item2.Id == -5000)
                                        $("#second_menu .menu_up, #right_second_menu .menu_up").append('<div style="position: relative; margin: 0 0 28px;"><div style="position:absolute; left: -35px; width: 192px; height: 20px; overflow: hidden; background: url(images/exmrw_4_5.jpg);">&nbsp;<img src="images/exmrw_4_6.gif" align="absmiddle">' + item2.Name + '<div></div>');
                                    else
                                        $("#second_menu .menu_up, #right_second_menu .menu_up").append('<p>' + item2.Name + '</p>');
                                }
                            });
                        }
                    });
                }
            });

            $("#second_menu .menu_down, #right_second_menu .menu_down").unbind("click").click(function() {
                location.href = "BrandTypeList.aspx?typeid=" + pid[0];
            });
        }
        else if (cell == 2) {
            $("#third_menu .menu_up, #right_third_menu .menu_up").text("");
            $.each(menus, function(i, item) {
                if (item.Id == pid[0]) {
                    $.each(item.Item, function(j, item1) {
                        if (item1.Id == pid[1]) {
                            $.each(item1.Item, function(k, item2) {
                                if (item2.Id == pid[2]) {
                                    var html = '<p>' + item2.Name + '</p><div class="series_wrap" style="height: 273px; overflow: hidden;">';

                                    $.each(item2.Item, function(m, item3) {
                                        if (id == item3.Id)
                                            html += '<p><a href="' + item3.Url + '" class="shop_nav_c">' + item3.Name + '</a></p>';
                                        else
                                            html += '<p><a href="' + item3.Url + '" class="shop_nav">' + item3.Name + '</a></p>';
                                    });
                                    html += '</div>';

                                    $("#third_menu .menu_up, #right_third_menu .menu_up").append(html);

                                    if (item2.Item.length > 12) {
                                        $("div.seriescontrol, div.seriescontrol2").show();
                                    }
                                }
                            });
                        }
                    });
                }
            });

            $("#third_menu .menu_down, #right_third_menu .menu_down").unbind("click").click(function() {
                Exmenu.showMenu(1, pid[2], 1, pid.slice(0, 2));
                $("div.seriescontrol, div.seriescontrol2").hide();
                Exmenu.scrollMenu(1);
            });
        }
    },
    scrollMenu: function(type) {
        if (type == 0) {
            $("#menu_wrap").stop().scrollTo('+=' + Exmenu._width, Exmenu._speed);
            $("#right_menu_wrap").stop().scrollTo('-=' + Exmenu._width, Exmenu._speed);
        }
        else if (type == 1) {
            $("#menu_wrap").stop().scrollTo('-=' + Exmenu._width, Exmenu._speed);
            $("#right_menu_wrap").stop().scrollTo('+=' + Exmenu._width, Exmenu._speed);
        }
    },
    scrollSeries: function(type) {
        if (type == 0) {
            $("div.series_wrap").stop().scrollTo('+=273', 1000, { axis: 'y' });
        }
        else if (type == 1) {
            $("div.series_wrap").stop().scrollTo('-=273', 1000, { axis: 'y' });
        }
    }
}

var Exscroll = {
    _speed: 1200,
    bind: function() {
        $.scrollTo.defaults.axis = 'x';

        $(".scrollRight").click(function() {
            $.scrollTo('+=395', Exscroll._speed);
        });

        $(".scrollLeft").click(function() {
            $.scrollTo('-=395', Exscroll._speed);
        });
    },
    brandBind: function() {
        $.scrollTo.defaults.axis = 'x';

        $(".bScrollLeft").click(function() {
            $.scrollTo('+=355', Exscroll._speed);
        });

        $(".bScrollRight").click(function() {
            $.scrollTo('-=355', Exscroll._speed);
        });
    },
    scrollBrand: function(type, width) {
        $.scrollTo.defaults.axis = 'x';
        if (type == 0) {
            $.scrollTo('+=' + width, Exscroll._speed);
        }
        else if (type == 1) {
            $.scrollTo('-=' + width, Exscroll._speed);
        }
    },
    mouseWheel: function() {
        if (window.addEventListener) {
            document.addEventListener("DOMMouseScroll", Exscroll.mouseWheelHandler, false);
        } else {
            document.onmousewheel = Exscroll.mouseWheelHandler;
        }
    },
    mouseWheelHandler: function(event) {
        var event = event || window.event;
        if (event.detail > 0 || event.wheelDelta < 0) {
            $.scrollTo('+=120', 0, { axis: 'x' });
        } else {
            $.scrollTo('-=120', 0, { axis: 'x' });
        }
    }
}

var Ex = {
    resize: function(id, left, top) {
        window.onresize = function() {
            Ex.redraw(id, left, top);
        }
        Ex.redraw(id, left, top);
    },
    redraw: function(id, left, top) {
        var obj = $(id);
        if (top) {
            var otop = (document.documentElement.clientHeight - obj.height()) / 2 - 60 + "px";
            if (document.documentElement.clientHeight < obj.height()) otop = "40px";
            obj.css("top", otop);
            if ($.browser.msie && $.browser.version >= 7) {
                $("#top").css("top", otop);
            }
        }
        if (left) {
            var oleft = (document.body.scrollWidth - obj.width()) / 2 + "px";
            if (document.body.scrollWidth < obj.width()) oleft = "60px";
            obj.css("left", oleft);
            if ($.browser.msie && $.browser.version >= 7) {
                $("#top").css("left", oleft);
            }
        }
    },
    addTempShelf: function(id, type) {
        $.get("CartCookie.ashx?action=addtemp&productid=" + parseInt(id) + "&type=" + type + "&" + Math.ceil(Math.random() * 100000000),
        function(txt) {
            if (txt == "error") { alert('添加错误，请重试。'); }
            else if (txt == "nologin") { alert('由于您还没有登录，因此您不能使用该功能。'); }
            else { alert('商品添加成功 ！'); }
        });
    },
    showJoinBrand: function(id) {
        tb_show("", Exmenu._path + "JoinBrandPop.aspx?id=" + id + "&TB_iframe=true&height=520&width=700&modal=true", false);
    },
    showConsultBrand: function(id) {
        tb_show("", Exmenu._path + "ConsultBrandPop.aspx?id=" + id + "&TB_iframe=true&height=520&width=700&modal=true", false);
    },
    showMarketPolicies: function(id) {
        tb_show("", Exmenu._path + "MarketPoliciesPop.aspx?id=" + id + "&TB_iframe=true&height=520&width=700&modal=true", false);
    },
    showObtainQuotation: function(id) {
        tb_show("", Exmenu._path + "ObtainQuotationPop.aspx?id=" + id + "&TB_iframe=true&height=520&width=700&modal=true", false);
    },
    showSelectJoinBrand: function(id) {
        tb_show("", Exmenu._path + "SelectJoinBrandPop.aspx?id=" + id + "&TB_iframe=true&height=480&width=680&modal=true", false);
    },
    callCS: function(id) {
        window.open('http://sighttp.qq.com/cgi-bin/check?sigkey=53001a29bdf6343796721045e2af102d5a4cd370c38a82120509f4f8afeb945c', 'newwindow', 'height=329, width=458, top=0, left=200, toolbar=no, menubar=no, scrollbars=no, resizable=yes');
    },
    showSelectBrand: function(id) {
        tb_show("", (location.href.toLowerCase().indexOf("/member") == -1 && location.href.toLowerCase().indexOf("/service") == -1 ? "../product/" : "../../product/") + "SelectBrandPop.aspx?TB_iframe=true&height=390&width=550&modal=true", false);
    },
    showSelectResult: function(params) {
        tb_show("", (location.href.toLowerCase().indexOf("/member") == -1 && location.href.toLowerCase().indexOf("/service") == -1 ? "../product/" : "../../product/") + "SelectResultPop.aspx?" + params + "&TB_iframe=true&height=550&width=819&modal=true", false);
    },
    selectBrandPosition: function(id) {
        if (id == 1) {
            $("#AllPanel").show();
            $("#SpecialPanel").hide();
        } else {
            $("#AllPanel").hide();
            $("#SpecialPanel").show();
        }
    },
    selectBrand: function() {
        var params = "";
        var brandPosition = $("input[@name=BrandPosition]:checked").val();
        if (brandPosition == 1) {
            params += "position=" + brandPosition;
            params += "&packaging=";
            var packaging = "";
            $("input[@name^=Packaging]:checked").each(function() {
                packaging += "," + $(this).next("label").text();
            });
            params += escape(packaging.length > 0 ? packaging.substring(1) : packaging);
            params += "&origin=";
            var origin = "";
            $("input[@name^=Origin]:checked").each(function() {
                origin += "," + $(this).next("label").text();
            });
            params += escape(origin.length > 0 ? origin.substring(1) : origin);
        } else {
            params += "position=" + brandPosition;
            params += "&effectiveness=";
            var effectiveness = "";
            $("input[@name^=Effectiveness]:checked").each(function() {
                effectiveness += "," + $(this).next("label").text();
            });
            params += escape(effectiveness.length > 0 ? effectiveness.substring(1) : effectiveness);
            params += "&brandcategory=";
            var brandcategory = "";
            $("input[@name^=BrandCategory]:checked").each(function() {
                brandcategory += "," + $(this).next("label").text();
            });
            params += escape(brandcategory.length > 0 ? brandcategory.substring(1) : brandcategory);
            params += "&origin=";
            var origin = "";
            $("input[@name^=Origin]:checked").each(function() {
                origin += "," + $(this).next("label").text();
            });
            params += escape(origin.length > 0 ? origin.substring(1) : origin);
        }
        parent.Ex.showSelectResult(params);
    },
    showKeFu: function(delay) {
        setTimeout('Ex.showKeFuFun()', delay);
    },
    showKeFuFun: function() {
        if (Ex["KeFuMsgState"] == null) $("#kefu").show(300);
        setTimeout('Ex.closeKeFu(' + function() {
            Ex.showKeFu(5000);
        } + ')', 10000);
    },
    closeKeFu: function(callback) {
        $("#kefu").hide(300);
        if ($.isFunction(callback)) callback();
    },
    showKeFuMsg: function() {
        $("#kefumsg").toggle(300);
        if (Ex["KeFuMsgState"] == null) {
            Ex["KeFuMsgState"] = "open";
            Ex.closeKeFu();
        } else {
            Ex["KeFuMsgState"] = null;
        }
        $("#kefumsg").hover(function() {
            $("#kefumsg").show(300);
            Ex["KeFuMsgState"] = "open";
        }, function() {
            $("#kefumsg").hide(300);
            Ex["KeFuMsgState"] = null;
        });
    },
    showUserInfoBar: function() {
        $.get("handler/ajaxpage.aspx?action=userinfobar&" + Math.ceil(Math.random() * 100000000),
          function(txt) {
            $("body").prepend(txt);
        });
    }
}

var ExIntro = {
    _brandid: 0,
    _typeId: 0,
    _width: 590,
    _state: false,
    productTemplate: '<table width="590" border="0" cellpadding="0" cellspacing="0">\
                        <tr>\
                          <td width="190" valign="top">\
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">\
                              <tr>\
                                <td height="50" align="center" style="background: #E2D9C3;" id="ProductName"></td>\
                              </tr>\
                              <tr>\
                                <td height="359" valign="top" bgcolor="#F7F2EA">\
                                  <table width="100%" border="0" cellspacing="0" cellpadding="0">\
                                    <tr>\
                                      <td height="23">&nbsp;</td>\
                                    </tr>\
                                  </table>\
                                  <table width="100%" border="0" cellspacing="0" cellpadding="0">\
                                    <tr>\
                                      <td height="150" align="center" id="ProductShow"></td>\
                                    </tr>\
                                    <tr>\
                                      <td height="30">\
                                        <table width="65%" border="0" align="center" cellpadding="0" cellspacing="0">\
                                        <tr>\
                                        <td height="8">\
                                        </td>\
                                        </tr>\
                                          <tr>\
                                            <td align="center" id="ProductBigPhoto"><a target="_blank" class="brown"><img src="images/zoom.gif" border="0" align="absmiddle">点击图片查看大图</a></td>\
                                          </tr>\
                                        </table>\
                                      </td>\
                                    </tr>\
                                  </table>\
                                  <br /><br /><br /><br /><br /><br /><br /><br />\
                                  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">\
                                    <tr>\
                                      <td height="24" align="center"><a href="#" onclick="return false;" id="JoinBrand"><img src="images/join.gif" style="border: none;" /></a>&nbsp;&nbsp;<a href="#" onclick="return false;" id="CallCS"><img src="images/callcs.gif" style="border: none;" /></a></td>\
                                    </tr>\
                                  </table>\
                                </td>\
                              </tr>\
                            </table>\
                          </td>\
                          <td>\
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">\
                              <tr>\
                                <td height="410" valign="top" background="images/E-shop_1_31.jpg">\
                                  <table width="100%" border="0" cellspacing="0" cellpadding="0">\
                                    <tr>\
                                      <td width="78%" height="45">&nbsp;</td>\
                                      <td width="10%" align="center"><a href="#" onclick="javascript:print(); return false;" class="brown">打印</a></td>\
                                      <td width="12%" align="center"><a href="#" onclick="return false;" id="ClosePanel" class="brown">关闭</a></td>\
                                    </tr>\
                                  </table>\
                                  <table width="355" border="0" align="center" cellpadding="0" cellspacing="0">\
                                    <tr>\
                                      <td height="38" background="images/E-shop_1_32.jpg">\
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0">\
                                          <tr>\
                                            <td height="15"><b>编号：</b></td>\
                                            <td><b>规格：</b></td>\
                                            </tr>\
                                          <tr>\
                                            <td height="15" id="ProductModel"></td>\
                                            <td id="ProductSize"></td>\
                                            <td id="WholeSalePrice"></td>\
                                          </tr>\
                                        </table>\
                                      </td>\
                                    </tr>\
                                    <tr>\
                                      <td height="25">&nbsp;</td>\
                                    </tr>\
                                  </table>\
                                  <div class="introContent">\
                                  <table width="330" border="0" cellpadding="0" cellspacing="0">\
                                    <tr>\
                                      <td>\
                                        <div style="line-height: 18px" id="ProductIntro"></div>\
                                        <div style="line-height: 18px" id="ProductEfficacy"><b>特性：</b><br></div>\
                                        <div style="line-height: 18px" id="ProductSkin"><br><b>适用肌肤：</b><br></div>\
                                      </td>\
                                    </tr>\
                                  </table>\
                                  </div>\
                                </td>\
                              </tr>\
                            </table>\
                          </td>\
                        </tr>\
                      </table>',
    classTemplate: '<table width="228" border="0" cellpadding="0" cellspacing="1" bgcolor="#d7d7d7">\
                          <tr>\
                            <td height="20" align="right" bgcolor="#9C9A9B"> <a href="#" onclick="return false;" class="white" id="ClosePanel">关闭</a> <img src="images/pop-up_close.gif" width="7" height="8" align="absmiddle" />&nbsp;</td>\
                          </tr>\
                          <tr>\
                            <td bgcolor="#FFFFFF">\
                              <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">\
                                <tr>\
                                  <td height="40" colspan="2" align="center" id="ProgramName"></td>\
                                </tr>\
                                <tr>\
                                  <td height="1" bgcolor="#d7d7d7"></td>\
                                </tr>\
                                <tr>\
                                  <td height="10"></td>\
                                </tr>\
                                <tr>\
                                  <td width="50%" height="50" valign="top" id="BrandName"><strong>·所属品牌:</strong><br /></td>\
                                </tr>\
                                <tr>\
                                  <td height="50" valign="top" id="Origin"><strong>·产地:</strong><br /></td>\
                                </tr>\
                                <tr>\
                                  <td height="195" valign="top" id="ProgramBenefits"><strong>·产品功效:</strong><br /></td>\
                                </tr>\
                                <tr>\
                                  <td height="50" align="center"><a href="#" onclick="return false;" id="IntroMore"><img src="images/more.gif" style="border: none;" /></a>&nbsp;&nbsp;&nbsp;<a href="#" onclick="return false;" id="AddCollection"><img src="images/collection_button.gif" style="border: none;" /></a></td>\
                                </tr>\
                                <tr>\
                                  <td height="20" >&nbsp;</td>\
                                </tr>\
                                <tr>\
                                  <td height="20" align="center">如果你对该品牌感兴趣，请点击</td>\
                                </tr>\
                                <tr>\
                                  <td height="20" align="center"><a href="#" onclick="return false;" id="JoinBrand"><img src="images/join.gif" style="border: none;" /></a></td>\
                                </tr>\
                                <tr>\
                                  <td height="13"></td>\
                                </tr>\
                              </table>\
                            </td>\
                          </tr>\
                        </table>',
    absPoint: function(obj) {
        var x = obj.offsetLeft;
        var y = obj.offsetTop;
        while (obj = obj.offsetParent) {
            x += obj.offsetLeft;
            y += obj.offsetTop;
        }
        return { "x": x, "y": y };
    },
    showIntro: function(evt, panel, id) {
        if (ExIntro._state == true) return;

        ExIntro._state = true;
        var srcObj = evt.target || evt.srcElement;
        var parentObj = srcObj.parentNode.offsetParent.parentNode.offsetParent.parentNode;
        $.scrollTo(ExIntro.absPoint(parentObj).x - 150, 500, { axis: 'x' });

        if (ExIntro["intropanel" + panel] != null) {
            $(ExIntro["intropanel" + panel]).animate({ left: "-=146px" }, 700, function() {
                $(srcObj).animate({ left: "+=146px" }, 700, function() {
                    ExIntro["intropanel" + panel] = srcObj;
                    ExIntro.openIntro(panel, id, parentObj);
                    ExIntro._state = false;
                });
            });
            $("#introPanel" + panel).html("<div style='width: 37px; height: 37px; position: absolute; top: 45%; left: 45%; background: url(images/loading.gif)'>");
        }
        else {
            $(srcObj).animate({ left: "+=146px" }, 700, function() {
                ExIntro["intropanel" + panel] = srcObj;
                ExIntro.openIntro(panel, id, parentObj);
                ExIntro._state = false;
            });
        }
    },
    openIntro: function(panel, id, parentObj) {
        var obj = $("#introPanel" + panel);
        if (obj.width() == 0) {
            $("#mid").animate({ width: "+=" + ExIntro._width + "px" }, 600);
            $(".RightSidebar").animate({ width: "+=" + ExIntro._width + "px" }, 700);

            obj.animate({ width: ExIntro._width + "px" }, 800,
                function() {
                    ExIntro.loadIntro(panel, id);
                    $.scrollTo(ExIntro.absPoint(parentObj).x - 150, 500, { axis: 'x' });
                }
            );
        }
        else {
            ExIntro.loadIntro(panel, id);
        }
    },
    loadIntro: function(panel, id) {
        var obj = $("#introPanel" + panel);
        obj.html("<div style='width: 37px; height: 37px; position: absolute; top: 45%; left: 45%; background: url(images/loading.gif)'>");

        $.getJSON("handler/ajaxpage.aspx?action=getintro&id=" + id,
        function(data) {
            var val = $(ExIntro.productTemplate);
            val.find("#ProductName").append(data.ProductName + "<br>" + data.EnProductName);
            val.find("#ProductShow").append('<a href="ProductPhoto.aspx?id=' + data.ProductID + '" target="_blank"><img src="' + data.ProductShow[0] + '" width="146" height="146" border="0" class="productimg" /></a>');
            val.find("#ProductBigPhoto a").attr("href", "ProductPhoto.aspx?id=" + data.ProductID);
            val.find("#ProductShow a, #ProductBigPhoto a").click(function() { if (Cookie.GetValue('ExUserAuth') == null) { if (confirm('您还没有登录，请先登录。')) { window.open("Login.aspx?url="+encodeURI("ProductPhoto.aspx?id="+data.ProductID),"newin");return false; } else { return false; } } });
//            if (data.WholeSalePrice > 0) {
//                val.find("#WholeSalePrice").append("￥" + data.WholeSalePrice);
//            } else {
//                val.find("#WholeSalePrice").hide();
//                val.find("#WholeSalePriceName").hide();<td id="WholeSalePriceName"><b>价格：</b></td>\
//            }
            val.find("#ProductModel").append(data.ProductModel);
            val.find("#ProductSize").append(data.ProductSize);
            if (data.ProductEfficacy.length == 0) {
                val.find("#ProductEfficacy").hide();
            } else {
                val.find("#ProductEfficacy").append(data.ProductEfficacy);
            }
            if (data.ProductSkin.length == 0) {
                val.find("#ProductSkin").hide();
            } else {
                val.find("#ProductSkin").append(data.ProductSkin);
            }
            val.find("#ProductIntro").append(data.ProductIntro);
            val.find("#ClosePanel").click(function() { ExIntro.closeIntro(panel); });
            val.find("#JoinBrand").click(function() { Ex.showJoinBrand(data.BrandID); });
            val.find("#CallCS").click(function() { Ex.callCS(data.BrandID); });
            obj.html(val);
        });
    },
    showClassIntro: function(evt, panel, id) {
        if (ExIntro._state == true) return;

        var srcObj = evt.target || evt.srcElement;
        var parentObj = srcObj.offsetParent.offsetParent;
        $.scrollTo(ExIntro.absPoint(parentObj).x - 250, 500, { axis: 'x' });

        var obj = $("#introPanel" + panel);
        if (obj.width() == 0) {
            $("#mid").animate({ width: "+=" + ExIntro._width + "px" }, 700);
            $(".RightSidebar").animate({ width: "+=" + ExIntro._width + "px" }, 750);

            obj.animate({ width: ExIntro._width + "px" }, 800,
                function() { ExIntro.loadClassIntro(panel, id); }
            );
        }
        else {
            ExIntro.loadClassIntro(panel, id);
        }
    },
    loadClassIntro: function(panel, id) {
        var obj = $("#introPanel" + panel);
        obj.html("<div style='width: 37px; height: 37px; position: absolute; top: 45%; left: 40%; background: url(images/loading.gif)'>");

        $.getJSON("handler/ajaxpage.aspx?action=getclassintro&id=" + id,
        function(data) {
            var val = $(ExIntro.classTemplate);
            val.find("#ProgramName").append(data.ProgramName + "<br>" + data.EnProgramName);
            val.find("#BrandName").append("<a href='BrandIntro.aspx?brandid='" + data.BrandID + " style='color: #000;'>" + data.BrandName + "</a>");
            val.find("#Origin").append(data.Origin);
            val.find("#ProgramBenefits").append("　　" + (data.ProgramBenefits.length > 100 ? data.ProgramBenefits.substring(0, 100) + ".." : data.ProgramBenefits));
            val.find("#ClosePanel").click(function() { ExIntro.closeIntro(panel); });
            val.find("#IntroMore").click(function() { ExIntro.showClassBox(id); });
            val.find("#AddCollection").click(function() { Ex.addTempShelf(id, 2); });
            val.find("#JoinBrand").click(function() { Ex.showJoinBrand(data.BrandID); });
            obj.html(val);
        });
    },
    closeIntro: function(panel) {
        ExIntro._state = true;

        $(ExIntro["intropanel" + panel]).animate({ left: "-=146px" }, 700, function() { ExIntro["intropanel" + panel] = null; });

        var obj = $("#introPanel" + panel);
        obj.animate({ width: "0px" }, 600, function() { obj.html(""); });
        $(".RightSidebar").animate({ width: "-=" + ExIntro._width + "px" }, 700);
        $("#mid").animate({ width: "-=" + ExIntro._width + "px" }, 800, function() { ExIntro._state = false; });
    },
    showProductBox: function(id) {
        tb_show("", "ProductPop.aspx?id=" + id + "&TB_iframe=true&height=440&width=655&modal=true", false);
    },
    showClassBox: function(id) {
        tb_show("", "ProgramPop.aspx?id=" + id + "&TB_iframe=true&height=470&width=675&modal=true", false);
    }
}
var Cookie = {
    GetValue: function(name) {
        var value = null;
        var cookie = document.cookie;
        var cookies = cookie.split(";");
        $.each(cookies, function(i) { 
            var cookieName = cookies[i].substring(0, cookies[i].indexOf("="));
            if (cookieName.replace(/(^\s*)|(\s*$)/g, "") == name) {
                value = cookies[i].substring(cookies[i].indexOf("=") + 1);
            }
        });
        return value;
    },
    SetValue: function(name, value, expires) {
        document.cookie = name + "=" + escape(value) + (expires == null || expires == undefined ? "" : "; expires=" + expires.toGMTString())
    }
}
var SearchAutoComplete = {
    obj: null,
    button: null,
    tips: null,
    tips_ishave: false,
    index: -1,
    initialize: function(obj, button, tips) {
        this.obj = $("#" + obj);
        this.button = $("#" + button);
        this.tips = $("#" + tips);
        this.obj.keyup(function(e) {
            if (e.keyCode == 38)
                SearchAutoComplete.SelectItem(-1);
            else if (e.keyCode == 40)
                SearchAutoComplete.SelectItem(1);
            else
                SearchAutoComplete.GetDate();
        }).focus(function() {
            SearchAutoComplete.obj.select();
        }).blur(function() {
            if (SearchAutoComplete.obj.val() == "") {
                SearchAutoComplete.obj.val("请输入展位号或品牌名");
            }
            if (SearchAutoComplete.tips_ishave == false) {
                SearchAutoComplete.tips.hide();
            }
        }).keydown(function(e) {
            if (e.keyCode == 13) {
                SearchAutoComplete.button.focus();
            }
        });
    },
    GetDate: function() {
        if (this.obj.val().length > 0) {
            $.get("handler/ajaxpage.aspx?action=searchautocomplete&key=" + encodeURI(this.obj.val()),
            function(txt) {
                if (txt.length > 0) {
                    SearchAutoComplete.ShowTips(txt);
                    SearchAutoComplete.tips.show();
                } else {
                    SearchAutoComplete.tips.hide();
                }
            });
        } else {
            SearchAutoComplete.tips.hide();
        }
    },
    ShowTips: function(txt) {
        this.index = -1;
        var arr = txt.split('|');
        SearchAutoComplete.tips.html("");
        $.each(arr, function(i, item) {
            var itemobj = $('<div style="height: 13px; line-height: 15px; overflow: hidden; cursor: default; padding: 3px;">' + item + '</div>').mousemove(function() {
                SearchAutoComplete.tips.children("div").css("color", "").css("background", "");
                $(this).css("color", "#352E2C").css("background", "#DDD1BB");
                SearchAutoComplete.index = i;
                SearchAutoComplete.tips_ishave = true;
            }).mouseout(function() {
                SearchAutoComplete.tips_ishave = false;
            }).click(function() {
                SearchAutoComplete.obj.val(decodeURI($(this).text()));
                SearchAutoComplete.button.click();
                SearchAutoComplete.tips.hide();
            });
            SearchAutoComplete.tips.append(itemobj);
        });
    },
    SelectItem: function(num) {
        var arr = this.tips.children("div");
        this.index += num;
        if (this.index < 0) this.index = arr.length - 1;
        if (this.index > arr.length - 1) this.index = 0;
        arr.each(function(i, item) {
            if (SearchAutoComplete.index == i) {
                $(item).css("color", "#352E2C").css("background", "#DDD1BB");
                SearchAutoComplete.obj.val(decodeURI($(item).text()));
            } else {
                $(item).css("color", "").css("background", "");
            }
        });
    }
}
function RenderInit() {
	offsetX = 10;
	offsetY = 20;
	altPop = null;

	document.write("<div id='popLayer' style='position:absolute;visibility: hidden;background: #FFFFFF; border: 1px solid #F5BC41; color: #000000; font-size: 12px; padding: 3px 5px 2px;'></div>");

	document.onmouseover=function(e) { if (!e) showPopupText(window.event); else showPopupText(e); };
}
function showPopupText(event) {
	var o=event.srcElement ? event.srcElement : event.target;
	if(o.alt!=null && o.alt!="") { o.pop=o.alt;o.alt="" }
	if(o.title!=null && o.title!=""){ o.pop=o.title;o.title="" }
	if(o.pop!=altPop) {
		altPop=o.pop;
		if(altPop==null || altPop=="") {
			document.getElementById("popLayer").style.visibility="hidden";	
		} else {
			document.getElementById("popLayer").style.left=document.documentElement.scrollLeft+event.clientX+offsetX+"px";
			document.getElementById("popLayer").style.top=document.documentElement.scrollTop+event.clientY+offsetY+"px";
			document.getElementById("popLayer").style.visibility="visible";
			document.getElementById("popLayer").innerHTML="<nobr>" + altPop + "</nobr>";
			document.onmousemove=function(e) { if (!e) showIt(window.event); else showIt(e); };
		}
	}
}

function showIt(event) {
	if(document.getElementById("popLayer").style.visibility=="visible"){
		document.getElementById("popLayer").style.left=document.documentElement.scrollLeft+event.clientX+offsetX+"px";
		document.getElementById("popLayer").style.top=document.documentElement.scrollTop+event.clientY+offsetY+"px";
	}
}