document.domain="xunlei.com";
var isIE=(navigator.appName).indexOf("Microsoft")!=-1;if(window.Event&&!isIE){function SearchEvent(){var func=SearchEvent.caller;while(func!=null){var arg=func.arguments[0];if(arg){if(String(arg.constructor).indexOf('Event')>-1){return arg}}func=func.caller}return null};window.constructor.prototype.__defineGetter__("event",function(){return SearchEvent()});Event.prototype.__defineSetter__("returnValue",function(bool){if(!bool){this.preventDefault()}return bool});Event.prototype.__defineSetter__("cancelBubble",function(bool){if(bool){this.stopPropagation()}return bool});Event.prototype.__defineGetter__("clientX",function(){return this.pageX});Event.prototype.__defineGetter__("clientY",function(){return this.pageY});Event.prototype.__defineGetter__("keyCode",function(){return this.which});Event.prototype.__defineGetter__("button",function(){return this.which});Event.prototype.__defineGetter__("srcElement",function(){var n=this.target;while(n.nodeType!=1){n=n.parentNode}return n});Event.prototype.__defineGetter__("offsetX",function(){return this.layerX});Event.prototype.__defineGetter__("offsetY",function(){return this.layerY});Event.prototype.attachEvent=function(type,handler){this.addEventListener(type.substring(2),handler,true)};Event.prototype.detachEvent=function(type,handler){this.removeEventListener(type.substring(2),handler,true)};window.constructor.prototype.attachEvent=function(type,handler){this.addEventListener(type.substring(2),handler,true)};window.constructor.prototype.detachEvent=function(type,handler){this.removeEventListener(type.substring(2),handler,true)};document.constructor.prototype.attachEvent=function(type,handler){this.addEventListener(type.substring(2),handler,true)};document.constructor.prototype.detachEvent=function(type,handler){this.removeEventListener(type.substring(2),handler,true)};Element.prototype.attachEvent=function(type,handler){this.addEventListener(type.substring(2),handler,true)};Element.prototype.detachEvent=function(type,handler){this.removeEventListener(type.substring(2),handler,true)};HTMLElement.prototype.attachEvent=function(type,handler){this.addEventListener(type.substring(2),handler,true)};HTMLElement.prototype.detachEvent=function(type,handler){this.removeEventListener(type.substring(2),handler,true)}}


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 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;
        }
        try{
            return decodeURIComponent(document.cookie.substring(offset, end));
        }catch(e){
            try{
                return unescape(document.cookie.substring(offset, end));
            }catch(e1){
                return document.cookie.substring(offset, end);
            }
        }
    }else {
        return "";
    }
}
function loadAD(){
    var a = arguments;
    var size = a.length;
    var args = [];
    var items = null;
    for(var i = 0; i < size; i++){
        items = a[i].split("|");
        if(items.length == 3){
            var count = parseInt(items[2], 10);
            var showed = parseInt(getCookie("RMTimes"+items[1]) || 0, 10);
            if(showed < count){
                args.push(items[0]);
            }
        }else{
            args.push(a[i]);
        }
    }
    loadJSData("http://misc.web.xunlei.com/www_5_2/js/banner_kankan.1.7.js", "fetchAD", args, false);
}
function loadJSData(url, handler, args, isDestory){
    var head = document.getElementsByTagName("head")[0];
    var script = $C("script");
    var id = "dynamic_script_"+(new Date().getTime())+"_"+Math.random();
    var eventType = (undefined !== script.onreadystatechange && undefined !== script.readyState) ? "onreadystatechange" : "onload";
    script.language="javascript";
    script.type="text/javascript";
    script.src = url;
    script.id = id;
    script.attachEvent(eventType, function(){
        var state = script.readyState || "loaded";
        if("loaded" == state || "complete" == state){
            if(typeof(handler) == "string"){
                setTimeout(function(){try{var hdl = eval(handler);hdl.apply(null, args);}catch(e){}}, 50);
            }else if(typeof(handler) == "function"){
                setTimeout(function(){try{handler.apply(null, args);}catch(e){}}, 50);
            }
            if(isDestory){
                $R(script, head);
            }
            head = null;
            script = null;
        }
    });
    $P(script, head);
}