/*
 * Ext JS Library 2.2.1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

Ext.onReady(function(){

  if(document.getElementById('customContractSearch'))
  {
  
    var ds = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: 'http://stickk.summit-tech.ca/members/suggestContractType.php'
        }),
        reader: new Ext.data.JsonReader({
            root: 'contractTypes',
            totalProperty: 'totalCount'
        }, [
            {name: 'contract_id', mapping: 'contractId'},
            {name: 'title', mapping: 'contractTitle'}
        ])                               
    });

    // Custom rendering Template
    var resultTpl = new Ext.XTemplate(
        '<tpl for=".">',
          '<div class="search-item" style="overflow:hidden;z-index:10;">',
              '<span class="listAutoComplete">{title}</span>',
          '</div>',
        '</tpl>'
    );
    
    var search = new Ext.form.ComboBox({
        store: ds,
        //triggerAction: 'all',
        triggerAction: 'query',
        displayField:'title',
        typeAhead: false,
        loadingText: 'Searching...',
        width: 375,
        pageSize:10,
        tpl: resultTpl,
        applyTo: 'customContractSearch',
        itemSelector: 'div.search-item',
        //hideTrigger:true,
        hideTrigger:false,
        onSelect: function(record){
            updateSelectionId(record.data.contract_id)
        },
        onEmptyResults: function(){
            this.collapse();
            showNoResultsFound();
        }        
    });
  }
});