function LocFilter( formID, provID, cityID, neighID ) {
	this.formID = formID;
	this.provinceID = provID;
	this.cityID = cityID;
	this.neighID = neighID;
	this.loaded = false;
	
	this.load();
}

LocFilter.prototype.load = function() {
	var IDs, o;
	
	this.form = this.xGetElementById( this.formID );
	
	if( !this.form ) return;
	
	this.province = this.xGetElementById( this.provinceID );
	this.provinceQ = this.form.qForm[ this.provinceID ];
	this.city = this.xGetElementById( this.cityID );
	this.cityQ = this.form.qForm[ this.cityID ];
	this.cityOptions = new Array( this.city.options.length );
	
	if( this.neighID ) {
		this.neigh = this.xGetElementById( this.neighID );
		this.neighQ = this.form.qForm[ this.neighID ];
		this.neighOptions = new Array( this.neigh.options.length );
	}
	
	// copy city options
	for( o = 0; o < this.city.options.length; o++ ) {
		this.cityOptions[ o ] = {
			provinceID: this.city.options[ o ].title
		,	value: this.city.options[ o ].value
		,	text: this.city.options[ o ].text
		};
	}
	this.cityQ.disabled( true );
	
	// copy neighborhood options
	if( this.neighID ) {
		// give neighborhood option a cityID & provinceID
		for( o = 0 ; o < this.neigh.options.length; o++ ) {
			IDs = this.neigh.options[ o ].title.split( ',' );
			this.neighOptions[ o ] = {
				cityID: IDs[0]
			,	provinceID: IDs[1]
			,	value: this.neigh.options[ o ].value
			,	text: this.neigh.options[ o ].text
			};
		}
		this.neighQ.disabled( true );
	}
	
	this.loaded = true;
	
	this.filterByProvince();
}

LocFilter.prototype.filterByProvince = function() {
	if( !this.loaded ) this.load();

	var x = 0
	var o;
	var reselect = false;
	var provinceValue = this.provinceQ.getValue();
	var cityValue = this.cityQ.getValue();
	
	if( provinceValue == 0 ) {
		// put them all back in
		for( o = 0 ; o < this.cityOptions.length; o++ ) {
			this.city.options[ o ] = new Option( this.cityOptions[ o ].text, this.cityOptions[ o ].value );
		}
		this.city.length = this.cityOptions.length;
	} else {
		for( o = 0 ; o < this.cityOptions.length; o++ ) {
			if( this.cityOptions[ o ].value == 0 || this.cityOptions[ o ].provinceID == provinceValue ) {
				if( this.cityOptions[ o ].value == cityValue ) {
					reselect = true;
				}
				this.city.options[ x ] = new Option( this.cityOptions[ o ].text, this.cityOptions[ o ].value );
				x++;
			}
		}
		this.city.length = x;
	}
	
	if( reselect ) {
	//	alert( 'reselect city ' + cityValue );
		this.cityQ.setValue( cityValue );
	}
	this.cityQ.disabled( ( provinceValue == 0 ) );
	
	this.filterByCity();
}

LocFilter.prototype.filterByCity = function() {
	if( !this.loaded ) this.load();
	
	if( !this.neighID ) return;
	
	var x = 0;
	var o;
	var reselect = false;
	var cityValue = this.cityQ.getValue();
	var provinceValue = this.provinceQ.getValue();
	var neighValue = this.neighQ.getValue();
	
//	alert( 'City: ' + cityValue + ' province: ' + provinceValue );
	
	if( provinceValue == 0 ) {
		// put them all back in
		for( o = 0 ; o < this.neighOptions.length; o++ ) {
			this.neigh.options[ o ] = new Option( this.neighOptions[ o ].text, this.neighOptions[ o ].value );
		}
		this.neigh.length = this.neighOptions.length;
	} else {
		for( o = 0 ; o < this.neighOptions.length; o++ ) {
			if( this.neighOptions[ o ].value == 0
			|| ( this.neighOptions[ o ].cityID == cityValue )
		//	|| ( this.neighOptions[ o ].provinceID == provinceValue )
			) {
				if( this.neighOptions[ o ].value == neighValue ) {
					reselect = true;
				}
				this.neigh.options[ x ] = new Option( this.neighOptions[ o ].text, this.neighOptions[ o ].value );
				x++;
			}
		}
		this.neigh.length = x;
	}
	
	if( reselect ) {
	//	alert( 'reselect neighbor ' + neighValue );
		this.neighQ.setValue( neighValue );
	}
	this.neighQ.disabled( ( cityValue == 0 ) );
}

LocFilter.prototype.xGetElementById = function( e ) {
	if(typeof(e)!='string') return e;
	if(document.getElementById) e=document.getElementById(e);
	else if(document.all) e=document.all[e];
	else e=null;
	return e;
}

