<?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);

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);
$ajax = "CRM/_forms/nastavitve/_ajax/ajax.vzrokNarocila.php";

$windowId = "WindowAddVzr";
?>
var <?php echo $windowId;?> = new Ext.Window({
	title: '<?php echo $LangPack->GetLabel("CRM_settings_panel", "add_order_cause_window_title","Dodaj vzrok naročila"); ?>',
    id		: '<?php echo $windowId;?>',
    width	: 350,
    height	: 150,
    plain	: true,
    layout	: 'fit',
    frame: true,
    modal: true,
    items:[new Ext.form.FormPanel({
    	bodyStyle: 'padding: 20px',
		border: false,
		id: 'addVzrForm',
		items:[{
			xtype: 'textfield',
        	name: 'vzrok',
        	fieldLabel: '<?php echo $LangPack->GetLabel("CRM_settings_panel", "order_cause_title","Vzrok"); ?>',
        	anchor: '100%',
        	allowBlank: false
		},{
			xtype: 'checkbox',
        	name: 'odprto',
        	fieldLabel: '<?php echo $LangPack->GetLabel("CRM_settings_panel", "order_cause_open_title","Odprto"); ?>',
        	inputValue: 1
		}]
    })],
    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('addVzrForm').getForm().isValid()){
				Ext.getCmp('addVzrForm').getForm().submit({
					url:'<?php echo $ajax;?>',
					params: {
						action: 'submit'
					},
					success: function(resp, opt){
						<?php echo $windowId;?>.close();			
						Ext.getCmp('<?php echo StringChecker::Check($_POST['name'])	; ?>').getStore().reload();
					}
				});
			}
		}
	}]
}).show();
