function BoardTypes(){
	this.rooms={};

	this.init=function(rids_visible){
		var type, i, j, ok;
		for(type in this.rooms){
			for(i in this.rooms[type]){
				ok=false;

				if(rids_visible!==false){
					for(j in rids_visible)
						if(j==i){ ok=true; break; }
				}else ok=true;

				if(ok){
					this.select(type, i);
					break;
				}
			}
		}
	};

	this.add_room=function(rid, type){
		if(this.rooms[type]==undefined) this.rooms[type]=[];
		this.rooms[type][rid]=true;
	};

	this.select=function(type, rid, bt_cnt, sel){
		var i;
		for(i in this.rooms[type]){
			if(rid==i) u('#rms_filter_room-'+i).show();
			else u('#rms_filter_room-'+i).hide();
		}
		if(sel==undefined) return true;
		for(i=0; i<bt_cnt; i++){
			if(i==sel) u('#room-board-'+rid+'-'+i).checked=true;
			else u('#room-board-'+rid+'-'+i).checked=false;
		}
	};
}

function RoomsFilter(def){
	this.types={};
	this.prev=false;
	this.inited=false;
	this.saved_state=false;

	this.add=function(type, rid){
		this.types[type][rid]=true;
	};

	this.reg=function(type){
		this.types[type]=[];
	};

	this.init=function(){
		var a=[], i;
		for(i in this.types)
			if(this.types[i].length){ u('#rms_filter-'+i).show(); a.push(i); }
		if(a.length==1){
			def=a[0];
			u('#rms_filter').hide();
			return true;
		}else
			u('#rms_filter').show();

		this.sel();

		this.inited=true;

		this.saved_state=parseInt(readCookie('rmsf_dscr'));
	};

	this.sel=function(type){
		var dscr=true;
		if(type==undefined) type=def;
		if(this.types[type]==undefined) type=false;

		if(!this.inited && def!='all') dscr=false;

		if(this.prev==type && this.prev!==false){
			u('#rms_filter-'+type).setClass('');
			if(dscr) u('#rms_filter_dscr_small-'+this.prev).hide();
			this.prev=false;
			this.filter_rms(false);
			return;
		}

		if(this.prev!==false){
			u('#rms_filter-'+this.prev).setClass('');
			u('#rms_filter_dscr_small-'+this.prev).hide();
		}
		this.prev=type;
		if(type!==false){
			u('#rms_filter-'+type).setClass('sel');
			if(dscr) u('#rms_filter_dscr_small-'+type).show();
		}

		this.filter_rms(type);
	};

	this.toggle_dscr=function(type, v, closed){
		if(this.types[type]==undefined) return false;

		if(closed!=undefined){
			createCookie('rmsf_dscr', 1, 0);
			this.saved_state=true;
		}

		if(v==1 && !this.saved_state) v=true;

		if(!v || v===1){
			u('#rms_filter_dscr-'+type).hide();
			u('#rms_filter_dscr_small-'+type).show();
		}else if(v===true){
			u('#rms_filter_dscr-'+type).show();
			u('#rms_filter_dscr_small-'+type).hide();
		}else{
			u('#rms_filter_dscr-'+type).hide();
			u('#rms_filter_dscr_small-'+type).hide();
		}

		if(type=='htl'){
			u('#rms_filter_dscr-htl-more').hide();
			u('#rms_filter_dscr-htl-mlink').show();
		}
	};

	this.filter_rms=function(type){
		var j, i, rids_visible=[];
		for(i in this.types)
			for(j in this.types[i])
				if(type===false || i==type){ u('#rms_filter_room-'+j).show(); rids_visible.push(j); }
				else if(this.types[type][j]==undefined) u('#rms_filter_room-'+j).hide();

		if(type===false) u('#rms_filter-all').setClass('sel');
		else u('#rms_filter-all').setClass('');

		BType.init(rids_visible);
	};
}
