Ext.ns('Application');
Ext.onReady(function(){
	Ext.QuickTips.init();
	Application.PointsPanel = Ext.extend(Ext.Panel, {
	autoHeight: true,	
		frame: false,
		border: false,
		bodyStyle: "padding: 10px",
		ctCls: 'bluepanel',
		layout:'column',
		buttonAlign: 'center',
		initComponent: function(){
			Ext.apply(this, {
				items: [
					new Ext.Panel({
						border: false,
						columnWidth: .5,
						bodyStyle: "padding: 0px; text-align: center;",
						
						items: [
							new Ext.form.ComboBox({								
								id: 'recv_country',
								width: 160,
								listWidth: 150,
								name: 'recv_country',
								fieldLabel: 'Страна',
								emptyText: 'Выберите страну...',
								mode: 'local',
								forceSelection: true,
								triggerAction: 'all',
								displayField: 'bank_country',
								valueField: 'bank_country',
								store: new Ext.data.JsonStore({
									url: '/load.php',
									baseParams: {'do': 'client/banks/countries/list'},
									fields: ['bank_country'],
									root: 'items', 																	
									autoLoad: true
								}),
								listeners:{
									scope: this,
									select: function(combo, record, index){
										Ext.getCmp('recv_city').store.reload({params: {bank_country: record.data.bank_country}});
										Ext.getCmp('recv_city').clearValue();
										this.buttons[0].setDisabled(true);
									}
								}
							})
						]
					}),
					new Ext.Panel({
						border: false,
						columnWidth: .5,
						bodyStyle: "padding: 0px; text-align: center;",
						items: [
							new Ext.form.ComboBox({
								id: 'recv_city',
								width: 160,
								listWidth: 150,
								name: 'recv_city',
								fieldLabel: 'Регион/город',
								emptyText: 'Выберите город...',
								mode: 'local',
								forceSelection: true,
								triggerAction: 'all',
								displayField: 'bank_region',
								valueField: 'bank_region',
								store: new Ext.data.JsonStore({
									url: '/load.php',
									baseParams: {'do': 'client/banks/regions/list'},
									fields: ['bank_region'],
									root: 'items', 																	
									autoLoad: true
								}),
								listeners:{
									scope: this,
									select: function(combo, record, index){
										//Ext.getCmp('recv_city').store.reload({params: {bank_country: record.data.bank_country}});
										this.buttons[0].setDisabled(false);
									}
								}
							})
						]
					})
				],
				buttons: [
					{
						text: 'Список банков',
						disabled: true,
						handler: function(){
							var wnd = new Ext.Window({
								width: 787,		
								modal: true,
								frame: true,
								title: 'Точки обслуживания',
								buttonAlign: 'center',								
								items: [													
									new Ext.grid.GridPanel({
										id: 'banks-grid',
										title: 'Список точек обслуживания',														
										height: 300,
										loadMask: true,
										border: false,
										cls: 'grid-multiline',									
										store: new Ext.data.JsonStore({
											url: '/load.php',
											baseParams: {'do': 'client/banks/list',bank_country: Ext.getCmp('recv_country').getValue(),bank_region: Ext.getCmp('recv_city').getValue()},
											fields: ['bank_id','bank_sname', 'bank_address', 'bank_phone', 'bank_opermode15', 'bank_opermode6', 'bank_opermode7'],
											root: 'items',
											autoLoad: true
										}),
										columns: [
											{ header: "Банк", width: 130, dataIndex: "bank_sname", sortable: false,  menuDisabled: true,  resizable: false},															
											{ header: "Адрес", width: 200, dataIndex: "bank_address", sortable: false, menuDisabled: true,  resizable: false, cls: 'grid-multiline'},
											{ header: "Телефон", width: 120, dataIndex: "bank_phone", sortable: false, menuDisabled: true,  resizable: false, cls: 'grid-multiline'},
											{ header: "Режим работы (пн-пт)", width: 100, dataIndex: "bank_opermode15", sortable: false, menuDisabled: true,  resizable: false, cls: 'grid-multiline'},
											{ header: "Режим работы (cб)", width: 100, dataIndex: "bank_opermode6", sortable: false, menuDisabled: true,  resizable: false, cls: 'grid-multiline'},
											{ header: "Режим работы (вс)", width: 100, dataIndex: "bank_opermode7", sortable: false, menuDisabled: true,  resizable: false, cls: 'grid-multiline'}
											
										]
									})
								],
								buttons: [
									{
										text: 'Закрыть',
										scope: this,
										handler: function(){
											wnd.close();
										}
									}
								]
							});
							wnd.show();											
						}
					}
				]
			});
			Application.PointsPanel.superclass.initComponent.apply(this, arguments);
		}
	});
	if(obj=Ext.get('points-main-form')){
		(new Application.PointsPanel()).render(obj);
	}
});
