CQ.SearchAthleteField = CQ.Ext.extend(CQ.Ext.form.ComboBox, {
		
	constructor : function(config) {
		config = CQ.Util.applyDefaults(config, {
			"width" :300,
            "pageSize" :6,
			"minChars" :1,
			"typeAhead" :true,
			"typeAheadDelay" :100,
			"validationEvent" :false,
			"validateOnBlur" :false,
			"displayField" :"aname",
			"triggerClass" :"x-form-search-trigger",
			"emptyText" :"",
			"loadingText" :CQ.I18n.getMessage("Searching..."),
			"tpl" :new CQ.Ext.XTemplate(
				'<tpl for=".">',
					'<div class="search-item">',
						'<div class="search-title">{aname}</div>',
					'</div>',
				'</tpl>'),
			"itemSelector" :"div.search-item"
		});
		var storeConfig = CQ.Util.applyDefaults(config.store, {
			"proxy":new CQ.Ext.data.HttpProxy( {
				"url" :config.url ? config.url : "/content/teamsingapore/tsdb/athlete.athletesearch.json",
				"method" :"GET"
			}),
			"baseParams": {
				"_charset_": "utf-8"
			},
			"reader":new CQ.Ext.data.JsonReader({
				"id":"aid",
				"root":"hits",
				"totalProperty":"results",
				"fields" : [ "aid", "aname" ]
			})
		});
		config.store = new CQ.Ext.data.Store(storeConfig);
		CQ.SearchAthleteField.superclass.constructor.call(this, config);
	},
	
	onSelect: function(record, index) {
		this.setValue(record.data['aname']);
        
		if (this.fireEvent('beforeselect', this, record, index) !== false) {
            this.collapse();
            this.fireEvent('select', this, record, index);
        }
    },
    
    onTypeAhead : function(){        
    }
});

CQ.Ext.reg("searchathletefield", CQ.SearchAthleteField);

