document.domain="wataobao.com";

function getCookie(name){
    var search = name + "=";
    var offset = document.cookie.indexOf(search);
    if (offset != -1) {
        offset += search.length;
        var end = document.cookie.indexOf(";", offset);
        if (end == -1){
            end = document.cookie.length;
        }
        return decodeURIComponent(document.cookie.substring(offset, end));
    }else {
        return "";
    }
}
function setCookie(name,value,hours){
    if(arguments.length>2){
        var expireDate=new Date(new Date().getTime()+hours*3600000);
        document.cookie = name + "=" + encodeURIComponent(value) + "; path=/; domain=wataobao.com; expires=" + expireDate.toGMTString();
    }else{
        document.cookie = name + "=" + encodeURIComponent(value) + "; path=/; domain=wataobao.com";
    }
}
var ioCtrl = {
    ioWriter:function(name,value,hours){
        if(G_DAPCTRL_VER>200000){
            this.ioCtrlWriter(name,value,hours||null);
        }else{
            if(hours){
                setCookie(name,value,hours);
            }else{
                setCookie(name,value);
            }
        }
    },
    ioReader:function(name){
        if(G_DAPCTRL_VER>200000){
            return this.ioCtrlReader(name) || "";
        }else{
            return getCookie(name);
        }
    },
    ioCtrlWriter:function(key, value, expires){
        var player = G_OCX_XPLAYER;
        var iExpire = expires || 720;
        player.Put("sCookieFileName", key+".dat");
        player.Put("sCookie", value+"～"+((new Date().getTime()) + iExpire * 3600000));
        player = null;
    },
    ioCtrlReader:function(key){
        var player = G_OCX_XPLAYER;
        var sCookie = null;
        var value = null;
        player.Put("sCookieFileName", key+".dat");
        sCookie = player.Get("sCookie")||null;
        if(null != sCookie){
            value = ioCtrlCheck(sCookie);
        }
        player = null;
        return value;
        function ioCtrlCheck(sCookie){
            var items = sCookie.split("～");
            var curDate = expires = 0;
            var value = null;
            if(items.length != 2){return null;}
            value = ""==items[0]?null:items[0];
            expires = parseInt(items[1], 10);
            curDate = new Date().getTime();
            if(curDate > expires){
                return null;
            }else{
                return value;
            }
        }
    }
};
String.prototype.trim = function(){
	return this.replace(/\s+/gm,"");
}
String.prototype.lTrim = function(){
    return this.replace(/^\s+/gm,"");
}
String.prototype.rTrim = function(){
    return this.replace(/\s+$/gm,"");
}
String.prototype.size = function(){
    return this.replace(/[^\u0000-\u00FF]/gmi, "**").length;
}
function $(s){
	return document.getElementById(s);
}
function $C(tagName){
	return document.createElement(tagName);
}
function $P(child,parent){
	return parent?parent.appendChild(child):document.body.appendChild(child);
}
function $R(child,parent){
	return parent?parent.removeChild(child):document.body.removeChild(child);
}
function getPosition(o){
	var p={Top:0,Left:0};
	while(!!o){
		p.Top+=o.offsetTop;
		p.Left+=o.offsetLeft;
		o=o.offsetParent;
	}
	return p;
}

function getUserInfo(){
	return getCookie('sessionid');
}
function checkUserTypeHandler(){
    var args = arguments;
    var vip = args[0];
    if(1 == vip){$("vip_icon").style.display='inline';}
}
function logout(_target){
	setCookie("sessionid","");setCookie("usrname","");setCookie("nickname","");setCookie("score","");setCookie("order","");
	$("kk_toolbar").innerHTML = getToolbarString(_target);
}
function showProducts(){
    var obj = $('_thunderProduct');
    if(obj){obj.style.display = "block";}
}
function hiddenProducts(){
    var obj = $('_thunderProduct');
    if(obj){obj.style.display = "none";}
}
function setProductsPosition(obj){
    var panel = $('_thunderProduct');
    var pos = getPosition(obj);
    var left = pos.Left;
    var top = pos.Top;
    if(panel){
        panel.style.left = (left - 380) + "px";
        panel.style.top = (top + 12) + "px";
    }
}

function isShowNewIcon(){
    var sTimes = ioCtrl.ioReader("newIcon")||0;
    var iTimes = parseInt(sTimes, 10);
    if(iTimes < 20){
        ioCtrl.ioWriter("newIcon", iTimes+1, 1440);
        return true;
    }
    return false;
}
function getMenuItems(tar){
    var menuItems=[{label:'首页',link:'/',type:0, isNew:false, stat:'A0001;'},{label:'女人街',link:'index-women.html',type:1, isNew:false, stat:'A0002;'},{label:'男人帮',link:'index-men.html',type:2, isNew:false, stat:'A0003;'},{label:'数码',link:'index-3c.html',type:4, isNew:false, stat:'A0004;'},{label:'美食',link:'index-food.html',type:3, isNew:false, stat:'A0005;'},{label:'居家',link:'index-home.html',type:6, isNew:false, stat:'A0006;'},{label:'亲子',link:'index-baby.html',type:7, isNew:false, stat:'A0007;'},{label:'名品百货',link:'index-mall.html',type:'1|1', isNew:true,stat:'A0008;'}];
    var size = menuItems.length;
    var str = '';
    var menu = null;
    var path = location.pathname;
    var prefixPath = path.substring(0, path.lastIndexOf("_"));
    var className = '';
    var type = getMenuType();
    for(var i=0;i<size;i++){
        menu=menuItems[i];
        if(0==i){
            if(path == menu.link || path.indexOf("/index.html")!=-1 || path=="/"){className = ' class="up"';G_IS_HOMEPAGE=true;}
        }else{
            className = (path.indexOf(menu.link)!=-1||type==menu.type)?' class="up"':'';
        }
        str += '<li id="menu'+i+'"'+className+'><a onclick="logForClick(\''+menu.stat+'\')" href="'+menu.link+'"'+tar+'>'+menu.label+'</a>'+((menu.isNew&&isShowNewIcon())?'<span>&nbsp;&nbsp;new</span>':'')+'</li>';
    }
    return str;
}
function printFooter(){
    var str = '<p><a onclick="this.style.behavior=\'url(#default#homepage)\';this.setHomePage(\'http://www.wataobao.com\');" id="homePage" href="javascript:;">设"挖淘宝"为首页</a>|<a href="http://my.taobao.com/mytaobao/guest/my_taobao_guest.htm" target="_blank">我的淘宝</a>|<a href="https://taobao.alipay.com/user/inpour_request.htm?src=yy_mmcm_list_chongzhi" target="_blank">支付宝充值</a>|<a href="http://favorite.taobao.com/collectList.htm" target="_blank">我的收藏</a>|<a href="http://my.taobao.com/mytaobao/rate/my_rate.htm" target="_blank">评价管理</a>|<a href="http://auction1.taobao.com/auction/itemlist/bought_items.jhtml" target="_blank">已买到的宝贝</a>|<a href="http://auction1.taobao.com/auction/itemlist/buying_items.jhtml" target="_blank">竞拍中的宝贝</a>|<a href="http://member1.taobao.com/member/deliver_address.htm" target="_blank">收货地址管理</a>|<a href="http://wuliu.taobao.com/user/order_list_new.htm?order_status_show=send" target="_blank">发货管理</a>|<a href="http://wuliu.taobao.com/user/new_order.htm" target="_blank">推荐物流</a></p>';
    document.write(str);
    setTimeout(function(){if(getUserInfo()){checkUserType();}}, 1500);
}
