if (!window.tezOnReady) {
    window.tezOnReady = [];
}
window.tezOnReady.push(function(){
	
    var button = Ext.get('calcBtn');

    var calcBtnClick = function(val) {
		var currencyId = 5561;
		if ('eur'==val) currencyId = 18864;
		var sourceField = Ext.get('calculator.source.id');
		var targetField = Ext.get('calculator.target.id');
		var value = sourceField.getValue();
		targetField.dom.value = ""+value*currencyRate[currencyId];
    }

	var win = new Ext.Window({
		title: getMessage('calculator.window.title'),
		layout:'fit',
		width:450,
		height:130,
		closeAction:'hide',
		resizable: false,
		plain: true,
		border: false,
		bodyStyle:'padding:5px 5px 0',
		items: new Ext.FormPanel({
			labelAlign: 'top',
			width: 440,
			frame: false,
			border: false,
			bodyBorder: false,
			items: [{
				layout:'column',
				border: false,
				items: [{
					columnWidth:.35,
					layout:'form',
					border: false,
					layoutConfig: {
						labelSeparator: ''
					},	                		
					items: [{
						id: 'calculator.source.id',
						fieldLabel: getMessage('calculator.source'),
						xtype: 'numberfield',
						name: 'calculator.source',
						anchor:'95%'
					}]
				},{
					columnWidth:.3,
					border: false,
					items: [{
						xtype: 'button',
						border: false,
						minWidth: 115,	                		
						text: getMessage('calculator.usd.to.rub'),
						handler: function() {
							calcBtnClick('usd');
						}
					},{
						xtype: 'button',
						border: false,	                		
						minWidth: 115,	                		
						text : getMessage('calculator.eur.to.rub'),
						handler: function() {
							calcBtnClick('eur')
						}
					}]
				},{
					columnWidth:.35,
					layout:'form',
					border: false,
					layoutConfig: {
						labelSeparator: ''
					},	                		
					items: [{
						id: 'calculator.target.id',
						fieldLabel: getMessage('calculator.target'),
						xtype: 'field',
						name: 'calculator.target',
						anchor:'95%'
					}]
				}]
			}]
		}),
		buttons: [{
			text: getMessage('button.close'),
			handler: function(){
				win.hide();
			}
		}]
	});
	
	button.on('click', function(){
		win.show(this);
	});
});