var __cookie = {
    set: function (name, value) {
        var Days = 90;
        var exp = new Date();
        exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
        document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
    },
    get: function (name) {
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null) return unescape(arr[2]); return null;
    },
    empty: function () {
        var name = "shopcar";
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = getCookie(name);
        if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    }
};
(function ($id) {
    var HexToString= function(s){
      var r = '';
      if(!s)return r;
        for (var i = 0; i < s.length; i += 2) {
            var sxx = parseInt(s.substring(i, i + 2), 16);
            r += String.fromCharCode(sxx);
        }
        return r;
    }
    var UNCookie = __cookie.get("UN");
    try {
        if (UNCookie != null) {            
            var to_login = $id('to_login').firstChild;
            to_login.innerHTML = '退出';
            to_login.href = "http://user.learbetty.com/logout.aspx";
            $id('to_login').className = "";
            $id('register_li').style.display = 'none';
            $id('loginalipay_li').style.display = 'none';
            
            $id('my_account_li').firstChild.innerHTML += '(' + HexToString(UNCookie) + ')';	

            var COBS_UN_Cookie = __cookie.get("COBS_UN"); 
            if (COBS_UN_Cookie != null) {
                $id('t_link').style.display = 'none';
                $id('logobar').style.display = 'none';
                $('#keyword').css({ "width": "300px", "border": "1px solid #000", "color": "#000", "background-position": "-191px -418px" });    
                $id('topnav').style.backgroundColor = '#fff';
                $id('topnav').style.padding = '13px 0';
                $id('btn_top_search').style.color = '#fff';
                $id('btn_top_search').style.backgroundColor = '#000';
                $id('FB').style.visible = 'hidden';
                $id('KF').style.visible = 'hidden';

                $id('cobs_un').innerHTML = COBS_UN_Cookie;                           
                $id('cobs_box').style.display = 'block';
                $id('cobs_cart_box').style.display = 'block';

               $('#cobs_act_cancel').click(function () {
                    $.getJSON("http://user.learbetty.com/CreateOrderByService.aspx?OP=Cancel&callback=?", function(data){
                        closePage();
                    });
                })

                function closePage() {
                    window.open('','_self');
                    window.close();                
                } 
            }
        } else {
            $id('my_account_li').style.display = 'none';
        }
    } catch (e) { } 

    var KF_link = $id('KF_link');
    if (KF_link) {
        KF_link.href = 'http://kf1.kishion.com/webCompany.php?arg=KISHION&style=1&keyword=www.learbetty.com&referer='+escape(location.href)+'&username='+encodeURIComponent(HexToString(UNCookie));
    }    

    (new Image()).src="/RefreshUserLoginToken.aspx";
})(function (d) { return document.getElementById(d) });
