<?php
include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");
include_once(PATH_TO_ROOT."CRM/class/class.checkString.php");

	
$db->ChangeDatabase(DB_WARPIT_WEBCATI_BASE);

$ajax = "CRM/_forms/nastavitve/_ajax/ajax.loanCredit.php";

include_once (PATH_TO_ROOT."CRM/_CRM_config.php");
include_once(PATH_TO_ROOT."CRM/class/class.Language-Pack.php");

$LangPack = new LanguagePack($db, $aLanguage);
$windowId = "WindowAddLoan";
?>
var <?php echo $windowId;?> = new Ext.Window({
	title: '<?php echo $LangPack->GetLabel("CRM_settings_panel", "add_loan_credit_title","Dodaj Kredit"); ?>',
    id		: '<?php echo $windowId;?>',
    width	: 350,
    height	: 230,
    plain	: true,
    layout	: 'fit',
    frame: true,
    modal: true,
    items:[new Ext.form.FormPanel({
    	bodyStyle: 'padding: 20px',
		border: false,
		id: 'addLoanCredit',
		items:[new Ext.form.ComboBox({
            mode: 'local',
            triggerAction: 'all',
            editable: false,
            //hidden:true,
            fieldLabel: '<?php echo $LangPack->GetLabel("CRM_settings_panel", "numberOfAnnuities","Število obrokov"); ?>',
            width: 100,
            hiddenName: 'numberOfAnnuities',
            name: 'numberOfAnnuities',
            renderer : function(a, metaData, record) {
                var st = Ext.getCmp('avans_check').getStore();
                if(st.find('id',a) != -1){
                    var r = st.getAt(st.find('id',a));
                    return r.data.value;
                }
            },
            id: 'numberOfAnnuities',
            lazyRender: true,
            store: new Ext.data.ArrayStore({
                fields:['id', 'value'],
                data:[
                  	['1', '2'],
                    ['2', '5'],
                    ['3', '8'],
                    ['4', '11'],
                    ['5', '13'],
                    ['6', '17'],
                    ['7', '21'],
                    ['8', '23'],
                    ['9', '31'],
                    ['10', '35']
                ]
            }),
            valueField: 'id',
            displayField: 'value'
        }),{
        	xtype: 'numberfield',
        	name: 'CreditPrice',
        	allowBlank: false,
        	fieldLabel: '<?php echo $LangPack->GetLabel("CRM_settings_panel", "CreditPrice","Znesek kredita"); ?>',
        	id: 'CreditPrice'
        },{
        	xtype: 'numberfield',
        	name: 'AnnuitiePrice',
        	allowBlank: false,
        	fieldLabel: '<?php echo $LangPack->GetLabel("CRM_settings_panel", "AnnuitiePrice","Znesek anuita"); ?>',
        	id: 'AnnuitiePrice'
        },{
        	xtype: 'numberfield',
        	name: 'DepositePrice',
        	allowBlank: false,
        	fieldLabel:'<?php echo $LangPack->GetLabel("CRM_settings_panel", "DepositePrice","Znesek pologa"); ?>',
        	id: 'DepositePrice'
        }]
    })],
    listeners: {
		afterRender: function(grid){
			var X = (screen.width/2) - ((Ext.getCmp('<?php echo $windowId;?>').getSize().width)/2);
			var Y = (screen.height/2) - ((Ext.getCmp('<?php echo $windowId;?>').getSize().height)/2);
			Ext.getCmp('<?php echo $windowId;?>').setPosition(X, Y);
		}
	},
	buttons:[{
		text: '<?php echo $LangPack->GetLabel("CRM_all", "CRM_cancle_button","Prekliči"); ?>',
		handler: function(){
			<?php echo $windowId;?>.close();
		}
	},{
		text:'<?php echo $LangPack->GetLabel("CRM_all", "CRM_add_button","Dodaj"); ?>',
		handler: function(){
			if(Ext.getCmp('addLoanCredit').getForm().isValid()){
				Ext.getCmp('addLoanCredit').getForm().submit({
					url:'<?php echo $ajax;?>',
					params: {
						action: 'submit',
						id_interval: '<?php echo $_POST['id_interval'];?>'
					},
					success: function(resp, opt){
						<?php echo $windowId;?>.close();			
						Ext.getCmp('<?php echo StringChecker::Check($_POST['name']); ?>').getStore().reload();
					}
				});
			}
		}
	}]
}).show();
