﻿//if (top.location != window.location) { top.location = window.location; }

var _SEARCH_HINT = "请输入关键字";

function doSearch() {
    var _w = $("#w");
    var _str = _w.val().trim();
    if (_str == _SEARCH_HINT) {
        _str = "";
    }
    var _url = "/category.aspx?w=" + encodeURIComponent(_str);
    window.location = _url;
}
function doSearch1() {
    var _w = $("#w1");
    var _str = _w.val().trim();
    if (_str == _SEARCH_HINT) {
        _str = "";
    }
    var _url = "/category.aspx?w=" + encodeURIComponent(_str);
    window.location = _url;
}

function updown(i,classname) {
    $("#imglst_ad_def").stop(true, false);
    $("#imglst_ad_def li").eq(i).show(500).siblings().hide(500);
    $("#navlst_ad_def li").eq(i).addClass("on").siblings().removeClass("on");
    $(".bottom ul").eq(i).show().siblings().hide();
    $("#slide_ad").attr("class", "def" + (i + 1));
    //$("#slide_ad").attr("class", classname);
}

function setblheight() {
    var bc_h = $(".page .bc").css("height");
    $(".page .bl").css("height", bc_h);
    $(".page .br").css("height", bc_h);
}

$(document).ready(function () {
    setblheight();

    var def_tab = $(".tab li");
    def_tab.each(function (i) {
        $(this).click(function () {
            $(this).addClass("on");
            $(this).siblings().removeClass("on");
            var _div = $("#id" + (i + 1).toString());
            _div.show();
            _div.siblings().hide();
            //lazyloadimg();
        })
    })

    $(".ul_rl li").each(function (i) {
        var _div = $("#show" + (i + 1));
        $(this).hover(function () {
            $(".rl div").each(function (i) {
                $("#show" + (i + 1)).hide();
            })
            _div.animate({ height: 'show' }, 500);
        }, function () { })
    })

    $(".rl div").each(function (i) {
        var _div = $("#show" + (i + 1));
        _div.hover(function () { }, function () {
            _div.animate({ height: 'hide' }, 500);
        })
    })

    var def_list = $("#l1");
    $("#allPro").click(function () {
        def_list.animate({ height: 'show' }, 500);
    })
    $("#logo").click(function () {
        def_list.animate({ height: 'show' }, 500);
    })
    def_list.hover(function () { }, function () {
        def_list.animate({ height: 'hide' }, 500);
    })

    var def_list2 = $("#l2");
    $("#hotPro").click(function () {
        def_list2.animate({ height: 'show' }, 500);
    })
    def_list2.hover(function () { }, function () {
        def_list2.animate({ height: 'hide' }, 500);
    })

    var def_list3 = $("#l3");
    $("#talentPro").click(function () {
        def_list3.animate({ height: 'show' }, 500);
    })
    def_list3.hover(function () { }, function () {
        def_list3.animate({ height: 'hide' }, 500);
    })

    //$(function () { $("img:not([delay='false'])").lazyload({ placeholder: "http://img.quanshimall.com/grey.gif" }) })

    //搜索处理-->start
    var _w = $("#w");
    var _w1 = $("#w1");

    //_w.val(_SEARCH_HINT).css("color", "#aaa");
    //_w.css("color", "#aaa");
    _w.keydown(function (event) {
        if (event.keyCode == 13) {
            //alert("doSearch");
            doSearch();
            return false;
        }
    })
    _w1.keydown(function (event) {
        if (event.keyCode == 13) {
            doSearch1();
            return false;
        }
    })

    _w.focus(function () {
        _w.val(_w.val().trim());
        _w.val("").css("color", "#000").css("background-color", "#ddd").css("border-color", "#888");
        //        if (_w.val() == _SEARCH_HINT) {
        //            _w.val("").css("color", "#000");
        //        }
    }).blur(function () {
        _w.val(_w.val().trim());
        if (_w.val() == "") {
            _w.val(_SEARCH_HINT).css("color", "#aaa").css("background-color", "#F3F3F3").css("border-color", "#C2C2C2");
        }
    })
    _w1.focus(function () {
        _w1.val(_w1.val().trim());
        _w1.val("").css("color", "#000").css("background-color", "#ddd").css("border-color", "#888");
    }).blur(function () {
        _w1.val(_w1.val().trim());
        if (_w1.val() == "") {
            _w1.val(_SEARCH_HINT).css("color", "#aaa").css("background-color", "#F3F3F3").css("border-color", "#C2C2C2");
        }
    })

    var _b = $("#b");
    _b.click(function () {
        doSearch();
        return false;
    })
    var _b1 = $("#b1");
    _b1.click(function () {
        doSearch1();
        return false;
    })
    //end<--搜索处理

    $(".rank li").each(function (i) {
        $(this).hover(function () {
            $(this).attr("class", "on");
            $("span", this).attr("class", "on");
            $("a", this).attr("class", "on");
            $("img", this).show();
            $("div", this).show();

            $(".rank li").each(function (j) {
                if (j != i) {
                    obj = $(".rank li").eq(j);
                    obj.attr("class", "no");
                    $("span", obj).attr("class", "no");
                    $("a", obj).attr("class", "no");
                    $("img", obj).hide();
                    $("div", obj).hide();
                }
            });
        }, function () { });
    });

    /*图片水平滚动*/
    var _imgIndex = 0;
    var _imgCount = $("#navlst_ad_def li").length;
    $("#navlst_ad_def li").each(function (i) {
        $(this).hover(function () {
            updown(i, $(this).attr("id"));
        }, function () { });
    })
    var timer = function () {
        updown(_imgIndex)
        _imgIndex++;
        if (_imgIndex >= _imgCount) { _imgIndex = 0; }
    }
    var interval = setInterval(timer, 5000);
    $(".slide_ad_def").hover(function () {
        if (interval) {
            clearInterval(interval);
        }
    }, function () {
        interval = setInterval(timer, 5000);
    });


    /*图片垂直滚动*/
    //    var _adIndex = 0;
    //    var _adCount = $("#def_ad_banner li").length;
    //    $("#def_ad_navlst li").each(function (i) {
    //        $(this).hover(function () { updown_banner(i); }, function () { });
    //    })
    //    var _timer = function () {
    //        updown_banner(_adIndex)
    //        _adIndex++;
    //        if (_adIndex >= _adCount) { _adIndex = 0; }
    //    }
    //    var _interval = setInterval(_timer, 3000);
    //    $(".banner").hover(function () {
    //        if (_interval) {
    //            clearInterval(_interval);
    //        }
    //    }, function () {
    //        _interval = setInterval(_timer, 3000);
    //    });
})

function IsProductJT(id) {
    var result = false;
    var arr = new Array("9f4aca6d-71a2-4e45-bfca-9f57011906bf", "9734dd20-2302-4fb6-9509-9f570119bfe2", "3052d597-b4eb-46be-ab30-9f57011a2bce", "92a5a53d-32e1-47fe-8d67-9f57011ce732", "67a92192-3c9a-4f69-8c4d-9f57011da1f6", "b0ae03c5-64a7-4270-9d61-9f57011ddec6");
    for (var i = 0; i < arr.length; i++) {
        if (id == arr[i]) {
            result = true;
            break;
        }
    }
    return result;
}

function IsProductS(id) {
    var result = false;
    var arr = new Array("5e2d2721-3dfc-4ad5-8a7e-9e0000a9d244", "6e704a95-8baf-49e8-b46f-9ead0152c51b", "c3b80c3a-dd32-4ed1-a60d-9ea90105a3f0", "8c5a40ed-3f1a-48c8-b437-9eae00e06af1");
    for (var i = 0; i < arr.length; i++) {
        if (id == arr[i]) {
            result = true;
            break;
        }
    }
    return result;
}

function fnAddCart(proId, shopId, num, name) {
    if (name.indexOf("随意送") != -1) {
        alert("赠送礼品不可以单独购买!");
    }
    else {
        var sUrl = "/_user/cart.aspx?action=add&productid=" + proId + "&shopid=" + shopId + "&amount=" + num;
        window.open(sUrl, "_blank");
    }
    return false;
}

function AddCart(proId, shopId, num, attr, name) {
    if (IsProductS(proId) || IsProductJT(proId)) {
        alert("赠送礼品不可以单独购买!");
    }
    else {
        var sUrl = "/_user/cart.aspx?action=add&productid=" + proId + "&shopid=" + shopId + "&amount=" + num + "&userSelect=" + encodeURIComponent(attr);
        window.open(sUrl, "_blank");
    }
    return false;
}

function AddCartPro(proId, shopId, num, attr, name, stock) {
    if (IsProductS(proId) || IsProductJT(proId)) {
        alert("赠送礼品不可以单独购买!");
    }
    else if (parseInt(stock) < 1) {
        var sUrl = "/wcf/Service.svc/LackProReg?pid=" + proId;
        $.getJSON(sUrl, function (data) { });
        alert("本商品当前缺货，已进行缺货登记！");
    }
    else {
        var sUrl = "/_user/cart.aspx?action=add&productid=" + proId + "&shopid=" + shopId + "&amount=" + num + "&userSelect=" + encodeURIComponent(attr);
        window.open(sUrl, "_blank");
    }
    return false;
}

//分享到<a title="分享到QQ空间" href="http://api.bshare.cn/share/qzone?url=[URL]&title=[title]&content=[content]&pic=[picURL]&publisherUuid=[UUID]" target="_blank" style="text-decoration:none;"><
function share(to, pic) {
    var title = document.title;
    var u;
    switch (to) {
        case "sina":
            u = 'http://v.t.sina.com.cn/share/share.php?title=' + encodeURIComponent(title) + '&url=' + encodeURIComponent(location.href) + '&pic=' + pic;
            if (!window.open(u, 'sina', 'toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330')) { location.href = u; }
            break;
        case "kaixin001":
            u = 'http://www.kaixin001.com/repaste/share.php?rtitle=' + encodeURIComponent(title) + '&rurl=' + encodeURIComponent(location.href) + '&rcontent=' + encodeURIComponent(title);
            if (!window.open(u, 'kaixin', 'toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330')) { location.href = u; }
            break;
        case "qq":
            u = 'http://api.bshare.cn/share/qqmb?title=' + encodeURIComponent(title) + '&url=' + encodeURIComponent(location.href) + '&content=' + encodeURIComponent(title);
            if (!window.open(u, 'qq', 'toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330')) { location.href = u; }
            break;
    }
}


function toUrlByPagerNum(num, urlparm, pageurl) {

    if (parseInt(num) > 0) {
        window.location.href = pageurl + "?page=" + num + urlparm;

    }
}
/* 图片预加载*/
jQuery(document).ready(
function ($) {
    try {
        lazyloadimg();
    }
    catch (e) { }
});

function lazyloadimg() {
    $("img").lazyload({
        placeholder: "/images/grey.gif",
        effect: "fadeIn"
    });
}

window.onload = function () {
    for (var i = 0; i < document.links.length; i++) {
        document.links[i].onfocus = function () { this.blur() }
    }
}

function moveBar() {
    var top = document.documentElement.scrollTop;
    this.scroll(0, top + 1)
} 
