/***This File forbidden relative  path，please use variable 'jiayi9www'***/

var loginUrl = "http://www.jiayi9.com/";
if (!WebSite) {
    var WebSite = "http://www.jiayi9.com";
    var WebSiteHttps = "https://www.jiayi9.com";
}
/*商品数*/
var itemCount = 0;
$(document).ready(function() {
    /*设置用户信息*/
    setShoppingCar();
    /*$("#spanCount").DMenu("#content");*/

    /*放在site_nav中调用此函数,因为在帮助中心中,$("#welcome")是后生成的.*/
    /*setLoginInfo();*/
});
function setLoginInfo() {
    if (hasLogin()) {
        setWelcome();
    }
}
/*判断用户是否登录*/
function hasLogin() {
    return getCookie("UserLogin") != "";
}

/*异步获取用户登录名称.*/
function setWelcome() {
    $.getScript("GetUserName.ashx", function() {
    if (typeof (data) != undefined && typeof (data) != "undefined" && data != "") {
            $("#login").html("<a class='top'  href='" + WebSiteHttps + "/login/UserLoginOut.aspx' target='_parent' >退出登录</a>");
            $("#welcome").html("您好，<a class='top'  href='" + WebSiteHttps + "/UserCenter/OrderList.aspx' >" + data + "</a>。<a class='top'  href='" + WebSiteHttps + "/Login/UserLoginOut.aspx' target='_parent' >退出登录</a>");
        }
        else {
            return;
        }
    }
        );
}

/*获取购物车内的物品数*/
function setShoppingCar() {

    var ShoppingCarInfocookie = getShoppingCookie("ShoppingCarInfo", false);
    if (ShoppingCarInfocookie != null && ShoppingCarInfocookie != "undefined" && ShoppingCarInfocookie.length > 0 && ShoppingCarInfocookie.indexOf("undefined") < 0 && ShoppingCarInfocookie.indexOf("null") < 0) {
        var cookies = ShoppingCarInfocookie.split("$");

        if (cookies.length > 0) {
            $("#prdCount").html(cookies[1]);
            $("#price").html(parseInt(cookies[0]) + "");
        } else {
            $("#prdCount").html(0);
            $("#price").html(0);
        }
    }
    else {
        var urlArray = new Array();
        urlArray.push("http://www.jiayi9.com");
        urlArray.push("GetUserShoppingCarInfo.ashx");
        $.getScript(urlArray.join(""), function() {

            if (typeof car_info != 'undefined' && car_info != "") {
                $("#prdCount").html((car_info.TotCount > 0 ? car_info.TotCount + GetPrizeCout() : car_info.TotCount));
                $("#price").html(car_info.TotMoney + "");

                var exp = new Date();
                exp.setTime(exp.getTime() + 15 * 24 * 60 * 60 * 1000);
                setShoppingCookie("ShoppingCarInfo", $("#price").html() + "$" + $("#prdCount").html(), exp, false);
            }
        });
    }


}
/*获取赠品的数量*/
function GetPrizeCout() {
    var t = 0;
    var noLargessSelected = getCookie("noLargessSelected");
    var Rules_Product = getCookie("MustHasSKU");
    if (noLargessSelected != "undefined" && noLargessSelected != "") {
        var obj = noLargessSelected.split("@");
        for (var i = 0; i < obj.length; i++) {
            var Largess = obj[i].split("$");
            if (Largess.length > 1) {
                var Prouductobj = Largess[1].split(",");
                for (var j = 0; j < Prouductobj.length; j++) {
                    var Product = Prouductobj[j].split("|");
                    t += parseInt(Product[1]);
                }
            }
        }
    }
    if (Rules_Product != "undefined" && Rules_Product != "") {
        var obj = Rules_Product.split("@");
        for (var i = 0; i < obj.length; i++) {
            var Largess = obj[i].split("$");
            if (Largess.length > 1) {
                var Prouductobj = Largess[1].split(",");
                for (var j = 0; j < Prouductobj.length; j++) {
                    t += 1;
                }
            }
        }
    }
    return t;
}
function getShoppingCookie(c_name, doEsc) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length; value = document.cookie.substring(c_start, c_end);
            return doEsc ? unescape(value) : value;
        }
    }
    return "";
}
function setShoppingCookie(c_name, value, expires, doEsc) {
    document.cookie = c_name + "=" + (doEsc ? escape(value) : value) +
((expires == null) ? ";" : ";expires=" + expires + ";") + "path=/;domain=.jiayi9.com;";
}
