window["ADS_CHECKER"] = {
    RAND: Math.random(),
    //lay path de check deu kien
    getPath2Check: function (type){
        return (type == 'Site:Pageurl') ? document.URL : document.referrer;
    },
    //check dieu kien don gian nam ngay ngoai banner
    checker: function(data, type, logic){
        var path2check = this.getPath2Check(type);
        switch(logic){
            case '==':  return (path2check == data);
            case '!=':  return (path2check != data);
            case '=~':  return ADS_CHECKER.stripos(path2check, data, 0);
            case '!~':  return !ADS_CHECKER.stripos(path2check, data, 0);
            case '=x':  var reg = new RegExp(data);return reg.test(path2check);
            case '!x':  var reg = new RegExp(data);return !reg.test(path2check);
        }
        return false;
    },
    //check cac dieu kien nam trong channel
    checker_checker: function(data, operator2){
        if(data){
            var len = data.length;
            var str = '';
            var operator = '';
            for(var i=0;i&lt;len;i++){
                if(data[i].data == undefined){
                    var str2 = '';
                    var operator = '';
                    for(var j=0;j&lt;data[i].length;j++){
                        operator = (data[i][j].join=='or'?'||':'&&');
                        str2 += ((j!=0)?operator:'')+ADS_CHECKER.checker(data[i][j].data,data[i][j].type,data[i][j].logic);
                    }
                    str += ((i!=0)?operator2:'')+'('+str2+')';
                }else{
                    str += ((i!=0)?operator2:'')+ADS_CHECKER.checker(data[i].data,data[i].type,data[i].logic);
                }
            }
            return str;
        }
        return false;
    },
    //sinh so ngau nhien trong khoang tu min -> max
    rand:function(min, max){
        var argc = arguments.length;
        if (argc == 0) {
            min = 0;
            max = 2147483647;
        } else if (argc == 1) {
            throw new Error('Error');
        }
        return Math.floor(ADS_CHECKER.RAND * (max - min + 1)) + min;
    },
    //dat cookie
    setCookie: function(name, value, expires, path, domain, secure) {
        expires instanceof Date ? expires = expires.toGMTString() : typeof(expires) == 'number' && (expires = (new Date( + (new Date) + expires * 1e3)).toGMTString());
        var r = [name + "=" + escape(value)],
        s,
        i;
        for (i in s = {
            expires: expires,
            path: path,
            domain: domain
        }) {
            s[i] && r.push(i + "=" + s[i])
        }
        return secure && r.push("secure"),
        document.cookie = r.join(";"),
        true
    },
    //lay cookie
    getCookie: function(c_name) {
        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;
                return unescape(document.cookie.substring(c_start, c_end))
            }
        }
        return ""
    },
    //kiem tra xem du lieu co nam trong mang khong
    in_array: function(needle, haystack, argStrict){
        var found = false, key, strict = !!argStrict;
        for (key in haystack) {
            if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
                found = true;
                break;
            }
        }
        return found;
    },
    //so sanh 2 mang, tra ve mang khac nhau thuoc 1 ma ko thuoc 2
    array_diff: function (arr1, arr2) {
        var retArr = [];
        for(var i=0;i&lt; arr1.length;i++){
            if(!ADS_CHECKER.in_array(arr1[i],arr2)){
                retArr[retArr.length] = arr1[i];
            }
        }
        return retArr;
    },
    //tim kiem phan tu dau tien xuat hien trong chuoi~
    stripos: function(f_haystack,f_needle,f_offset ){
        var haystack = (f_haystack+'').toLowerCase();
        var needle = (f_needle+'').toLowerCase();
        return haystack.indexOf(needle, f_offset) !== -1;
    },
    processClick: function(id, link){
        var len = link.length;
        for(var i=0;i&lt;len;i++){
            var iframe = document.createElement('iframe');
            iframe.width = 0;
            iframe.height= 0;
            iframe.style.border=0;
            iframe.src = link;
            document.getElementById(id).appendChild(iframe);
        }
    }
};
function banner(banner_data){
    var props = {
        bid:    parseInt(banner_data.bid),
        title:  banner_data.title,
        type:   banner_data.type,
        link:   banner_data.link,
        src:    banner_data.src,
        width:  parseInt(banner_data.width),
        height: parseInt(banner_data.height),
        created:banner_data.created,
        expired:banner_data.expired,
        slotIdx:banner_data.slotIdx,
        attr:   banner_data.attr,
        terms:  banner_data.terms,
        clicks: banner_data.clicks,
        views:  banner_data.views,
        cpname: banner_data.cpname,
        counter:banner_data.counter,
        iframe: banner_data.iframe,
        sort:   banner_data.sort,
        link_clicks: banner_data.link_clicks,
        link_views: banner_data.link_views,
        bool:   false
    };
    for (var p in props)    this[p] = props[p];
};
banner.prototype.logging = function(zoneid, img, rand_num, encode){
    var return_link = this.link ? this.link : '-1';
    var random = ADS_CHECKER.rand(0,9);
    random = 'http://' + ((random != 0) ? 'i'+random+'.' : '');
    if(img){
        img = random+'logging.admicro.vn/_adv.gif';
    }else{
        img = random+'logging.admicro.vn/_adc.html';
    }
    if(encode)
        return_link = encodeURIComponent(img+'?adm_domain='+document.URL+'&adm_campaign='+(this.cpname?this.cpname:'')+'&adm_aditem='+this.bid+'&adm_zoneid='+zoneid+'&adm_channelid=-1&adm_rehttp='+return_link+'&adm_random='+rand_num);
    else
        return_link = img+'?adm_domain='+document.URL+'&adm_campaign='+(this.cpname?this.cpname:'')+'&adm_aditem='+this.bid+'&adm_zoneid='+zoneid+'&adm_channelid=-1&adm_rehttp='+encodeURIComponent(return_link)+'&adm_random='+rand_num;
    return return_link;
};
banner.prototype.renderLinkViews = function(){
    var out = '';
    if(this.link_views != null){
        var len = this.link_views.length;
        for(var i=0;i&lt;len;i++){
            out += '&lt;img src="'+this.link_views[i]+'" width="0" height="0" border="0" style="position:absolute" />';
        }
    }
    return out;
};
banner.prototype.renderLinkClicks = function(zone_tag){
    var out = '';
    if(this.link_clicks != null){
        if(this.type == 'swf'){
            out+= 'onmousedown="';
        }else{
            out+= 'onclick="';
        }
        out+='ADS_CHECKER.processClick(\''+zone_tag+'\',[';
        var len = this.link_clicks.length;
        for(var i=0;i&lt;len;i++){
            out+= '\''+this.link_clicks[i]+'\''+((i&lt;len-1)?',':'');
        }
        out+=']);"';
    }
    return out;
};
banner.prototype.renderBanner = function(zone_tag, zoneid, rand_num, hidden, cl){
    var out = '&lt;div id="'+zone_tag+'" class="'+cl+'" '+(hidden?'style="display:none"':'')+'>';
    switch(this.type){
        case 'gif':case 'jpeg':case 'png':
            out += this.renderBannerImage(zone_tag, zoneid, rand_num, hidden);
        break;
        case 'swf':
            out += this.renderBannerFlash(zone_tag, zoneid, rand_num, hidden);
        break;
        case 'html':
            out += (this.src+'').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
        break;
    }
    if(this.counter){
        out += '&lt;img src="'+this.logging(zoneid, true, rand_num)+'" width="0" height="0" border="0" style="position:absolute;border:none;background:none" />';
    }
    return out+this.renderLinkViews()+'&lt;/div>';
};
banner.prototype.renderBannerImage = function (zone_tag, zoneid, rand_num, hidden){
    var item = '&lt;img border="0" id="'+zone_tag+'" src="'+this.src+'"'+(this.width?' width="'+this.width+'"':'')+(this.height?' height="'+this.height+'"':'');
    if(this.attr){
        for(var p in this.attr){
            item += ' '+p+'="'+this.attr[p]+'"';
        }
    }
    item+=' '+this.renderLinkClicks(zone_tag)+' />';
    return (this.link?('&lt;a href="'+this.logging(zoneid,false,rand_num)+'" target="_blank">'+item+'&lt;/a>'):item);
};
banner.prototype.renderBannerFlash = function (zone_tag, zoneid, rand_num, hidden){
    var itemE= '';
    var flashvar = this.link ? ('alink1='+this.logging(zoneid,false,rand_num,true)+'&amp;atar1=_blank') : '';
    var checkFlashvar = false;
    if(this.attr){
        for(var p in this.attr){
            if(p == 'flashvars'){
                this.attr[p] = flashvar+'&amp;'+this.attr[p];
                checkFlashvar= true;
            }
            itemE+= ' '+p+'="'+this.attr[p]+'"';
        }
    }
    if(flashvar != '' && !checkFlashvar){
        itemE+= ' flashvars="'+flashvar+'"';
    }
    return '&lt;embed '+this.renderLinkClicks(zone_tag)+' src="'+this.src+'" height="'+this.height+'" align="middle" width="'+this.width+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" '+itemE+' allowscriptaccess="always" wmode="transparent" quality="high" />';
};
banner.prototype.time = function(){
    return ads_time_server?ads_time_server:Math.round(new Date().getTime()/1000);
};
banner.prototype.checkViews = function(zone_tag){
    zone_tag = zone_tag.substring(0,zone_tag.length-1);
    var view = 0;
    eval('view = view_'+zone_tag+this.bid); 
    return (view==0||view==null)?true:(view&lt;=this.views);
};
banner.prototype.checkClicks = function(zone_tag){
    zone_tag = zone_tag.substring(0,zone_tag.length-1);
    var click = 0;
    eval('click = click_'+zone_tag+this.bid);   
    return (click==0||click==null)?true:(click&lt;=this.clicks);
};
banner.prototype.checkExpired = function(){
    var now = this.time();
    if((this.created &lt; now) && (this.expired == null)) return false;
    if((this.created &lt; now) && (now &lt; this.expired)) return false;
    return true;
};
banner.prototype.checkInvalid = function(zone_tag){
    if(this.checkExpired()) return false;
    if(!this.checkViews(zone_tag))  return false;
    if(!this.checkClicks(zone_tag)) return false;
    return true;
};
banner.prototype.process = function(){
    if(this.terms){
        var terms = this.terms;
        var len = terms.length;
        var str = '';
        var operator = '';
        var temp_bool= false;
        for(var i=0;i&lt;len;i++){
            if(i!=0) operator = (terms[i].join=='or'?'||':'&&');
            if(terms[i].channel){
                str += operator+((terms[i].logic == '!~') ? '!' : '')+'('+ADS_CHECKER.checker_checker(terms[i].data,((terms[i].logic == '==')?'&&':'||'))+')';
            }else{
                str += operator+ADS_CHECKER.checker(terms[i].data, terms[i].type, terms[i].logic);
            }
        }
        this.bool = eval(str);
    }else{
        this.bool = true;
    }
};
/*
 zone.style{
    string html: zone's template
    string css: zone's css
    int slot: number slots of zone
    array effect: slot's effect (ex: [0,1,2,0,0] &lt;-> slot 0:null, slot 1:rotate banner, slot 2: all banner (note: this type must have default banner), slot 3 + 4: refresh banner)
    array slots_rotate: slot rotate together (ex: [[1,2],[4,5,6]] &lt;-> slot1 rorate with slot 2 & slot 4,5,6 rorate together)
    array slot_type: type of slots_rotate (refresh or rotate) (ex: slots_rotate=[[1,2],[4,5,6]], slot_type=[0,1] &lt;-> slot1+2 refresh, slot4+5+6 rotate)
    array sort_banner_slot: define sort idx in each slot to inert banner default for all banner slot (ex:[0,[1,3,5,6],0,0,0] &lt;-> slot1 have 4 banner & sort idx like 1,3,5,6)
    array banner_default: banner default for slot
 }
 
*/
function zone(zoneid, style, width, height, attr){
    var props = {
        banners: new Array(),
        zoneid:(zoneid?zoneid:-1),
        width: width,
        height:height,
        attr:  attr,
        style: style,
        slots: null,
        time:10000,
        preload_time:3000,
        rand_num:ADS_CHECKER.RAND,
        theme: new Array(),
        run_fix: false,
        ie:(navigator.appName == 'Opera') || (navigator.appName == 'Microsoft Internet Explorer')
    };
    for (var p in props)    this[p] = props[p];
};
zone.prototype.addBanner = function(b){
    if(b.bid){
        var ban = new banner(b);
        ban.process();
        if(ban.bool){
            if(ban.checkInvalid(this.getZoneTag()+'_banner0')){
                var new_idx = this.banners.length;
                if(this.slots != null){
                    if(this.slots[b.slotIdx] != ''){
                        this.slots[b.slotIdx] += ';'+new_idx;
                        if(this.slots[b.slotIdx].indexOf(";") != -1){
                            if((this.style.effect[b.slotIdx] != 0) && this.banners[parseInt(this.slots[b.slotIdx])]){
                                this.banners[parseInt(this.slots[b.slotIdx])].counter = false;
                            }
                        }
                        if(this.style.effect[b.slotIdx] != 0){
                            ban.counter = false;
                        }
                    }else{
                        this.slots[b.slotIdx] += new_idx;
                    }
                    if((this.style.effect[b.slotIdx] == 1) && (b.type == 'swf')){
                        this.append2slot('&lt;div id="'+this.getZoneTag()+'_slot'+b.slotIdx+'_banner_'+b.bid+'" style="display:none">&lt;/div>',b.slotIdx);
                    }
                    if((ban.type == 'html') && (ban.iframe == 0)){
                        if(!this.run_fix) this.run_fix = (b.fix_ie == 1);
                        var banner_html = ban.renderBanner(this.getZoneTag()+'_banner'+ban.bid,this.zoneid,this.rand_num,true);
                        if(b.fix_ie==0 || !this.ie){
                            if(this.style.effect[b.slotIdx] != 2)
                                this.append2slot(banner_html, b.slotIdx);
                        }else{
                            this.theme[b.slotIdx] = (this.theme[b.slotIdx]?this.theme[b.slotIdx]:'')+banner_html;
                        }
                    }
                }
                this.banners[new_idx] = ban;
            }
        }
    }
};
zone.prototype.addBanners= function(data){
    if(this.style){
        if(this.style.slot > 0){
            this.slots = new Array();
            for(var i=0;i&lt;=this.style.slot;i++)
                this.slots[i] = '';
        }
    }
    if(data){
        for (var p in data) this.addBanner(data[p]);
    }
    if(this.slots != null){
        var auto_slot = {banners:new Array(), slots:{idx:new Array(),number:new Array()}};
        for(var i=1;i&lt;=this.style.slot;i++){
            if((this.slots[i] != '') && (this.slots[i].indexOf(";") != -1)){
                var temp = this.slots[i].split(";");
                temp.sort(function(){return 0.5 - Math.random()});
                this.slots[i] = temp.join(';');
            }
            if(this.style.auto_change && (this.slots[i] != '')){
                var now_b = null;
                if(this.slots[i].indexOf(";") != -1){
                    now_b = this.slots[i].split(";");
                    if(this.style.effect[i] == 2){
                        var auto_len = auto_slot.slots.idx.length;
                        auto_slot.slots.number[auto_len] = 0;
                        auto_slot.slots.idx[auto_len] = i;
                        for(var j=0;j&lt;now_b.length;j++){
                            if((this.banners[now_b[j]].width==125)&&(this.banners[now_b[j]].height==125)){
                                auto_slot.banners[auto_slot.banners.length] = now_b[j];
                                auto_slot.slots.number[auto_len]++;
                            }
                        }
                        now_b = null;
                    }else{
                        now_b = now_b[0];
                    }
                }else{
                    now_b = this.slots[i];
                }
                if((now_b!=null)&&(this.banners[now_b].width==125)&&(this.banners[now_b].height==125)){
                    auto_slot.banners[auto_slot.banners.length] = now_b;
                    auto_slot.slots.idx[auto_slot.slots.idx.length] = i;
                    auto_slot.slots.number[auto_slot.slots.number.length] = 1;
                }
            }
        }
        if(this.style.auto_change && (auto_slot.banners.length > 0) && (auto_slot.slots.idx.length > 0) && (auto_slot.slots.number.length > 0)){
            auto_slot.banners.sort(function(){return 0.5 - Math.random()});
            var banner_idx = 0;
            for(var i=0;i&lt;auto_slot.slots.idx.length;i++){
                if(auto_slot.slots.number[i] > 1){
                    var temp = new Array();
                    for(var j=0;j&lt;auto_slot.slots.number[i];j++){
                        temp[temp.length] = auto_slot.banners[banner_idx];
                        this.banners[auto_slot.banners[banner_idx]].slotIdx = auto_slot.slots.idx[i];
                        this.banners[auto_slot.banners[banner_idx]].sort = j+1;
                        banner_idx++;
                    }
                    this.slots[auto_slot.slots.idx[i]] = temp.join(';');
                }else{
                    this.slots[auto_slot.slots.idx[i]] = auto_slot.banners[banner_idx];
                    this.banners[auto_slot.banners[banner_idx]].slotIdx = auto_slot.slots.idx[i];
                    this.banners[auto_slot.banners[banner_idx]].sort = 1;
                    banner_idx++;
                }
            }
        }
    }
};
zone.prototype.getSizeStr = function(){
    this.width = parseInt(this.width) > 0 ? 'width:'+this.width+'px;' : '';
    this.height= parseInt(this.height)> 0 ? 'height:'+this.height+'px;' : '';
};
zone.prototype.getZoneTag = function(){
    return 'ads_zone'+this.zoneid;
};
zone.prototype.append2slot   = function(html, slot_id){
    var str = 'slot'+slot_id+'_content';
    this.style.html = this.style.html.replace(str, html+str);
};
zone.prototype.drawZoneTag = function(){
    var zone_tag = this.getZoneTag();
    this.getSizeStr();
    var out = '&lt;div id="'+zone_tag+'"';
    var style = false;
    for(var p in this.attr){
        if(p=='style') style = true;
        out += ' '+p+'="'+((p=='style')?(''+this.width+';'+this.height+''):'')+this.attr[p]+'"';
    }
    if((this.attr == null) || !style){out+='style="'+this.width+';'+this.height+'"'}
    out +='>';
    if(this.style){
        out +=this.style.html.replace(/id=\"slot/gi, 'id="'+zone_tag+'_slot');
        this.bindCSS(this.style.css);
    }else{
        this.bindCSS('#'+zone_tag+' object, #'+zone_tag+' img{border:1px solid #DADADA;background:#fff;padding:2px;float:left;margin:0 4px 4px 0}');
    }
    out+='&lt;/div>';
    if(this.run_fix && this.ie){
        var html = out;
        var i = html.search(/slot([0-9]+)_content/);
        while( i != -1){
            var temp = html.substr(0, i);
            html = html.substr(i);
            var slotIdx = html.substr(4, html.search(/_content/)-4);
            html = html.substr(12+slotIdx.length);
            document.write('&lt;script type="text/javascript" src="'+url_write+'?code='+encodeURIComponent(temp)+'">&lt;/script>');
            slotIdx = parseInt(slotIdx);
            if(this.theme[slotIdx] && this.theme[slotIdx] != ''){
                document.write(this.theme[slotIdx]);
            }
            i = html.search(/slot([0-9]+)_content/);
            if( i == -1){
                document.write('&lt;script type="text/javascript" src="'+url_write+'?code='+encodeURIComponent(html)+'">&lt;/script>');
                html = '&lt;script type="text/javascript">'+zone_tag+'.hideEmptyZone("'+zone_tag+'");&lt;/script>';
                document.write('&lt;script type="text/javascript" src="'+url_write+'?code='+encodeURIComponent(html)+'">&lt;/script>');
            }
        }
    }else{
        document.write(out.replace(/slot([0-9]+)_content/gi, ''));
        document.write('&lt;script type="text/javascript">'+zone_tag+'.hideEmptyZone("'+zone_tag+'");&lt;/script>');
    }
};
zone.prototype.hideEmptyZone = function(zone_tag){
    if(this.slots){
        var all_off = true;
        var no_default = true;
        for(var i=1;i&lt;=this.style.slot;i++){
            no_default = true;
            var slot_c = document.getElementById(zone_tag+'_slot'+i);
            if((this.slots[i] == '') && slot_c){
                //neu co banner default
                if(this.style.banner_default[i] != 0){
                    //tao banner default tuong ung
                    var b_def = this.style.banner_default[i];
                    b_def = new banner({"bid":0,"title":"","type":b_def.type,"link":b_def.link,"src":b_def.src,"width":b_def.width,"height":b_def.height,"created":null,"expired":null,"slotIdx":i,"attr":null,"terms":b_def.terms,"clicks":0,"views":0,"cpname":"","counter":false,"iframe":0,"fix_ie":0,"sort":0,"link_clicks":null,"link_views":null});
                    //Kiem tra dieu kien channel cua banner default
                    b_def.process();
                    if(b_def.bool){
                        if(this.style.effect[i] == 2){
                            var arr_s = this.style.sort_banner_slot[i];
                            for(var s=0;s&lt;arr_s.length;s++){
                                var new_idx = this.banners.length;
                                b_def.sort = arr_s[s];
                                this.banners[new_idx] = b_def;
                                if(s == 0){
                                    this.slots[i] += new_idx;
                                }else{
                                    this.slots[i] += ';'+new_idx;
                                }
                            }
                        }else{
                            var new_idx = this.banners.length;
                            this.banners[new_idx] = b_def;
                            this.slots[i] = ""+new_idx;
                        }
                        no_default = false;
                        all_off = false;
                    }
                }
                //Neu khong co banner default
                if(no_default){
                    //an slot di
                    slot_c.style.display = 'none';
                    //kiem tra xem co nam trong slot share khong
                    var inslot = this.inSlotShare(i);
                    if(inslot != -1){
                        //neu co thi loai bo
                        var new_array = this.style.slots_rotate[inslot];
                        for(var j=0;j&lt;new_array.length;j++){
                            if(i == new_array[j]){
                                this.style.slots_rotate[inslot].splice(j,1);
                                break;
                            }
                        }
                    }
                }
            }else{
                all_off = false;
            }
        }
        if(all_off){
            document.getElementById(zone_tag).style.display = 'none';
        }else{
            this.showBanner();
        }
    }else{
        for(var i=1;i&lt;=this.style.slot;i++)
            document.getElementById(zone_tag+'_slot'+i).style.display = 'none';
        document.getElementById(zone_tag).style.display = 'none';
    }
};
zone.prototype.bindCSS = function(css){
    var st = document.createElement('style');
    st.type = 'text/css';
    var head = document.getElementsByTagName('head')[0];
    head.appendChild(st);
    if (st.styleSheet) {
        st.styleSheet.cssText = css
    }else {
        st.appendChild(document.createTextNode(css))
    }
};
zone.prototype.inSlotShare= function(idx){
    if(this.style.slots_rotate){
        var len = this.style.slots_rotate.length;
        for(var i=0;i&lt;len;i++){
            if(((this.style.effect[idx] == 2)||(this.style.slots_rotate[i].length > 1))&&ADS_CHECKER.in_array(idx, this.style.slots_rotate[i])) return i;
        }
    }
    return -1;
};
zone.prototype.showBanner = function(){
    if(this.banners.length > 0){
        var zone_tag = this.getZoneTag();
        if(this.slots != null){
            var randItem = [];
            for(var i=1;i&lt;=this.style.slot;i++){
                if(this.slots[i] != ''){
                    var inslot = this.inSlotShare(i);
                    if(inslot != -1)
                        randItem[inslot] = ADS_CHECKER.rand(0,this.style.slots_rotate[inslot].length-1);
                    if(this.slots[i].indexOf(";") != -1){
                        var bannerIDArr = this.slots[i].split(";");
                        if(inslot != -1){
                            if((this.style.slots_rotate[inslot][randItem[inslot]] == i))
                                this.drawBannerSlotShare(zone_tag, i, true);
                        }else{
                            switch(this.style.effect[i]){
                                case 0:this.drawBannerShareRefresh(zone_tag, i, bannerIDArr);break;
                                case 1:
                                    this.banners[parseInt(bannerIDArr[0])].counter = true;
                                    this.drawBannerShare(zone_tag, i, bannerIDArr[0]);
                                break;
                            }
                        }
                    }else{
                        if(inslot != -1){
                            if(this.style.slots_rotate[inslot][randItem[inslot]] == i){
                                if(this.style.effect[i] != 2){
                                    this.drawBanner(zone_tag, this.slots[i], false);
                                }else{
                                    this.drawBannerSlotShare(zone_tag, i, true);
                                }
                            }
                        }else{
                            this.drawBanner(zone_tag, this.slots[i], false);
                        }
                    }
                }
            }
            if(this.style.slots_rotate){
                for(var j=0;j&lt;this.style.slots_rotate.length;j++){
                    var temp = new Array();
                    for(var i=0;i&lt;this.style.slots_rotate[j].length;i++){
                        if(this.slots[this.style.slots_rotate[j][i]] != ''){
                            temp[temp.length] = this.style.slots_rotate[j][i];
                        }
                    }
                    this.style.slots_rotate[j] = temp;
                    this.drawSlotShare(zone_tag, j, randItem[j]);
                }
            }
        }else{
            for(var i=0;i&lt;this.banners.length;i++)
                this.drawBanner(zone_tag, i, false);
        }
    }
};
zone.prototype.drawBanner = function(zone_tag, idx, hidden){
    if(this.banners[idx]){
        var zoneDIV = document.getElementById(zone_tag);
        var cl = 'banner'+this.banners[idx].sort;
        if(zoneDIV){
            var slot = zone_tag+'_slot'+this.banners[idx].slotIdx;
            var ban  = zone_tag+'_banner'+idx;
            var slotContainer = document.getElementById(slot);
            var container = slotContainer ? slotContainer : zoneDIV;
            if(this.banners[idx].type == 'html'){
                if(this.banners[idx].iframe && (this.banners[idx].iframe==1)){
                    container.innerHTML += '&lt;iframe src="about:blank" style="margin:0;padding:0" id="html_'+ban+'" width="'+this.banners[idx].width+'" height="'+this.banners[idx].height+'" scrolling="no" framespacing="0" frameborder="no">&lt;/iframe>';
                    var io=document.getElementById('html_'+ban);
                    doc = io.contentWindow ? io.contentWindow.document : (io.contentDocument ? io.contentDocument : io.document);
                    doc.write('&lt;style type="text/css">body{margin:0}&lt;/style>'+this.banners[idx].renderBanner(ban, this.zoneid, this.rand_num, hidden, cl));
                }else{
                    var banner_html = document.getElementById(zone_tag+'_banner'+this.banners[idx].bid);
                    if(banner_html){
                        banner_html.id  = ban;
                        banner_html.className = cl;
                        if(!hidden){
                            banner_html.style.display = 'block';
                        }                       
                    }
                    else if(this.style.effect[this.banners[idx].slotIdx] == 2){                         
                        var html = this.banners[idx].renderBanner(ban, this.zoneid, this.rand_num, hidden, cl);
                        container.innerHTML += html;                            
                    }
                }
            }else{
                var b_src = this.banners[idx].renderBanner(ban, this.zoneid, this.rand_num, hidden, cl);
                if(this.style.effect[this.banners[idx].slotIdx] == 1){
                    var c = document.getElementById(zone_tag+'_slot'+this.banners[idx].slotIdx+'_banner_'+this.banners[idx].bid);
                    if(c){
                        c.style.display = hidden ? "none" : "block";
                        c.innerHTML = b_src;
                    }else{
                        container.innerHTML += b_src;
                    }
                }else{              
                    container.innerHTML += b_src;
                }
            }
        }else{
            document.write(this.banners[idx].renderBanner(ban, this.zoneid, this.rand_num, false, cl));
        }
    }
};
zone.prototype.drawBannerShare = function(zone_tag, slotIdx, now){
    var bannerIDArr = this.slots[slotIdx].split(";");
    var length = bannerIDArr.length;
    if(bannerIDArr[bannerIDArr.length-1] == undefined){
        length--;
        bannerIDArr.length = length;
    }
    now = parseInt(now);
    now = (now >= length)?0:now;
    for(var i=0;i&lt;length;i++){
        var temp = document.getElementById(zone_tag+'_banner'+bannerIDArr[i]);
        if(now == i){
            if(temp){
                temp.innerHTML += '';
                temp.style.display = 'block';
                if(this.banners[bannerIDArr[i]].type == 'swf'){
                    temp.parentNode.style.display = 'block';
                }
            }else{
                this.drawBanner(zone_tag, bannerIDArr[now], false);
            }
            var next_id = (now >= length-1)?0:(now+1);
            if(next_id >= 0){
                if(document.getElementById(zone_tag+'_banner'+bannerIDArr[next_id])){
                    next_id = null;
                }else{
                    setTimeout(zone_tag+'.drawBanner(\''+zone_tag+'\', '+bannerIDArr[next_id]+', true)',this.time/2);
                }
            }
        }else if(temp){
            temp.style.display = 'none';
            if(this.banners[bannerIDArr[i]].type == 'swf'){
                temp.parentNode.style.display = 'none';
            }
        }
    }
    now++;
    setTimeout(zone_tag+'.drawBannerShare(\''+zone_tag+'\', '+slotIdx+', '+now+')',this.time);
};
zone.prototype.getRandomRefreshIdx = function(arr){
    return (arr != null && arr.constructor == Array) ? arr[0] : 0;
};
zone.prototype.clearBannerArray = function(bannerIDArr){
    var temp = new Array();
    for(var i=0;i&lt;bannerIDArr.length;i++){
        if(bannerIDArr[i] != ''){
            temp[temp.length] = bannerIDArr[i];
        }
    }
    return temp;
};
zone.prototype.getBannerShareRefresh = function (zone_tag, slotIdx, bannerIDArr) {  
    if(typeof(cookie_val) == "undefined") {
        cookie_val = ADS_CHECKER.getCookie('_azs');
    }
    
    var cookie_slot = zone_tag.replace('ads_zone','z') + 's' + slotIdx;
    var bannerCookie = cookie_val;
    var c_start=bannerCookie.indexOf(cookie_slot + ":");    
    var c_end;
    if (c_start!=-1){
        c_start=c_start + cookie_slot.length+1;
        c_end=bannerCookie.indexOf(";z",c_start);

        if (c_end==-1) c_end=bannerCookie.length;
        else c_end = c_end + 1;
        bannerCookie = bannerCookie.substring(c_start,c_end);
        
    }else{
        bannerCookie='';
    }

    var bannerID = '';
    bannerIDArr = this.clearBannerArray(bannerIDArr);
    if (bannerCookie == '') {
        bannerID = this.getRandomRefreshIdx(bannerIDArr)
    } else {
        bannerID = bannerCookie.split(";");
        var diffArr = ADS_CHECKER.array_diff(bannerIDArr, bannerID);
        if ((diffArr[0] == undefined) || (diffArr[0] == '')) {
            bannerCookie = '';
            bannerID = this.getRandomRefreshIdx(bannerIDArr)
        } else {
            bannerID = this.getRandomRefreshIdx(diffArr)
        }       
    }

    if(c_start == -1){
        new_cookie_slot_val = cookie_slot+":"+bannerID;
        var new_cookie_val = cookie_val + new_cookie_slot_val + ';';
    }else{          
        var new_cookie_slot_val = cookie_val.substring(c_start,c_end);
        if(bannerCookie!=''){
            new_cookie_slot_val = new_cookie_slot_val + bannerID + ';';
        }else{
            new_cookie_slot_val = bannerID + ';';
        }
        var new_cookie_val = cookie_val.substring(0,c_start) + new_cookie_slot_val + cookie_val.substring(c_end,cookie_val.length);     
    }
    ADS_CHECKER.setCookie('_azs', (new_cookie_val), '', '/');
    cookie_val = new_cookie_val;
    return bannerID
};
zone.prototype.drawBannerShareRefresh = function(zone_tag, slotIdx, bannerIDArr){
    if(typeof( bannerIDArr ) == 'string'){
        bannerIDArr = bannerIDArr.split(";");
    }
    var bannerID = this.getBannerShareRefresh(zone_tag, slotIdx, bannerIDArr);
    this.drawBanner(zone_tag, bannerID, false);
};
zone.prototype.drawBannerSlotShare = function(zone_tag, id_slot, counter){
    if(this.style.effect[id_slot] != 2){
        this.drawBannerShareRefresh(zone_tag, id_slot, this.slots[id_slot]); return;
    }
    var b_def = null;
    var slot_c = null;
    var arrBanner = this.slots[id_slot].split(";");
    var length = arrBanner.length;
    if(length > 1){
        if(arrBanner[length-1] == undefined){
            length--;
            arrBanner.length = length;
        }
        for(var i=0;i&lt;length;i++){
            for(var j=i+1;j&lt;length;j++){
                if(this.banners[arrBanner[j]].sort &lt; this.banners[arrBanner[i]].sort){
                    var temp = arrBanner[j];
                    arrBanner[j] = arrBanner[i];
                    arrBanner[i] = temp;
                }
            }
        }
    }
    if((this.style.banner_default[id_slot] != 0) && (this.style.sort_banner_slot[id_slot] != 0)){
        var len = this.style.sort_banner_slot[id_slot].length;
        var tempArr = new Array();
        for(var i=0;i&lt;len;i++){
            var check = -1;
            for(var j=0;j&lt;length;j++){
                if(this.style.sort_banner_slot[id_slot][i] == this.banners[arrBanner[j]].sort){
                    if(tempArr[i] == undefined){
                        tempArr[i] = new Array();
                        l = 0;
                    }else{
                        l = tempArr[i].length;
                    }
                    tempArr[i][l] = arrBanner[j];
                    check = 0;
                }
            }
            //truong hop co banner default
            if(check == -1){
                tempArr[i] = ['sort',this.style.sort_banner_slot[id_slot][i]];
                //khoi tao banner default neu chua co
                if(b_def == null){
                    b_def = this.style.banner_default[id_slot];
                    if(b_def != 0){
                        b_def = new banner({"bid":0,"title":"","type":b_def.type,"link":b_def.link,"src":b_def.src,"width":b_def.width,"height":b_def.height,"created":null,"expired":null,"slotIdx":null,"attr":null,"terms":b_def.terms,"clicks":0,"views":0,"cpname":"","counter":false,"iframe":0,"fix_ie":0,"sort":0,"link_clicks":null,"link_views":null});
                        //Kiem tra dieu kien channel cua banner default
                        b_def.process();
                    }
                    slot_c = document.getElementById(zone_tag+'_slot'+id_slot);
                }
            }
        }
        arrBanner = tempArr;
        tempArr   = null;
        length    = arrBanner.length;
    }
    for(var i=0;i&lt;length;i++){
        if(arrBanner[i][0] == 'sort'){
            if(slot_c && (b_def != 0)){
                slot_c.innerHTML += b_def.renderBanner('','',0,false,'banner'+arrBanner[i][1]);
            }
        }else{
            var bannerID = 0;
            if (arrBanner[i].constructor.toString().indexOf('Array') == -1){
                bannerID = arrBanner[i];
            }else{
                bannerID = this.getBannerShareRefresh(zone_tag, id_slot+'_'+i, arrBanner[i]);
            }
            this.banners[bannerID].counter = counter;
            this.drawBanner(zone_tag, bannerID, false);
        }
    }
};
zone.prototype.drawSlotShare = function(zone_tag,groupIdx,now){
    var style  = this.style.slot_type[groupIdx];
    var length = this.style.slots_rotate[groupIdx].length;
    if((length > 1)){
        now = parseInt(now);
        now = (now >= length)?0:now;
        for(var i=0;i&lt;length;i++){
            document.getElementById(zone_tag+'_slot'+this.style.slots_rotate[groupIdx][i]).style.display = 'none';
        }
        var now_slot = document.getElementById(zone_tag+'_slot'+this.style.slots_rotate[groupIdx][now]);
        var now_slotIdx = this.style.slots_rotate[groupIdx][now];
        if(this.style.effect[now_slotIdx] == 1){
            //truog hop slot co hieu ung rotate thi chuyen ve dang banner refresh moi lan rotate slot
            now_slot.innerHTML = '';
            this.drawBannerShareRefresh(zone_tag, now_slotIdx, this.slots[now_slotIdx]);
        }
        now_slot.style.display = 'block';
        if(style==1){
            if(now_slot.className.indexOf("loaded") == -1)
                now_slot.className = now_slot.className ? (now_slot.className+' '+'loaded') : 'loaded';
            var next_id = (now >= length-1)?0:(now+1);
            if(next_id >= 0){
                var id_slot = this.style.slots_rotate[groupIdx][next_id];
                var slot_obj = document.getElementById(zone_tag+'_slot'+id_slot);
                var show = (slot_obj && ADS_CHECKER.stripos(slot_obj.className, 'loaded', 0)) ? false : true;
                if(this.slots[id_slot] != '' && show){
                    if(this.slots[id_slot].indexOf(";") != -1){
                        switch(this.style.effect[id_slot]){
                            case 0:case 1: setTimeout(zone_tag+'.drawBannerShareRefresh(\''+zone_tag+'\', '+id_slot+', "'+this.slots[id_slot]+'")',this.time);break;
                            case 2: setTimeout(zone_tag+'.drawBannerSlotShare(\''+zone_tag+'\', '+id_slot+', false)',this.preload_time);break;
                        }
                    }else{
                        if(this.style.effect[id_slot] != 2){
                            setTimeout(zone_tag+'.drawBanner(\''+zone_tag+'\', '+this.slots[id_slot]+', false)',this.preload_time);
                        }else{
                            setTimeout(zone_tag+'.drawBannerSlotShare(\''+zone_tag+'\', '+id_slot+', false)',this.preload_time);
                        }
                    }
                    slot_obj.className = slot_obj.className ? (slot_obj.className+' '+'loaded') : 'loaded';
                }
            }
            now++;
            setTimeout(zone_tag+'.drawSlotShare(\''+zone_tag+'\', '+groupIdx+', '+now+')',this.time);
        }
    }
};

.l {text-align:left}
.c {text-align:center}
.r {text-align:right}
.left {float:left}
.right {float:right}
#stats_members a.member, .bday_strip {white-space:nowrap}
.calendar li span {cursor:default}
#c_tos li {display:list-item;margin-left:25px}
#c_tos ul li {list-style:disc}
#c_tos ol li {list-style:lower-alpha}
#shoutrefresh {cursor:pointer}