var Cart = {
    bindView: function(a) {
        var b = a.getParent().getParent();
        new QMenu(a, new Element("div", {
            "class": "fmenu",
            style: "text-align:left;top:20;right:0;width:100px;display:none;height:100px;"
        }).inject(b)).addEvent("firstshow",
        function(c) {
            new Ajax(Shop.url.viewcart, {
                update: c.target,
                onSuccess: function() {
                    this.setStyles({
                        width: null,
                        height: null
                    })
                }.bind(c.target)
            }).request()
        }.bind(this))
    },
    _update: function(g, f) {
        try {
            var b = Cookie.get("S[CART]");
            if (b) {
                var j = b.split("-");
                var d = false;
                for (var c = 0; c < j.length; c++) {
                    var a = j[c].split("_");
                    if (a[0] == g) {
                        if (!a[1]) {
                            a[1] = 1
                        }
                        j[c] = g + "_" + (Number(a[1]) + 1);
                        d = true;
                        break
                    }
                }
                if (!d) {
                    j.push(g)
                }
            } else {
                var j = [g]
            }
            Cookie.set("S[CART]", j.join("-"))
        } catch(h) {
            throw h
        }
    },
    countItem: function(a, b) {
        if (a.getAttribute("price")) {
            $E(".itemTotal", b).innerHTML = Cart.moneyFormat(a.getAttribute("price").toFloat() * $E("input[name^=cartNum[]", b).value)
        }
        if (a.getAttribute("point")) {
            $E(".itemTotal", b).innerHTML = a.getAttribute("point").toFloat() * $E("input[name^=cartNum[]", b).value
        }
    },
    update: function(a, c, b, d, e) {
        if (this.updateRequest && this.updateRequest.cancel) {
            this.updateRequest.cancel()
        }
        this.updateRequest = new Request({
            method: "post",
            data: $("form-cart"),
            onRequest: function() {
                var f = $("fix-CartBtn") || new Element("div", {
                    id: "fix-CartBtn"
                }).inject(document.body).setStyles({
                    position: "absolute",
                    background: "#ffffff",
                    visibility: "hidden",
                    zIndex: 2000,
                    opacity: 0.3
                });
                f.setStyles($E(".CartBtn", "form-cart").getCis()).setStyle("visibility", "visible")
            },
            onSuccess: function(f) {
                if (f.contains("totalprice")) {
                    b.setProperty("number", d.value);
                    $("cartTotal").setHTML(f);
                    Cart.countItem(e, b)
                } else {
                    d.value = b.getProperty("number");
                    MessageBox.error(f)
                }
                $("fix-CartBtn").setStyle("visibility", "hidden")
            }
        }).send({
            url: a
        })
    },
    inputUpdate: function(b) {
        b = new Event(b);
        var a = $(b.target);
        for (obj = a.getParent(); ! obj.getAttribute("urlupdate"); obj = obj.getParent()) {}
        if (obj.getProperty("number").toInt() > a.value) {
            a.value = a.value.toInt() + 1;
            var c = $E(".decrease", obj)
        } else {
            a.value = a.value.toInt() - 1;
            var c = $E(".increase", obj)
        }
        b.target = c;
        c.fireEvent("click", b)
    },
    load: function() {
        Cart.els = $E(".CartInfoWrap");
        if (Cart.els.length > 0) {
            if (Cookie.get("S[CART]") && Cookie.get("S[CART]").length > 0) {
                var b = new Ajax(Shop.url.viewcart, {
                    method: "get"
                });
                b.addEvent("onComplete", Cart.updateView);
                b.request()
            } else {
                for (var c = 0; c < Cart.els.length; c++) {
                    Cart.els[c].style.visibility = ""
                }
            }
        }
    },
    add: function(d) {
        new Event(d).stop().target;
        var c = this.getAttribute("buy");
        if (c) {
            var f = Cart.els.length > 0 ? Cart.els[0] : $E(".s-menu-cart");
            if (f) {
                new Event(d).stop();
                var b = new Ajax(Shop.url.addcart, {
                    method: "post",
                    data: "gid=" + c
                });
                if (Cart.els) {
                    b.addEvent("onComplete", Cart.updateView)
                }
                b.request()
            }
        }
    },
    updateView: function(b) {
        for (var a = 0; a < Cart.els.length; a++) {
            Cart.els[a].innerHTML = b;
            Cart.els[a].style.visibility = ""
        }
    },
    selectbuy: function(a) {
        new Ajax(a, {
            method: "post"
        }).request();
        alert("加入购物车成功！")
    },
    shipping_id: 0,
    d_pay: 0,
    is_protect: "false",
    payment: 0,
    checkout: {
        shipping: function(a) {
            if (a && a.value) {
                new Request.HTML({
                    url: Shop.url.shipping,
                    update: "shipping",
                    onRequest: function() {
                        $("shipping").set("text", "loading...")
                    }
                }).post({
                    area: a.value
                })
            }
        },
        setShipping: function(f, c) {
            if (f.id) {
                var d = f.id,
                b;
                b = d.split("_");
                var e = $("shipping").getElementsByTagName("INPUT");
                for (var a = 0; a < e.length; a++) {
                    if (b[0] == "shipping") {
                        if (e[a].id != "protect_" + b[1] && e[a].id != d) {
                            e[a].checked = false
                        }
                        if (e[a].id == "protect_" + b[1]) {
                            if (Cart.is_protect == "true") {
                                e[a].checked = true
                            } else {
                                e[a].checked = false
                            }
                        }
                    } else {
                        if (f.checked) {
                            if (e[a].id != "protect_" + b[1]) {
                                e[a].checked = false
                            }
                            if (e[a].id == "shipping_" + b[1]) {
                                e[a].checked = true;
                                Cart.shipping_id = e[a].value
                            }
                        }
                    }
                }
            }
            if (c == 1) {
                if (f.checked == true) {
                    Cart.is_protect = "true"
                } else {
                    Cart.is_protect = "false"
                }
            } else {
                Cart.shipping_id = f.value
            }
            if ($("shipping_" + Cart.shipping_id).getAttribute("has_cod") == 1) {
				if($("_pay_cod")){
					$("_pay_cod").style.display = "";
					Cart.d_pay = 1
				}
            } else {
                $("_pay_cod").style.display = "none";
                if ($("_pay_cod").getElement("#payment_bank").checked == true) {
                    $("_pay_cod").getElement("#payment_bank").checked = false
                }
                Cart.d_pay = 0
            }
            Cart.checkout.total();
            return
        },
        setCurrency: function(a) {
            if (a.value) {
                new Ajax(Shop.url.payment, {
                    method: "post",
                    onComplete: function() {
                        if ($("shipping_" + Cart.shipping_id).getAttribute("has_cod") == 1) {
                            if($("_pay_cod")){
								$("_pay_cod").style.display = "";
								Cart.d_pay = 1
							}
                        }
                    },
                    update: "payment",
                    data: "cur=" + a.options[a.selectedIndex].value + "&d_pay=" + Cart.d_pay + "&payment=" + Cart.payment,
                    onComplete: function(e, d, f) {
                        $ES("input.x-payMethod", "payment").addEvent("click", Cart.checkout.setPayment)
                    }.bind(this)
                }).request()
            }
            Cart.payment = 0;
            return
        },
        setPayment: function(c, a) {
            Cart.payment = new Event(c).target.value;
            Cart.checkout.total()
        },
        total: function() {
            if ($("is_tax") && $("is_tax").checked == true) {
                var b = "true"
            } else {
                var b = "false"
            }
			var obj = document.getElementById("freeshipping");
			var free_shipping =0;
			if(obj){
				free_shipping = obj.value;
			}
            var a = "shipping_id=" + Cart.shipping_id + "&is_protect=" + Cart.is_protect + "&payment=" + Cart.payment + "&cur=" + $("payment-cur").getValue() + "&is_tax=" + b + "&free_shipping=" + free_shipping;
            if ($E("input[name^=delivery[ship_area]")) {
                a += "&area=" + $E("input[name^=delivery[ship_area]").getValue()
            }
            new Ajax(Shop.url.total, {
                method: "post",
                update: $("amountInfo"),
                data: a,
                onComplete: function(e, d, f) {
                    var obj = document.getElementById("checkout_total");
					obj.innerHTML = e;
                }
            }).request()
        }
    },
    dlgHandler: {},
    getReceiverList: function(a) {
        a = new Event(a).stop();
        Cart.dlgHandler = new Dialog(a.target.href, {
            title: "选取收获地址"
        })
    },
    checkAddr: function(d) {
        d = new Event(d).stop();
        var f = $("addrList").getElementsByTagName("INPUT");
        for (var b = 0; b < f.length; b++) {
            if (f[b].checked) {
                break
            }
        }
        if ( !! !f[b]) {
            return alert("请选择收获地址!")
        }
        var a = f[b].parentNode.parentNode;
        var c = a.getElementsByTagName("TD");
        for (var b = 0; b < c.length; b++) {
            if (c[b].className) {
                if ($(c[b].className)) {
                    $(c[b].className).value = c[b].innerHTML
                }
            }
        }
        Cart.dlgHandler.close()
    },
    moneyFormat: function(a) {
        a = a.toFloat();
        a = a.round(moneyFormat.decimals) + "";
        var b = a.indexOf(".");
        if (b < 0) {
            b = a.length;
            part = ""
        } else {
            part = a.substr(b + 1)
        }
        while (part.length < moneyFormat.decimals) {
            part += "0"
        }
        var d = [];
        while (b > 0) {
            if (b > 2) {
                d.unshift(a.substr(b -= 3, 3))
            } else {
                d.unshift(a.substr(0, b));
                break
            }
        }
        return moneyFormat.sign + d.join(moneyFormat.thousands_sep) + moneyFormat.dec_point + part
    }
};
if ($("form-cart")) {
    $ES(".increase", "form-cart").each(function(a) {
        a.addEvent("click",
        function(c) {
            c = new Event(c).stop();
            var b = c.target;
            for (obj = b.getParent(); ! obj.getAttribute("urlupdate"); obj = obj.getParent()) {}
            $E("input[name^=cartNum[]", obj).value = $E("input[name^=cartNum[]", obj).value.toInt() + 1;
            Cart.update(obj.getAttribute("urlupdate"), null, obj, $E("input[name^=cartNum[]", obj), b)
        })
    });
    $ES(".decrease", "form-cart").each(function(a) {
        a.addEvent("click",
        function(c) {
            c = new Event(c).stop();
            var b = c.target;
            for (obj = b.getParent(); ! obj.getAttribute("urlupdate"); obj = obj.getParent()) {}
            if ($E("input[name^=cartNum[]", obj).value.toInt() > 1) {
                $E("input[name^=cartNum[]", obj).value = $E("input[name^=cartNum[]", obj).value.toInt() - 1;
                Cart.update(obj.getAttribute("urlupdate"), null, obj, $E("input[name^=cartNum[]", obj), b)
            }
        })
    });
    $ES(".quiet", "form-cart").each(function(a) {
        a.addEvent("click",
        function(d) {
            d = new Event(d).stop();
            var c = d.target;
            for (obj = c.getParent(); ! obj.getAttribute("urlremove"); obj = obj.getParent()) {}
            var b = obj.getAttribute("urlremove");
            obj.remove();
            new Ajax(b, {
                method: "post",
                update: "cartTotal",
                data: $("form-cart")
            }).request()
        })
    })
}
if ($("clearCart")) {
    $("clearCart").addEvent("click",
    function(c) {
        c = new Event(c).stop();
        if (window.confirm("确定要清空吗?")) {
            var b = c.target;
            var a = b.getAttribute("url");
            $("cartItems").remove();
            new Ajax(a, {
                method: "post",
                data: "a=a",
                onComplete: function(d) {
                    $("cart-items").remove();
                    $("cart-coupon").remove();
                    $("cart-none-msg").style.display = "inline"
                }
            }).request()
        }
    })
}
Order = {
    url: {},
    updateTotal: function() {
        new Ajax(Shop.url.ordertotal, {
            method: "post",
            update: "order-total",
            data: $("order-create")
        }).request()
    },
    applyCoupon: function(a) {
        $("order-main").set("html", "loading...");
        a = a ? "coupon=" + a: "";
        new Ajax(Shop.url.applycoupon, {
            method: "post",
            update: "order-main",
            data: a
        }).request()
    }
};
if ($("anonymityBuy")) {
    $("anonymityBuy").addEvent("click",
    function(a) {
        Cookie.set("S[ST_ShopEx-Anonymity-Buy]", "true")
    })
}
$ES(".cal").each(function(a) {
    a.makeCalable()
});
var compare_goods = new Class({
    showad: true,
    Toppx: 0,
    PageWidth: window.getWidth() - 210,
    MinScreenW: window.screen.height,
    initialize: function() {
        var a = '<div class="title"><h3 >商品对比 <a class="close fontnormal fontcolorOrange" onClick="show_compare.hidead();return false;" href="#">[关闭]</a></h3></div>';
        var e = "";
        var b = this.vreturn(Cookie.get("S[c_product]"));
        var d = this.vreturn(Cookie.get("S[c_name]"));
        var f = this.vreturn(Cookie.get("S[c_pic]"));
        var c = this.vreturn(Cookie.get("S[c_id]"));
        if ($chk(b)) {
            for (i = 0; i < b.length; i++) {
                e += "<div class='division clearfix' id='goods_" + c[i] + "'><div class='span-3'><span title='" + d[i] + "'><a href='?product-" + c[i] + ".html'>" + d[i] + "</a></span></div><a class='floatRight lnk' href='#' onClick='show_compare.del_compare(" + c[i] + ");return false;'>删除</a></div>"
            }
        }
        window.addEvents({
            scroll: this.scall.bind(this),
            resize: this.scall.bind(this)
        });
        new Element("div").setHTML('<div id="goods_compare" class="FormWrap" style="width:180px;position: absolute;top:-1000px; display:none;z-index:1000">' + a + '<form id="-form-diff" action="' + Shop.url.product_diff + '" method="post" target="_compare_goods"><div id="compare_goods">' + e + '</div><div class="cmpbar"><input type="submit" name="comareing" class="btn_compare" value="对比"><input type="button" name="clearn_compare" class="btn_compare" onClick="show_compare.clean_compare()" value="清空"></div></form></div>').inject(document.body);
        this.scall()
    },
    vreturn: function(a) {
        if (a) {
            return a.split(",")
        } else {
            return a
        }
    },
    scall: function() {
        this.PageWidth = window.getSize().x - 210;
        if (this.showad == false) {
            return
        }
        $("goods_compare").setStyles({
            left: this.PageWidth,
            top: window.getScrollTop(),
            zIndex: 2000
        })
    },
    hidead: function() {
        $("goods_compare").hide();
        if (window.ie6) {
            $$("select").setStyle("visibility", "visible")
        }
    },
    del_compare: function(a) {
        $("goods_compare").show();
        var c = Cookie.get("S[c_product]");
        var b = c.split(",");
        var e = "";
        if (b.length == 1) {
            Cookie.remove("S[c_product]");
            Cookie.remove("S[c_type]");
            Cookie.remove("S[c_name]");
            Cookie.remove("S[c_pic]");
            Cookie.remove("S[c_id]");
            $("compare_goods").innerHTML = ""
        } else {
            for (var d = 0; d < b.length; d++) {
                if (b[d] != a) {
                    e += b[d] + ","
                }
            }
            e = e.substr(0, e.length - 1);
            Cookie.set("S[c_product]", e);
            $("goods_" + a).parentNode.removeChild($("goods_" + a))
        }
    },
    clean_compare: function() {
        Cookie.remove("S[c_product]");
        Cookie.remove("S[c_type]");
        Cookie.remove("S[c_name]");
        Cookie.remove("S[c_pic]");
        Cookie.remove("S[c_id]");
        $("compare_goods").innerHTML = ""
    },
    add_comare_goods: function(b, f, a, g) {
        if (window.ie6 && this.showad) {
            $$("select").setStyle("visibility", "hidden")
        }
        $("goods_compare").show();
        var d = Cookie.get("S[c_product]");
        var h = Cookie.get("S[c_type]");
        var c = Cookie.get("S[c_name]");
        var k = Cookie.get("S[c_pic]");
        var l = Cookie.get("S[c_id]");
        if (h) {
            if (h != g) {
                alert("只能对比同一类型的产品");
                return
            }
        } else {
            h = g;
            Cookie.set("S[c_type]", h)
        }
        if (d) {
            var j = d.split(",");
            if (j.length >= 4) {
                alert("对比的产品不能超过4个");
                return false
            } else {
                for (var e = 0; e < j.length; e++) {
                    if (j[e] == b) {
                        return
                    }
                }
                c = c + "," + a;
                d = d + "," + b;
                k = k + "," + f;
                l = l + "," + b
            }
        } else {
            d = b;
            c = a;
            k = f;
            l = b
        }
        Cookie.set("S[c_product]", d);
        Cookie.set("S[c_name]", c);
        Cookie.set("S[c_pic]", k);
        Cookie.set("S[c_id]", l);
        $("compare_goods").innerHTML += "<div class='division clearfix' id='goods_" + b + "'><div class='span-3'><span title='" + a + "'><a href='?product-" + b + ".html'>" + a + "</a></span></div><a class='floatRight lnk' href='#' onClick='show_compare.del_compare(" + b + ");return false;'>删除</a></div>"
    }
});
window.addEvent("domready",
function() {
    show_compare = new compare_goods()
});
var gStore = {
    _d: {},
    data: function(c) {
        if (!gStore._d[c]) {
            var a = Cookie.get("S[ST_" + c + "]");
            a = $chk(a) && a.length > 0 ? a.split("_") : [];
            for (var b = 0; b < a.length; b++) {
                a[b] = a[b].replace("^&", "_").split(".");
                a[b][0].replace("^#", ".")
            }
            gStore._d[c] = a
        }
        return gStore._d[c]
    },
    add: function(c, b, e, a) {
        if (!a) {
            a = 10
        }
        var d = gStore.data(c);
        if (b && e) {
            gStore._d[c] = d.filter(function(f) {
                return f[1] != e
            });
            gStore._d[c].unshift([b.clean(), e])
        }
        if (gStore._d[c].length == (a + 1)) {
            gStore._d[c].pop()
        }
        gStore.save(c)
    },
    save: function(b) {
        var a = [];
        gStore.data(b).each(function(c) {
            a.push((c[0].replace(".", "^#") + "." + c[1]).replace("_", "^%"))
        });
        Cookie.set("S[ST_" + b + "]", a.join("_"))
    },
    display: function(b, a, c) {
        gStore.data(b).each(function(e) {
            var d = a.replace(/\%GNAME\%/g, e[0]).replace(/\%GID\%/g, e[1]);
            if (c) {
                c.innerHTML += d
            } else {
                document.write(d)
            }
        })
    },
    clear: function(a) {
        Cookie.get("S[ST_" + a + "]", "")
    },
    remove: function(a, b) {
        gStore._d[a] = gStore.data(a).filter(function(c) {
            return c[1] != b
        });
        gStore.save(a)
    },
    toggle: function(c, b, e, a) {
        var d = true;
        gStore._d[c] = gStore.data(c).filter(function(f) {
            if (f[1] == e) {
                d = false;
                return false
            } else {
                return true
            }
        });
        if (d) {
            gStore.add(c, b, e, a)
        } else {
            gStore.save(c)
        }
        return d
    }
};
var goodsStar = {
    els: [],
    init: function() {
        goodsStar.els = $ES(".favViewer");
        var d = gStore.data("FAV");
        var b = $ES("li[star]");
        if (d.length == 0) {
            for (var a = 0; a < b.length; a++) {
                b[a].className = "star-off";
                b[a].addEvent("click", goodsStar.change)
            }
        } else {
            var c = {};
            d.each(function(f) {
                c[f[1]] = true
            });
            b.each(function(f, e) {
                f.className = c[f.get("star")] ? "star-on": "star-off";
                f.addEvent("click", goodsStar.change);
                if (f.hasClass("star-on")) {
                    $E("a", f).setText("已加入收藏")
                }
            })
        }
        goodsStar.page()
    },
    change: function() {
        var b = this.getAttribute("star");
        if (this.className == "star-on") {
            $E("a", this).setText("加入收藏");
            var a = "star-off";
            new Ajax("index.php?member-" + b + "-ajaxDelFav.html", {
                method: "post",
                update: "",
                data: "t=" + new Date().getTime()
            }).request()
        } else {
            $E("a", this).setText("已加入收藏");
            new Ajax("index.php?member-" + b + "-ajaxAddFav.html", {
                method: "post",
                update: "",
                data: "t=" + new Date().getTime()
            }).request()
        }
        var a = gStore.toggle("FAV", this.getAttribute("title"), b, 11) ? "star-on": "star-off";
        $ES("li[star=" + b + "]").each(function(c) {
            c.className = a
        });
        goodsStar.page()
    },
    page: function() {
        var a = "";
        gStore.data("FAV").each(function(b) {
            a += '<li><input type="checkbox" name="goods[]" value="' + b[1] + '" />' + b[0] + "</li>"
        });
        a += "";
        goodsStar.els.each(function(b) {
            $E("ul", b).innerHTML = a;
            b.style.visibility = ""
        })
    }
};
window.addEvent("domready",
function() {
    $ES(".buy-select").each(function(a) {
        new QMenu(a, $E(".buy-select-list", a))
    });
    if ($$(".cart-number") && $$(".cart-number").length) {
        $$(".cart-number").setText(Cookie.get("S[CART_COUNT]") ? Cookie.get("S[CART_COUNT]") : 0)
    }
});
window.addEvent("domready", goodsStar.init);
var GoodsPic = new Class({
    options: {
        readingGlass: false,
        readingGlassWidth: false,
        readingGlassHeight: false
    },
    initialize: function(c, a, b) {
        var b = $extend(this.options, b);
        this.readingGlass = b.readingGlass;
        this.container = $E(".goods-detail-pic-thumbnail");
        this.imgs = $ES("img", this.container);
        this.imgEl = $E(".goods-detail-pic", "goods-viewer").getElement("a");
        if (!this.container || !(this.imgs && this.imgs.length > 0)) {
            return
        }
        this.maxHeight = a || $E(".goods-detail-pic", "goods-viewer").getSize().y;
        this.maxWidth = c || $E(".goods-detail-pic", "goods-viewer").getSize().x;
        this.imgs.each(function(d, e) {
            var f = this;
            d.addEvent("load",
            function(g) {});
            d.getParent("a").addEvent("click",
            function(k) {
                k ? k.stop() : null;
                this.blur();
                var j = this.getParent("td");
                var h = this.getParent("table");
                if (j.hasClass("current")) {
                    return
                }
                var g = h.retrieve("tc");
                if (g) {
                    g.removeClass("current")
                }
                j.addClass("current");
                f.changeImg(d);
                h.store("tc", j)
            })
        },
        this);
        this.imgs[0].getParent("a").fireEvent("click");
        if (this.readingGlass) {
            this.readingGlassBox = new Element("div", {
                styles: {
                    width: b.readingGlassWidth || this.maxWidth,
                    height: b.readingGlassHeight || this.maxHeight,
                    position: "absolute",
                    zIndex: 200,
                    display: "none",
                    background: "#fff",
                    overflow: "hidden",
                    border: "1px solid #333"
                },
                "class": "readingGlassBox"
            }).inject(document.body);
            this.bindreadingGlass(this.imgEl)
        }
    },
    changeImg: function(b, j) {
        j = j || $empty;
        var k = b.src,
        d = b.alt,
        m = b.getParent("a").get("href");
        var e = this.imgEl.empty();
        var h = e.getParent();
        var f = this;
        var g = function(n) {
            e.empty().adopt(n);
            var o = {
                "margin-top": 0
            };
            if (e.getSize().y < h.getSize().y) {
                o = $merge(o, {
                    "margin-top": (h.getSize().y - e.getSize().y) / 2
                })
            }
            e.effects({
                link: "cancel"
            }).start(o)
        };
        if (b.retrieve("imgView")) {
            return g(b.retrieve("imgView"))
        }
        var l = b.get("b_src") || k;
        var c = b.get("c_src") || k;
        h.addClass("goods-detail-pic_loading");
        var a = new Asset.image(l, {
            alt: d,
            onload: function() {
                var n = $(this);
                if (n.$e) {
                    return
                }
                n.zoomImg(f.maxWidth, f.maxHeight);
                h.removeClass("goods-detail-pic_loading");
                e.empty();
                g(n.set("c_src", c));
                b.store("imgView", n);
                n.getParent("a").set("href", m);
                j.call(f, n);
                n.$e = true
            },
            onerror: function() {
                h.removeClass("goods-detail-pic_loading");
                e.setHTML('<span style="diaplay:block;font-family:Verdana;margin:10px;">NO PHOTO</span><hr/><h4>' + d + "</h4>")
            }
        })
    },
    bindreadingGlass: function(a) {
        var b = this;
        a.addEvent("mouseenter",
        function(d) {
            var c = this.getElement("img");
            if (!c) {
                return
            }
            this.setStyle("cursor", "crosshair");
            if (window.ie6) {
                $$("select").setStyle("visibility", "hidden")
            }
            b.readingGlassBox.empty().addClass("goods-detail-pic_loading").setStyle("display", "").setStyles({
                left: $E(".goodsname", "goods-viewer").getPosition().x,
                top: $E(".goodsname", "goods-viewer").getPosition().y + 23
            });
            if (c.retrieve("readingGlassIMG")) {
                c.retrieve("readingGlassIMG").inject(b.readingGlassBox.empty());
                b.readingGlassBox.removeClass("goods-detail-pic_loading");
                a.fireEvent("mousemove", d);
                return
            }
            new Asset.image(c.get("c_src"), {
                onload: function() {
                    if (this.$e) {
                        return
                    }
                    this.inject(b.readingGlassBox.empty());
                    b.readingGlassBox.removeClass("goods-detail-pic_loading");
                    c.store("readingGlassIMG", this);
                    a.fireEvent("mousemove", d);
                    this.$e = true
                }
            })
        });
        a.addEvent("mousemove",
        function(j) {
            var k = j.page;
            var g = this.getSize();
            var h = this.getPosition();
            var f = {
                x: (k.x - h.x).limit(0, g.x),
                y: (k.y - h.y).limit(0, g.y)
            };
            var d = {
                x: (f.x / g.x).toFloat(),
                y: (f.y / g.y).toFloat()
            };
            var c = b.readingGlassBox.getScrollSize();
            b.readingGlassBox.scrollTo((c.x * d.x).toInt() - ((b.options.readingGlassWidth || b.maxWidth) / 2).toInt(), (c.y * d.y).toInt() - ((b.options.readingGlassHeight || b.maxHeight) / 2).toInt())
        });
        a.addEvent("mouseleave",
        function() {
            this.setStyle("cursor", "pointer");
            if (window.ie6) {
                $$("select").setStyle("visibility", "visible")
            }
            b.readingGlassBox.setStyle("display", "none").removeClass("goods-detail-pic_loading")
        })
    }
});
var QMenu = new Class({
    options: {
        overshow: true,
        delay: 500
    },
    initialize: function(b, c, a) {
        this.setOptions(a);
        this.base = $(b);
        this.menu = $(c);
        if (this.options.overshow) {
            this.base.addEvent("mouseover", this.show.bind(this))
        } else {
            this.base.addEvent("click", this.show.bind(this))
        }
    },
    show: function(a) {
        if (!this.showing) {
            this.showing = true;
            if (!this.moreOnce) {
                this.moreOnce = true;
                this.fireEvent("firstshow", {
                    target: this.menu,
                    type: "first"
                });
                if (this.options.overshow) {
                    this.menu.addEvents({
                        mouseover: function() {
                            this.overmenu = true
                        }.bind(this),
                        mouseout: function() {
                            this.overmenu = false;
                            this.hide.delay(this.options.delay, this)
                        }.bind(this)
                    });
                    this.base.addEvent("mouseout",
                    function() {
                        this.overbase = false;
                        this.hide.delay(this.options.delay, this)
                    }.bind(this))
                }
            }
            this.menu.setStyle("display", "");
            this.fireEvent("show", {
                target: this.menu,
                type: "show"
            })
        }
        if (this.options.overshow) {
            this.overbase = true
        }
    },
    hide: function() {
        if (this.showing) {
            if (this.options.overshow && (this.overbase || this.overmenu)) {
                return
            }
            this.showing = false;
            this.menu.setStyle("display", "none");
            this.fireEvent("hide", {
                target: this.menu,
                type: "hide"
            })
        }
    }
});
QMenu.implement(new Events, new Options);
var validatorMap = new Hash({
    required: ["本项必填",
    function(b, a) {
		return true;
        //return a != null && a != ""
    }],
    number: ["请录入数值",
    function(b, a) {
        return a == null || a == "" || !isNaN(a) && !/^\s+$/.test(a)
    }],
    msn: ["请输入MSN",
    function(b, a) {
        return a == null || a == "" || /\S+@\S+/.test(a)
    }],
    skype: ["请输入Skype",
    function(b, a) {
        return a == null || a == "" || !/\W/.test(a) || /^[a-zA-Z0-9]+$/.test(a)
    }],
    digits: ["请录入整数",
    function(b, a) {
        return a == null || a == "" || !/[^\d]/.test(a)
    }],
    unsignedint: ["请录入正整数",
    function(b, a) {
        return a == null || a == "" || (!/[^\d]/.test(a) && a > 0)
    }],
    unsigned: ["请输入大于等于0的数值",
    function(b, a) {
        return a == null || a == "" || (!isNaN(a) && !/^\s+$/.test(a) && a >= 0)
    }],
    positive: ["请输入大于0的数值",
    function(b, a) {
        return a == null || a == "" || (!isNaN(a) && !/^\s+$/.test(a) && a > 0)
    }],
    alpha: ["请录入英文字母",
    function(b, a) {
        return a == null || a == "" || /^[a-zA-Z]+$/.test(a)
    }],
    alphaint: ["请录入英文字母或者数字",
    function(b, a) {
        return a == null || a == "" || !/\W/.test(a) || /^[a-zA-Z0-9]+$/.test(a)
    }],
    alphanum: ["请录入英文字母、中文及数字",
    function(b, a) {
        return a == null || a == "" || !/\W/.test(a) || /^[\u4e00-\u9fa5a-zA-Z0-9]+$/.test(a)
    }],
    date: ["请录入日期格式yyyy-mm-dd",
    function(b, a) {
        return a == null || a == "" || /^(19|20)[0-9]{2}-([1-9]|0[1-9]|1[012])-([1-9]|0[1-9]|[12][0-9]|3[01])+$/.test(a)
    }],
    email: ["请录入正确的Email地址",
    function(b, a) {
        return a == null || a == "" || /(\S)+[@]{1}(\S)+[.]{1}(\w)+/.test(a)
    }],
    text: ["",
    function(b, a) {
        return true
    }],
    select: ["",
    function(b, a) {
        return true
    }],
    radio: ["",
    function(b, a) {
        return true
    }],
    checkbox: ["",
    function(b, a) {
        return true
    }],
    url: ["请录入正确的网址",
    function(b, a) {
        return a == null || a == "" || /^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*)(:(\d+))?\/?/i.test(a)
    }],
    area: ["请选择完整的地区",
    function(b, a) {
        return b.getElements("select").every(function(d) {
            var c = d.getValue();
            return c != "" && c != "_NULL_"
        })
    }]
});
var validator = new Abstract({
    test: function(b, f) {
        f = $(f);
        this.bindBlurWithValidator(b, f);
        var l = [],
        h = f.get("required"),
        e = f.get("vtype"),
        k = f.get("caution");
        extra = b.get("extra");
        if (e && e.contains("&&")) {
            e = e.split("&&")
        }
        if ("true" == h) {
            l.include("required")
        }
        if ( !! e) {
            l.include(e)
        }
        l = l.flatten();
        var a = l.every(function(o) {
            var p = true;
            var n = validatorMap.get(o) || window[o];
            if (!n) {
                return p
            }
            var q = k || n[0];
            var m = n[1];
            p = m(f, f.getValue() ? f.getValue().trim() : "");
            if (!p) {
                this.showCaution(f, q)
            }
            return p
        },
        this);
        if (!a) {
            return false
        }
        if (extra && extra_validator) {
            var j = extra_validator[extra];
            if (!j) {
                return true
            }
            var d = j[e];
            if (!d) {
                return true
            }
            var g = d[0];
            var c = d[1];
            if (!c(b, (f.getVlaue ? f.getVlaue() : f))) {
                this.showCaution(f, g);
                return false
            }
        }
        return true
    },
    showCaution: function(a, c) {
        var b = $(a).getNext();
        if (b && b.get("name") && b.get("name").contains("validationMsgBox")) {
            return
        }
        if (!c || c.trim() == "") {
            return
        }
        new Element("div", {
            "class": "valierror",
            name: "validationMsgBox",
            html: c
        }).injectAfter(a)
    },
    removeCaution: function(a) {
        var b = $(a).getNext();
        if (b && b.get("name") && b.get("name").contains("validationMsgBox")) {
            return b.remove()
        }
    },
    bindBlurWithValidator: function(c, a) {
        var b = $$(a, a.getFormElements());
        b.removeEvents("blur").addEvent("blur",
        function() {
            this.removeCaution(a);
            this.test(c, a)
        }.bind(this))
    }
});
$ES("form").each(function(b, a) {
    if ($chk(b.action)) {
        b.addEvent("submit",
        function(c) {
            if (!b.bindValidator()) {
                c.stop();
                return false
            }
        })
    }
});
if ($("goodsselect")) {
    $("goodsselect").addEvent("click",
    function(b) {
        b = new Event(b);
        var c = $ES("INPUT", "goodsbody");
        for (var a = 0; a < c.length; a++) {
            c[a].checked = $("goodsselect").checked
        }
    })
}
if ($("pkgselect")) {
    $("pkgselect").addEvent("click",
    function(b) {
        b = new Event(b);
        var c = $ES("INPUT", "pkgbody");
        for (var a = 0; a < c.length; a++) {
            c[a].checked = $("pkgselect").checked
        }
    })
}
if ($("giftselect")) {
    $("giftselect").addEvent("click",
    function(b) {
        b = new Event(b);
        var c = $ES("INPUT", "giftbody");
        for (var a = 0; a < c.length; a++) {
            c[a].checked = $("giftselect").checked
        }
    })
} (function() {
    if (window.google && google.gears) {
        return
    }
    var a = null;
    if (typeof GearsFactory != "undefined") {
        a = new GearsFactory()
    } else {
        try {
            a = new ActiveXObject("Gears.Factory");
            if (a.getBuildInfo().indexOf("ie_mobile") != -1) {
                a.privateSetGlobalObject(this)
            }
        } catch(b) {
            if ((typeof navigator.mimeTypes != "undefined") && navigator.mimeTypes["application/x-googlegears"]) {
                a = document.createElement("object");
                a.style.display = "none";
                a.width = 0;
                a.height = 0;
                a.type = "application/x-googlegears";
                document.documentElement.appendChild(a)
            }
        }
    }
    if (!a) {
        return
    }
    if (!window.google) {
        google = {}
    }
    if (!google.gears) {
        google.gears = {
            factory: a
        }
    }
})(); (function() {
    function f() {
        return new Swiff(Shop.set.path + "statics/sop.swf", {
            id: "shareObjectsStorage",
            container: $("shareObjectsStorage_panel"),
            width: "1",
            height: "1"
        })
    }
    f();
    ViewState = new Class({
        initialize: function() {
            this.storage = d() || {};
            return this
        },
        set: function(k, l) {
            this.storage.setStorage = this.storage.setStorage || $empty;
            this.storage.setStorage(k, e(l));
            return this
        },
        get: function(k, l) {
            this.storage.getStorage = this.storage.getStorage || $empty;
            this.storage.getStorage(k, l)
        },
        remove: function(k) {
            if (!k || !this.storage) {
                return false
            }
            this.storage.removeStorage = this.storage.removeStorage || $empty;
            this.storage.removeStorage(k);
            return this
        },
        clear: function() {
            if (!this.storage) {
                return false
            }
            this.storage.clearStorage = this.storage.clearStorage || $empty;
            this.storage.clearStorage();
            return this
        }
    });
    function g(k) {
        return k ? Json.evaluate("(" + k + ")") : null
    }
    function e(k) {
        return k ? Json.toString(k) : null
    }
    function d() {
        if ( !! window.openDatabase) {
            return c.init()
        }
        if (window.google && google.gears) {
            return j.init()
        }
        if ( !! window.sessionStorage) {
            return b.init()
        }
        if (window.ie) {
            return h.init()
        }
        if (Browser.Plugins.Flash.version >= 6) {
            return a.init()
        }
        return false
    }
    var j = {
        init: function() {
            var k;
            try {
                if (!google.gears.factory.create) {
                    return a.init()
                }
                k = google.gears.factory.create("beta.database");
                if (k) {
                    k.open("database-shopex_viewstatus");
                    k.execute("create table if not exists status (skey text, sval text)");
                    this.db = k
                } else {
                    return false
                }
            } catch(l) {
                return a.init()
            }
            return this
        },
        setStorage: function(l, m) {
            var k = this.db.execute("select * from status where skey=?", [l]);
            if (k.isValidRow()) {
                var o = this.db.execute("update status set sval=? where skey=?", [m, l]);
                k.close()
            } else {
                var n = this.db.execute("insert into status values (?,?)", [l, m])
            }
        },
        getStorage: function(l, m) {
            var k = this.db.execute("select * from status where skey=?", [l]);
            if (k.isValidRow()) {
                m(k.field(1))
            } else {
                m()
            }
            k.close()
        },
        removeStorage: function(k) {
            this.db.execute("delete from status where skey=?", [k])
        },
        clearStorage: function() {
            this.db.execute("drop table status")
        }
    };
    var b = {
        init: function() {
            this.Master = "firefox2+ Ie8";
            if (!window.globalStorage) {
                f();
                return a.init()
            }
            this._storage = globalStorage[location.hostname];
            return this
        },
        setStorage: function(k, l) {
            this._storage.setItem(k, l);
            return true
        },
        getStorage: function(k, n) {
            var l = this._storage.getItem(k);
            var m = l ? l.value: null;
            n(m)
        },
        removeStorage: function(k) {
            this._storage.removeItem(k);
            return true
        },
        clearStorage: function() {
            if (this._storage.clear) {
                this._storage.clear()
            } else {
                for (i in this._storage) {
                    if (this._storage[i].value) {
                        this.remove(i)
                    }
                }
            }
            return true
        }
    };
    var h = {
        init: function() {
            this.Master = "ie6+";
            if (!window.ie) {
                return false
            }
            this._storage = new Element("span").setStyles({
                display: "none",
                behavior: "url('#default#userData')"
            }).inject(document.body);
            return this
        },
        setStorage: function(k, l) {
            this._storage.setAttribute(k, l);
            this._storage.save("shopEX_VS");
            return true
        },
        getStorage: function(k, l) {
            this._storage.load("shopEX_VS");
            l(this._storage.getAttribute(k))
        },
        removeStorage: function(k) {
            this._storage.removeAttribute(k);
            this._storage.save("shopEX_VS");
            return true
        },
        clearStorage: function() {
            var k = new Date();
            k.setMinutes(k.getMinutes() - 1);
            this._storage.expires = k.toUTCString();
            this._storage.save("shopEX_VS");
            this._storage.load("shopEX_VS");
            return true
        }
    };
    var a = {
        init: function() {
            this.Master = "flashSharedObject";
            this._storage = $("shareObjectsStorage");
            if (!this._storage.getStorage) {
                return false
            }
            return this
        },
        setStorage: function(k, l) {
            this._storage.setStorage(l, k);
            return true
        },
        getStorage: function(k, l) {
            l(this._storage.getStorage(k))
        },
        removeStorage: function(k) {
            this._storage.removeStorage(k);
            return true
        },
        clearStorage: function() {
            this._storage.cleanStorage();
            return true
        }
    };
    var c = {
        init: function() {
            this.Master = "Safari (Version >= 3.1) openDatabase";
            if (!window.openDatabase) {
                return false
            }
            this._storage = window.openDatabase("viewState", "1.0", "ShopEX48 ViewState Storage", 20000);
            this._createTable();
            return this
        },
        setStorage: function(k, l) {
            this._storage.transaction(function(m) {
                m.executeSql("SELECT v FROM SessionStorage WHERE k = ?", [k],
                function(o, n) {
                    if (n.rows.length > 0) {
                        o.executeSql("UPDATE SessionStorage SET v = ?  WHERE k = ?", [l, k])
                    } else {
                        o.executeSql("INSERT INTO SessionStorage (k, v) VALUES (?, ?)", [k, l])
                    }
                })
            });
            return true
        },
        getStorage: function(k, l) {
            this._storage.transaction(function(m) {
                v = m.executeSql("SELECT v FROM SessionStorage WHERE k = ?", [k],
                function(o, n) {
                    if (n.rows.length > 0) {
                        return l(n.rows.item(0).v)
                    }
                    l(null)
                })
            })
        },
        removeStorage: function(k) {
            this._storage.transaction(function(l) {
                l.executeSql("DELETE FROM SessionStorage WHERE k = ?", [k])
            });
            return true
        },
        clearStorage: function() {
            this._storage.transaction(function(k) {
                k.executeSql("DROP TABLE SessionStorage", [])
            });
            return true
        },
        _createTable: function() {
            this._storage.transaction(function(k) {
                k.executeSql("SELECT COUNT(*) FROM SessionStorage", [], $empty,
                function(l, m) {
                    l.executeSql("CREATE TABLE SessionStorage (k TEXT, v TEXT)", [], $empty)
                })
            })
        }
    }
})();
