function brpFindWidget(opts, container){

	// properties
	this.opts = opts;
	this.container = $(container);
	this.location = null;
	
	// event methods
	this.onLocationFound = null;

	// attach handlers
	var me = this;
	$('#find-text', me.container).keyup(function(event){me.checkEnter(event);});
	$('#find-button', me.container).click(function(){me.findClicked();});
	$('#find-error', me.container).click(function(){$(this).fadeOut('slow')});

	// init gui
	$('#find-error', me.container).hide();
}

brpFindWidget.prototype.checkEnter = function(event){
	if (event.keyCode==13)
		this.findClicked();
} 

brpFindWidget.prototype.findClicked = function(){ 
	$('#find-error', this.container).fadeOut();
	var txt = $('#find-text', this.container).val();	
	var me = this;
	var bIsPostalCode = me.isValidPostalCode(txt);
	me.bIsPostalCode = bIsPostalCode;
	if (txt.length > 0){
		$.getJSON(brpFindLocationUrl + '&format=json&callback=?', {'text': txt}, function(data, textStatus, bIsPostalCode){
			me.findResult(data, textStatus, me.bIsPostalCode);
		});
	}
}

brpFindWidget.prototype.findResult = function(data, textStatus, bIsPostalCode){
	if (data.location)
		this.locationFound(data.location, bIsPostalCode);
	else
		$('#find-error', this.container).show();
} 

brpFindWidget.prototype.locationFound = function(loc, bIsPostalCode){
	this.location = loc;
	if (this.onLocationFound)
		this.onLocationFound(loc, bIsPostalCode);
}

brpFindWidget.prototype.isValidPostalCode = function(postalCode){
    postalCodeRegex = /^[\d]{4} ?[A-Z]{2}$/i;
    return postalCodeRegex.test(postalCode);
}