﻿var wl = {};
wl.rootpath = function (link) { return 'tongji.aspx' + link; };
wl.addfavorite = function () { if (document.all) { window.external.addFavorite(location.href, document.title); } else if (window.sidebar) { window.sidebar.addPanel(document.title, location.href, ""); } };
wl.homeMenu = function () {
    var memid = $$.cookie.get('member_id'), mname = $$.cookie.get('member_name');
    if (memid && mname) {
        var hour = new Date().getHours(), t;
        if (hour < 6) { t = "凌晨"; }
        else if (hour < 9) { t = "早上"; }
        else if (hour < 12) { t = "上午"; }
        else if (hour < 14) { t = "中午"; }
        else if (hour < 17) { t = "下午"; }
        else if (hour < 19) { t = "傍晚"; }
        else if (hour < 22) { t = "晚上"; }
        else { t = "夜里"; }
        $$.text($$('login_status'), t + '好, <a href="' + wl.rootpath('?') + '"><b>' + mname + '</b></a> 欢迎来到精确统计！ <a href="' + wl.rootpath('?logout') + '">安全退出</a>');
    }
};
wl.listStars = function (id) { $$.each($$.by($$(id), 'em'), function (i, em) { em.parentNode && !em.parentNode.className && ($tool.stars.bind(em)); }); };

wl.prod_buyover = function (o) {
    var lis = $$.by(o, 'li'), change = function (num, i) {
        i = (parseInt(num.value) || 0) + i;
        if (i < 1) { alert('商品最少购买数量为 1 '); } else if (!i || i == NaN || i > 1000000) { alert('请输入正确的商品数量'); }
        num.value = i < 1 || i > 1000000 ? 1 : i;
    };
    $$.each(lis, function (i, li) {
        var as = $$.by(li, 'a'), num = $$.byc(li, 'input');
        $$.each(as, function (i, a) { !a.href && (a.href = 'javascript:void(0);'); });
        num.onchange = function () { change(num, 0); };
        as[0].onclick = function () { change(num, -1); };
        as[1].onclick = function () { change(num, 1); };
    });
};
wl.prod_imgs = function () {
    /*处理产品图片*/
    var bimg = $$('div_bimg'), bs = $$.byc(bimg, 'img').src, over = function () {
        var s = $$.att(this, 'bimg');
        this.className = 'sel';
        if (s === bs) { return; } bs = s;
        $$.text(bimg, '<img src="' + s + '" />');
    }, out = function () { this.className = ''; };
    bs = bs.substr(bs.indexOf('/', 8)).toLocaleLowerCase();
    $$.each($$.by('div_simg', 'li'), function (i, li) {
        li.onmouseover = over;
        li.onmouseout = out;
    });
    /*鼠标放到购买产品数量的时候*/
    //o.onmouseover = null;
    var colors = $$.txt($$('div_color')).split(','), dbuy = $$('div_buy');
    if (colors.length > 0) {
        var d = [];
        $$.each(colors, function (i, txt) {
            var m = txt.split('#'); if (m.length != 3) { return; }
            d.push('<li><span><em style="color:' + m[1] + ';background-color:' + m[2] + '">' + m[0] + '</em><a  class="pbuyqua">-</a><input type="text" class="ctxt" size="2" maxlength="6" value="1" /><a  class="pbuyqua">+</a></span><a class="pbuycar" href="#" >加入购物车</a><a class="pbuyadd" href="#">加关注</a></li>');
        });
        if (d.length > 0) { $$.text(dbuy, d.join('')); }
    }
};
