Ext.ns('Search.form');

Search.form.LocationField = Ext.extend(Ext.form.ComboBox, {
	wwtype: 'location',
	itemCls: 'ww-custom-combobox w250',
	hiddenName: 'location[]',
	fieldLabel: 'Location',
	valueField: 'location_code',
	displayField: 'location_title',
	// lazyRender: true,
	// store: location_store,
	mode: 'local',
	typeAhead: true,
	triggerAction: 'all',
	emptyText: 'Pick One or Type a Zip Code',
	selectOnFocus: true,
	editable: true,
	allowBlank: true,
	validator: function(value){
		var is_a_location = !!this.getStore().queryBy(function(record, id){
			return record.json[1] == value;
		}).length;
		
		// if given value is one of the provided options for the combobox
		// or is a five digit number, then the value is valid.
		if (is_a_location || value.match(/^\d{5}$/) || (this.allowBlank == true && value == '')) {
			return true;
		}
		
		// otherwise, return an error message.
		return 'Please choose a location or type in a five-digit zip code.';
	},
	width: 250
});
