﻿function hideblock(id) { $("#" + id).hide(); }
function showblock(id) { $("#" + id).show(); }
var toggleHunboUsers = false;
function getHunboUsers() {
    $.getScript("http://www.bloves.com/AjaxServer/GetHunboUsers.ashx?rnd=" + new Date().getTime(), function() {
        $(".head_custom").hide();
        if (window.hunboUsers && window.hunboUsers.length > 0 && $("#Marhead").length === 1) {
            var $userListObj = $("#Marhead").hide();
            for (i = 0; i < hunboUsers.length; i++) {
                $userListObj.html($userListObj.html() + "<li><span><label>" + hunboUsers[i].c + "</label>成功预约<label>" + hunboUsers[i].s + "</label></span></li>");
            }
            $userListObj.show();

            $(".head_custom").eq(1).show();
            if (!toggleHunboUsers) {
                setTimeout(startHeader, stoptimeHeaderObj);
                toggleHunboUsers = true;
            }
        }
        else {
            $(".head_custom").eq(0).show();
        }
    })
}

(function() {
    $.getScript("http://passport.bloves.com/AjaxServer/GetLoginUserID.ashx?rnd=" + new Date().getTime(), function() {
        if (window.blovesUser && window.blovesUser.success === 1) {
            var dispName = "您好！" + window.blovesUser.name;
            $("#aLogin").html(dispName).attr("href", "http://account.bloves.com/MyAccount.aspx");
            $("#aRegister").html("退出").attr("href", "http://passport.bloves.com/LoginOut.ashx");

        } else {
            $("#aLogin").html("登录").attr("href", "http://passport.bloves.com/login.aspx");
            $("#aRegister").html("注册").attr("href", "http://passport.bloves.com/Register.aspx");
        }
    });

    getHunboUsers();
})();
function keydown() { if (event.keyCode == 13) { $("#search_btn").click(); } }
function cleartext(id) { $("#" + id).val(""); keydown(); }

function searchProduct(evt) {
    evt = window.event || evt;
    if (window.event) window.event.returnValue = false;
    else evt.preventDefault();
    var keyword = $.trim($("#txtSearch5").val());
    if (keyword)
        location.href = "http://www.bloves.com/Search/Search.aspx?keyword=" + escape(keyword);
}

function getCartItemCount() {
    $.getScript("http://shopping.bloves.com/AjaxServer/GetCartObejctCount.ashx" + "?ran=" + Math.random(), function() {
        if (window.blovesCartCount && window.blovesCartCount > 0) {
            $("#spnCartObjectCount").html(blovesCartCount);
            $("#spnHeaderCartObjectCount").html(blovesCartCount);
        }
    });
}
function GetVerdict(chkId, nameId, contentId) {
    if (!$("#" + chkId)[0].checked) {
        if ($("#" + nameId).val().length == 1) {
            alert("评论昵称不能为空！");
            return false;
        }
    }
    if ($("#" + contentId).val().length == 1) {
        alert("评论内容不能为空！");
        return false;
    }
    return true;
}
function AutoScroll(obj) {
    $(obj).find("ul:first").animate({
        marginTop: "-20px"
    }, 500, function() {
        $(this).css({ marginTop: "0px" }).find("li:first").appendTo(this);
    });
}

function showHidde(objId, x, theProp, theValue) { //v9.0
    var obj = null; with (document) {
        if (getElementById)
            obj = getElementById(objId);
    }
    if (obj) {
        if (theValue == true || theValue == false)
            eval("obj.style." + theProp + "=" + theValue);
        else eval("obj.style." + theProp + "='" + theValue + "'");
    }
};

//显示商务通在线资讯
function showService() {
    var cw = document.body.clientWidth;
    var conw = document.getElementById("container").offsetWidth;
    $("#customer_service").show();

    var width = document.getElementById("customer_service").offsetWidth;
    return document.getElementById("customer_service").style.marginLeft = (cw - 20 - width - (cw - conw) / 2) + "px"

}

//显示分期付款
function showPaymentByInstalments() {
    $(".stage_div").show();
}
//隐藏分期付款
function hidePaymentByInstalments() {
    $(".stage_div").hide();
}
//处理当前菜单样式
(function() {
    var nav = document.getElementById("globalNav");
    if (!nav) return false;
    var links = nav.getElementsByTagName("a");
    var currenturl = window.location.href;
    var regExpPrefix = /(^http:\/\/www\.)|(^http:\/\/)/;
    var regExpPostfix = /(\/$)|(\/index\.html$)/;
    for (var i = 0; i < links.length; i++) {
        var linkurl = links[i].getAttribute("href");
        //判断链接是否为首页
        if (linkurl.toLowerCase().replace(regExpPrefix, "").replace(regExpPostfix, "") == "bloves.com" || linkurl == "/") {
            if (currenturl.toLowerCase().replace(regExpPrefix, "").replace(regExpPostfix, "") == "bloves.com") {
                links[i].className = "active dropdownTab";
                var curr_li_id = links[i].parentNode.getAttribute("id");
                if (curr_li_id == "last") { links[i].parentNode.childNodes[0].className = "nonew"; }
                break;
            }
        } else if (currenturl.indexOf(linkurl) != -1) {
            links[i].className = "active dropdownTab";
            var curr_li_id = links[i].parentNode.getAttribute("id");
            if (curr_li_id == "last") { links[i].parentNode.childNodes[0].className = "nonew"; }
            break;
        }
    }
})();

//显示子菜单
$("#navString").find("li").each(function() {
    $(this).hover(
                function() { $(this).addClass("nav_over"); $("#globalSerach").addClass("hiddenslt"); },
                function() { $(this).removeClass("nav_over"); $("#globalSerach").removeClass("hiddenslt"); }
    );
});

var MarHeaderObj = document.getElementById("Marhead");
var child_div_obj = MarHeaderObj.getElementsByTagName("li")
var picHeaderObj = 20; //头部的移动高度
var scrollstepHeaderObj = 1; //移动步幅,越大越快
var scrolltimeHeaderObj = 200; //移动频度(毫秒)越大越慢
var stoptimeHeaderObj = 1; //间断时间(毫秒)
var tmpHeader = 0;
MarHeaderObj.innerHTML += MarHeaderObj.innerHTML;

function startHeader() {
    if (tmpHeader < picHeaderObj) {
        tmpHeader += scrollstepHeaderObj;
        if (tmpHeader > picHeaderObj) tmpHeader = picHeaderObj;
        MarHeaderObj.scrollTop = tmpHeader;
        setTimeout(startHeader, scrolltimeHeaderObj);
    } else {
        tmpHeader = 0;
        MarHeaderObj.appendChild(child_div_obj[0]);
        MarHeaderObj.scrollTop = 0;
        setTimeout(startHeader, stoptimeHeaderObj);
    }
}

//读取门店菜单
(function GetStoreMenu() {
    $.getScript("http://www.bloves.com/AjaxServer/GetAllStores.ashx" + "?ran=" + Math.random(), function() {
        if (window.storeMenu && window.storeMenu.length > 0) {
            $("#gl10").siblings().find(".subitem").html("");
            var storeHtml = "";
            for (i = 0; i < storeMenu.length; i++) {
                storeHtml += '<dd><a href="' + storeMenu[i].u + '" title="' + storeMenu[i].a + '">' + storeMenu[i].n + '</a></dd>';
            }
            $("#gl10").siblings().find(".subitem").html(storeHtml);
        }
    });
})();
