function HFilter(cname, farea)
{
	this.items = new Array();
	this.felement = null;
	
	var divs = document.getElementsByTagName( "DIV" );
	
	for( var j = 0; j < divs.length; j ++ ) {
		var el = divs[j];
		
		if( el.className !== undefined ) {
			if( el.className == filter ) {
				this.felement = el;
				continue;
			}
			
			if( el.className != cname )
				continue;
		} else {
			if( el.getAttribute( "class" ) == filter ) {
				this.felement = el;
				continue;
			}

			if( el.getAttribute( "class" ) != cname )
				continue;
		}
		
		var sdl = el.getAttribute( "details" );
		
		if( !sdl ) continue;
		
		try {
			var dl = sdl.parseJSON(null);
			this.items[ this.items.length ] = {
				ele : el,
				r : dl.r,
				l : dl.l,
				vis : true,
				xr : false,
				xl : false
			};
		} catch( e ) {
			continue;
		}
	}

	if( this.felement ) {
		this.checks = new Array();
		this.checks["r"] = new Array();
		this.checks["l"] = new Array();
		
		var cks = this.felement.getElementsByTagName( "INPUT" );
		
		for( var j = 0; j < cks.length; j ++ ) {
			var fam = cks[ j ].getAttribute( "family" );
			
			if( !fam ) continue;
			if( !this.checks[ fam ] ) continue;
			
			this.checks[ fam ][ this.checks[ fam ].length ] = cks[ j ];
		}
	}
}

HFilter.prototype.onSwitch = function(cat, val, chk)
{
	var hiddens = new Array();
	
	for( var j = 0; j < this.items.length; j ++ ) {
		var valid = false;
		if( cat == "r" ) {
			if( this.items[ j ].r == val )
				valid = true;
		} else if( cat == "l" ) {
			if( this.items[ j ].l == val )
				valid = true;
		}
				
		if( valid ) {
			if( chk.checked ) {
				if( cat == "r" )
					this.items[ j ].xr = false;
				else if( cat == "l" )
					this.items[ j ].xl = false;

				if( !this.items[ j ].xr && !this.items[ j ].xl ) {
					this.items[ j ].ele.style.display = "block";
					this.items[ j ].vis = true;
				}
			} else {
				this.items[ j ].ele.style.display = "none";
				this.items[ j ].vis = false;
				hiddens[ hiddens.length ] = this.items[ j ];

				if( cat == "r" )
					this.items[ j ].xr = true;
				else if( cat == "l" )
					this.items[ j ].xl = true;
			}
		}
	}
	
	var hasvis = false;
	
	for( var j = 0; j < this.items.length; j ++ ) {
		if( this.items[ j ].vis ) {
			hasvis = true;
			break;
		}
	}
	
	if( !hasvis ) {
		chk.checked = true;
		for( var j = 0; j < hiddens.length; j ++ ) {
			if( cat == "r" )
				hiddens[ j ].xr = false;
			else if( cat == "l" )
				hiddens[ j ].xl = false;

			if( !hiddens[ j ].xr && !hiddens[ j ].xl ) {
				hiddens[ j ].ele.style.display = "block";
				hiddens[ j ].vis = true;
			}
		}
	}
}

