
var MInscribe_SearchBox_Form = function() {
	var form, _config;
	
return {
	init: function(pConfig) {
	    _config = pConfig;
		//Ext.QuickTips.init();

		// turn on validation errors beside the field globally
		Ext.form.Field.prototype.msgTarget = 'side';
		form = new Ext.form.Form({ labelAlign: 'top', buttonAlign: 'right' });

        var cbCountry = new awCreateComboBox({ listId:627, id: 'mi_sb_cbCountry', width: 154, emptyText: 'Choose Country', maxHeight: 160 })
          , txtQuery = new Ext.form.TextField({ name: 'query', emptyText: 'Search Site' });

        cbCountry.on('select', function(sender, record, index) {
            if (!isNaN(record.id)) location.href = 'search-by-country-' + record.data.nodeId + '.aspx';
        });

        txtQuery.on('specialkey', function(sender, e) {
            if (e.getKey() == e.ENTER) submit();
        });

		form.container({ hideLabels: true, width: 126 }
			, txtQuery
		); form.applyIfToFields({ width: 124 });

		//form.render('MInscribe_SearchBox');
		form.render('Site_SearchBox');
		
        var form_CB = new Ext.form.Form({ labelAlign: 'top', buttonAlign: 'right' });
		form_CB.container({ hideLabels: true, width: 126 }
            , cbCountry
        );
        form_CB.render('MInscribe_SearchBox');
		
		function submit() {
		    var query = Ext.util.Format.trim(txtQuery.getValue());
	        if (query.length == 0) { txtQuery.reset(); return; }
	        
	        location.href = 'search.aspx?q=' + escape(query);
		}
		
		Ext.get('Site_SearchBox_Submit').addListener('click', submit);
		
		window.cbCountry = cbCountry;
	}
};}();

Ext.onReady(function(){ MInscribe_SearchBox_Form.init({}); });
