function bt_gi(id, size, count,countmax) {
	var i;
	if(bt_icons) {
		i = bt_icons[id];
	}
	if(!i || i === '') {i='skill_unlearn';}
	i = 'url(/img/icons/rom/'+size+'/'+i+'.png)';
	var oodiv = bce('div',{_className: 'db-icon-div-'+size, backgroundImage:i});
	var odiv=bce('div',{_className:'db-icon-fl'});
	var a = bce('a', {_href: '?i='+id});
	bac(odiv,a);
	if(count > 1 || (countmax && countmax>1)) {
		if(countmax) {
			count = count.toString()+'-'+countmax.toString();
		}
		var s = bce('span',{position:'absolute',bottom:'0px',right:'0px',margin:'1px 3px'});
		for(var x =-1;x<=1;x++) {
			for(var y =-1;y<=1;y++) {
				var div = bce('div',{align:'right',position:'absolute',whiteSpace:'nowrap',top:y+'px',left:x+'px',fontWeight:'bold'},count);
				if(x===0 && y===0) {
					div.style.zIndex= 10;
					div.style.color = 'white';
				} else {
					div.style.color = 'black';
				}
				//.setStyle({height : size+'px', width: size+'px', fontWeight: 'bold', color:'black', });
				bac(s,div);
			}
		}
		bac(s,bce('span',{visibilty:'hidden'},count));
		//var div = bce('div',{align:'right',position:'absolute',whiteSpace:'nowrap',fontWeight:'bold',color:'white'},count);

		bac(s,div);
		bac(odiv,s);
	}
	bac(oodiv,odiv);
	return oodiv;
}

function bt_gis(id, i, size) {
	if(!i || i === '') {i='skill_unlearn';}
	i = '/img/icons/rom/'+size+'/'+i+'.png';
	var img = bce('img',{_src:i,_width:size,_height:size,_align:'absmiddle'});
	var a = bce('a', {_href: '?s='+id},img);
	return a;

}

function BtabsType_Item(opts) {
	bim(this, opts);
	this.field = 'n';
	this.title = BTLANG.Name;
	this.align = 'left';
	this.colspan = 2;
	this.sortable = 1;

	this.makeCell =function(rowdata,tr) {
		var href = '/?i='+rowdata.id;		
		var tdi = bce('td',{borderRight:"none",width:"1%"});
		var q = 0;
		if(rowdata.q) {
			q = rowdata.q;
		}

		bac(tdi,bt_gi(rowdata.id,40,rowdata.c,rowdata.cm));
		bac(tr,tdi);

		var tds = bce('td',{_align:'left'},bce('a',{_href:href, _className:'qrom'+q},rowdata.n), bce('br'));

		if(rowdata.on) {
			bac(tds,bce('span',{_className:'origname'},bct(rowdata.on)));
			bac(tds,bce('br'));
		}
		
		if(rowdata.viewable){
			var hrefpreview = 'javascript:buffedViewer('+rowdata.viewable+',"'+BTLANG.locale+'");'
			var preview = bce('small',{_align:'left'},bce('a',{_href:hrefpreview}, BTLANG.Viewerpreview));
		}
		
		if(rowdata.viewable)bac(tds,preview);
		bac(tr,tds);
	};
	
	this.sortFunc = function(a,b,f) {
		var r = -bcmpn(a,b,'q');
		if(r!==0) return r;
		return bcmps(a.n,b.n);
	}
}

function BtabsType_Skill(opts) {
	bim(this, opts);
	this.field = 'n';
	this.title = BTLANG.Name;
	this.align = 'left';
	this.colspan = 2;
	this.sortable = 1;

	this.makeCell =function(rowdata,tr) {
		var href = '/?s='+rowdata.id;		
		var tdi = bce('td',{borderRight:"none",width:"1%"});
		var q = 0;
		if(rowdata.q) {
			q = rowdata.q;
		}

		bac(tdi,bt_gis(rowdata.id,rowdata.icon,40));
		bac(tr,tdi);

		var tds = bce('td',{_align:'left'},bce('a',{_href:href, _className:'sq'+q},rowdata.n), bce('br'));

		if(rowdata.on) {
			bac(tds,bce('span',{_className:'origname'},bct(rowdata.on)));
			bac(tds,bce('br'));
		}
		
		if(rowdata.viewable){
			var hrefpreview = 'javascript:buffedViewer('+rowdata.viewable+',"'+BTLANG.locale+'");'
			var preview = bce('small',{_align:'left'},bce('a',{_href:hrefpreview}, BTLANG.Viewerpreview));
		}
		
		if(rowdata.viewable)bac(tds,preview);
		bac(tr,tds);
	};
	
	this.sortFunc = function(a,b,f) {
		var r = -bcmpn(a,b,'q');
		if(r!==0) return r;
		return bcmps(a.n,b.n);
	}
}


function BtabsType_ItemList(opts) {	
	this.sortable = 1;
	this.field = "rew";
	bim(this, opts);
	
	this.getItemList = function(list,title) {
		var l = list.length
		var div = bce('div',{width:(l*28+2)+"px",position:"relative"});
		if(list.length>0) {
			if(title) {
				bac(div,bce('div',{position:'relative', width:'1px'},bce('div',{position:'absolute',right:(l*14+2)+'px',whiteSpace: 'nowrap',lineHeight:'24px',_className:'qrom0',fontSize:'smaller'},bct(title))));
			}
			for(var i=0,l=list.length; i<l; i++) {
				if(list[i].icon) {
					bt_icons[list[i].id] = list[i].icon;
				}
				bac(div,bt_gi(list[i].id,24,list[i].c));
			}
			bac(div,bce('div',{clear:"both",width:"1px"}))
		}
		return div;
	}

	this.makeCell =function(rowdata, tr) {
		var td = bce('td',{_align:'center'});

		f = rowdata[this.field];
		if(!f) {
			bac(td, bnd());
			bac(tr,td);
			return;
		}

		if(f.c) {
			bac(td,this.getItemList(f.c,BTLANG.Choose));
		}
		if(f.r) {
			bac(td,this.getItemList(f.r));
		}
		
		if(f.t) {
			var list= f.t;
			for(var i=0,l=list.length; i<l; i++) {
				var c = list[i].c;
				if(!c) c=1;
				bac(td,bct(c+' '));
				bac(td,bt_gis(list[i].id,16));
			}
		}

		if(f.xp) {
			var s = ' XP ';
			if(f.mo) {
				s = s + ' + ';
			}
			bac(td,bct(f.xp+s));
		}
		
		if(f.ap) {
			bac(td,bce('span',{_className:'arenacoin',_title:BTLANG.ArenaPoints},bct(f.ap)));
		}
		if(f.hp) {
			bac(td,bce('span',{_className:'honorcoin',_title:BTLANG.HonorPoints},bct(f.hp)));
		}
		if(f.mo) {
			bac(td,bt_money(f.mo));
		}
		
		
		bac(tr,td);
	};

	this.sortFunc = function(a,b,f) {
		var aa = {xp:0};
		var bb = aa;
		if(a[f] && a[f].xp) aa = a[f];
		if(b[f] && b[f].xp) bb = b[f];
		return bcmpn(aa,bb,'xp');
	}
}

function BtabsType_ItemSet(opts) {
	bim(this, opts);
	this.field = 'n';
	this.title = BTLANG.Name;
	this.align = 'left';
	this.sortable = 1;

	this.makeCell =function(rowdata,tr) {
		var href = '/?set='+rowdata.id;		
		var tdi = bce('td',{borderRight:"none",width:"1%"});
		var q = rowdata.q


		var tds = bce('td',{_align:'left',paddingLeft:'4px'},bce('a',{_href:href, _className:'qrom'+q},rowdata.n), bce('br'));

		//if(rowdata.t && bt_settag[rowdata.t]) {
		//	bac(tds,bce('small',null,bt_settag[rowdata.t]));
		//}
		
		if(rowdata.viewable){
			var hrefpreview = 'javascript:buffedViewer('+rowdata.viewable+',"'+BTLANG.locale+'");'
			var preview = bce('small',{_align:'left'},bce('a',{_href:hrefpreview}, BTLANG.Viewerpreview));
		}
		if(rowdata.viewable)bac(tds,preview);
		
		bac(tr,tds);
	};
}

function BtabsType_RoM_Char(opts) {
	bim(this, opts);
	this.title = BTLANG.Name;
	this.align = 'left';
	this.colspan = 2;
	this.sortable = 1;

	this.makeCell =function(rowdata,tr) {
		var href = 'char/view/'+rowdata.id;		
		var tdi = bce('td',{borderRight:"none",width:"1%"});

		bac(tdi,bce('a', {_href: 'char/view/'+rowdata.id}, bce('img',{_src:'/img/icons/rom/32/'+rowdata.icon+'.png',margin : '2px'})));

		var tds = bce('td',{_align:'left'},bce('a',{_href:href},rowdata.n), bce('br'));
		bac(tr,tdi);		
		bac(tr,tds);
	};
}

function BtabsType_RoM_Level(opts){
	bim(this, opts);
	this.title = BTLANG.Class+" / "+BTLANG.Level;
	this.align = 'center';
	
	this.makeCell = function(rowdata,tr) {
		var tdi = bce('td');
		
		var mainclass = "";
		var subclass = "";
		
		if(rowdata.l1){
			var mainclass = bt_class[rowdata.c1]+" ("+rowdata.l1+")";
		}
		if(rowdata.l2){
			var subclass = bt_class[rowdata.c2]+" ("+rowdata.l2+")";
		}
		
		bac(tdi,mainclass+" "+subclass);
		bac(tr,tdi);
	}
}

function BtabsType_RoM_Race(opts){
	bim(this, opts);
	this.title = BTLANG.Race;
	this.align = 'center';
	
	this.makeCell = function(rowdata,tr) {
		var tdi = bce('td'), racename;
		
		racename = BTLANG.RaceHuman;
		if(rowdata.r) {
			racename = BTLANG.RaceElf;
		}
			
		bac(tdi,racename);
		bac(tr,tdi);
	}
}
