﻿function setmain(storyno) {
    for (var i = 1; i <= 4; i++) {
        if (storyno == i) {
            window.document.getElementById("main_link" + i).style.display = '';
            window.document.getElementById('offer' + i).style.backgroundColor = '#F2F2F2';
        }
        else {
            window.document.getElementById("main_link" + i).style.display = 'none';
            window.document.getElementById('offer' + i).style.backgroundColor = '#FFFFFF';
        }
    }
}

function rotateoffers() {
    if (!inoffer) {

        for (var i = 1; i <= 4; i++) {
            if (dispoffer == i) {
                window.document.getElementById("main_link" + i).style.display = '';
                window.document.getElementById('offer' + i).style.backgroundColor = '#F2F2F2';
            }
            else {
                window.document.getElementById("main_link" + i).style.display = 'none';
                window.document.getElementById('offer' + i).style.backgroundColor = '#FFFFFF';
            }
        }
        dispoffer++;
        if (dispoffer == 5) {
            dispoffer = 1;
        }
    }
}

function rotateNews() {
    for (var i = 1; i <= totstories; i++) {
        if (storyno == i) {
            window.document.getElementById("story" + i).style.display = '';
        }
        else {
            window.document.getElementById("story" + i).style.display = 'none';
        }
    }
    storyno++;
    if (storyno == (totstories + 1)) {
        storyno = 1;
    }
}

function startRotate() {
    //window.document.getElementById('offer1').style.backgroundColor = '#F2F2F2';
    //setInterval("rotateNews();rotateoffers();", 4000);
}

function showSubCategory() {
    $("#AllSort dt").mouseover(function() {
        var newDiv = document.getElementById("EFF_div_" + this.id.substr(7));
        this.className = "curr";
        if (newDiv) {
            newDiv.style.display = "block";
            return;
        } else {
            var CLASS_NAME = ($.browser.msie ? ($.browser.version > "7.0") ? "class" : "className" : "class");
            var newDiv_wrap = document.createElement("div");
            newDiv_wrap.setAttribute(CLASS_NAME, "pop_wrap");
            newDiv_wrap.setAttribute("id", "EFF_div_" + this.id.substr(7))
            var newDiv = document.createElement("div");
            newDiv.setAttribute(CLASS_NAME, "pop");
            newDiv_wrap.appendChild(newDiv);
            newDiv.innerHTML = this.nextSibling.innerHTML;
            this.parentNode.insertBefore(newDiv_wrap, this);
            newDiv_wrap.style.display = "block";
        }
        //test/		
        $(".pop_wrap").mouseover(function() {
            $(this).css({ "display": "block" });
            this.nextSibling.className = "curr";
        }).bind("mouseleave", function() {
            $(this).css({ "display": "none" });
            this.nextSibling.className = "";
        })
        //test end/
    }).bind("mouseleave", function() {
        this.className = (this.nextSibling.className == "Dis") ? "curr" : "";
        $(".pop_wrap").css({ "display": "none" });
    });
}

//add by y on 2009-5-14
var LOGINED_ID = (new Cookies()).select("LOGINED_ID");
$(function() {
    //用户已登录
    if (LOGINED_ID != "") {
        $.ajax({
            cache: false,
            url: "/Ajax/memberGet.aspx",
            success: function(msg) {
                var str = '<li>' + msg + "，您好!";
                str += "</li><li><a target=_blank href=\"http://www.lvdodo.com/shopping/cart.aspx\">购物袋</a></li><li><a target=_blank href=\"/Member/Index.aspx\">历史订单</a>";
                str += "</li><li><a href=\"/RemoveUser.aspx\">退出登录</a><li>";
                $("#membStatus").html(str);
            }
        });
    } else {
        $("#membStatus").html("<li><a href=\"/login.aspx\">登录</a></li><li><a href=\"/reg.aspx\">注册</a></li><li><a target=_blank href=\"http://www.lvdodo.com/shopping/cart.aspx\">购物袋</a></li>");
    }

    /*********
    *商品搜索
    *********/
    $("#btnSearch").click(function() {
        search($("#txtKeyWord").val());
    });
    $("#txtKeyWord").keydown(function(event) {
        var evt = event ? event : window.event;
        if (13 == evt.keyCode) search($("#txtKeyWord").val());

    });
});

/*********
*商品搜索
*********/
function search(w) {
    w = w.replace(/'/g, "").replace(/&/g, "＆").replace(/#/g, "＃");
    if (w == "") {
        alert("请输入关键词");
        return;
    }
    //location.href = "/Search/" + encodeURI(w) + ".aspx";
    location.href = "/Search/" + w + ".aspx";
}
