// Create user extension namespace (Application)
Ext.namespace('Application');

/**
  *  Application.guestSearchForm Extension class
  * 
  *  @author Seabor
  *  @version 1.0
  *  
  *  @class Application.guestSearchForm
  *  @extends Ext.form.FormPanel
  *  @constructor
  *  @param {Object} config Configuration options
  */

Application.guestSearchForm = function(config) {

    // call parent constructor
    Application.guestSearchForm.superclass.constructor.call(this, config);

}; // end of Application.guestSearchForm constructor

Ext.extend(Application.guestSearchForm, Ext.form.FormPanel, {

	// configurables
    // anything what is here can be configured from outside
	title: 'Поиск'
	,titlebar: true
    ,frame: true    
    ,height: 100
    ,monitorValid: true
    ,labelAlign: 'left'
    ,labelWidth: 40
    ,buttonAlign: 'right'

    // initComponent {{{
    ,initComponent: function() {
        var that = this;
    	// Ext.apply {{{
    	Ext.apply(this, {
    	    items: [{
                xtype: 'textfield'
                ,fieldLabel: 'Я ищу'
                ,name: 'searchString'
                ,anchor: '-7'
                ,allowBlank: false
                ,minLength: 3
                ,emptyText: 'например, «p-352»'
            }]
            ,buttons: [{
                id: 'srchSbmt'
                ,type: 'submit'
                ,text: 'Искать'
                ,disabled: true
            }]
            ,keys: {
                key: Ext.EventObject.ENTER
                ,fn: function(){
                	if (that.searchBtn.disabled === false)
                        that.searchBtn.fireEvent('click', that.searchBtn);
                }
            }
    	});// }}} e/o Ext.apply
    	
    	// call parent
    	Application.guestSearchForm.superclass.initComponent.apply(this, arguments);
    	
    	this.searchField = this.items.itemAt(0);
    	this.searchBtn = this.buttons[0];
    	
    	this.on({
    	    scope: this
    	    ,render: function() {
    	       this.on({
    	           scope: this
    	           ,clientvalidation: function(x, y) {
    	               if (y) {this.searchBtn.enable()} else {this.searchBtn.disable()}
    	           }
    	       });
    	    }
    	});
    }// }}} e/o initComponent
});

// register new xtype
Ext.reg('guestSearchForm', Application.guestSearchForm);
