<?php

include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");
include_once (PATH_TO_ROOT."config.php");

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

$LangPack = new LanguagePack($db, $aLanguage);

$suffix = $_POST['suffix'];
$gridName = "NakupiTab".$suffix;
$zipAjax = CRM_RPATH."_forms/_ajax/ajax.zipCheck.php";
$ajax = CRM_RPATH."_forms/prisotnost/_ajax/ajax.nakupi.php";
$windowId = "windowNakupId";


$zipChecker1 = new ZipChecker($db, 'Posta_podjetja', "Kraj_podjetja");
$zipChecker2 = new ZipChecker($db, "Posta", "Kraj");

$zipId = StringChecker::Check($_POST['zipId']);
$dan = StringChecker::Check($_POST['dan']);
$ura = StringChecker::Check($_POST['ura']);
$cati_location = StringChecker::Check($_POST['cati_location']);
$projectId = StringChecker::Check($_POST['projectId']);
$id_tel = StringChecker::Check($_POST['id_tel']);
//echo "console.log('$ura', '$dan');";
?>

var narocnik = false;
var firstConfirm = false;
var <?php echo $gridName;?> = new Ext.form.FormPanel({
    id:'<?php echo $gridName;?>',
    bodyStyle:'padding: 20px',
    border: false,
    region: 'center',
    labelAlign: 'left',
    autoScroll: true,
    labelWidth: 150,
    items:[{
        layout: 'form',
        xtype: 'fieldset',
        anchor: '-0',
        title: '<?php echo $LangPack->GetLabel("edit_order_window", "order_fiedset_title","Naročilo");?>',
        items:[
            new Ext.form.ComboBox({
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "cause_title","Vzrok");?>', 
                mode: 'local',
                triggerAction: 'all',
                editable: false,
                width: 170,
                name: 'brez_nakupa_vzrok',
                hiddenName: 'brez_nakupa_vzrok',
                id: 'vzrok',
                lazyRender: true,
                renderer : function(a, metaData, record) {
                    var st = Ext.getCmp('vzrok').getStore();
                    if(st.find('id',a) != -1){
                        var r = st.getAt(st.find('id',a));
                        return r.data.value;
                    }
                },
                store: new Ext.data.ArrayStore({
                    fields:['id', 'value', 'open'],
                    data:[
                    <?php
                        $k = array();
                        $sql = "SELECT * FROM ".WARPIT_CRM."._vzrokiNarocila WHERE deleted = 0 ORDER BY orderBy";
                        $res = $db->SQLexecute($sql);
                        while($row = $db->fetchAssoc($res)){
                            array_push($k, "['".$row['id']."', '".$row['naziv_vzroka']."', '".$row['odpri_narocilo']."']");
                        }
                        echo implode(", ", $k);
                    ?>
                    ]
                }),
                listeners: {
                    focus: function(combo){
                        if(combo.getValue() == 0 || combo.getValue == null)
                            combo.setValue('<?php echo $LangPack->GetLabel("CRM_all", "select_option_title","Izberite...");?>');
                    },
                    select: function(c, i, e){
                        if(i.data.open == 1){
                            Ext.getCmp('brez_nakupa_komentar').hide();
                            Ext.getCmp('podatki_narocila').show();
                         	//<?php echo $windowId; ?>.setHeight(240);
                            narocnik = true;
                        }
                        else {
                            if(narocnik){
                                Ext.Msg.confirm('<?php echo $LangPack->GetLabel("edit_order_window", "delete_changes_title","Opozorilo");?>', '<?php echo $LangPack->GetLabel("edit_order_window", "delete_changes_msg","Podatki dobo izbrisani, želete nadaljevati?");?>', function(btn) {
                                    if(btn=='yes'){
                                        var temp = Ext.getCmp('vzrok').getValue();
                                        Ext.getCmp('<?php echo $gridName;?>').getForm().reset();
                                        Ext.getCmp('vzrok').setValue(temp); 
                                        Ext.getCmp('podatki_narocila').hide();
                                      	//<?php echo $windowId; ?>.setHeight(250);
                                        narocnik = false;   
                                        Ext.getCmp('brez_nakupa_komentar').show();
                                    }
                                });
                            }
                            Ext.getCmp('save_button').enable();
                        }
                    }
                },
                valueField: 'id',
                displayField: 'value'
         }),{
                xtype: 'textarea',
                id: 'brez_nakupa_komentar',
                name: 'brez_nakupa_komentar',
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "no_order_comment_title","Komentar");?>',
                anchor: '100%',
                height: 70
            }]
    },{
        hidden: true,
        layout: 'form',
        id: 'podatki_narocila',
        xtype: 'fieldset',
        title: '<?php echo $LangPack->GetLabel("edit_order_window", "order_details_fieldset_title","Podatki o naročilu");?>',
        anchor: '-0',
        items:[
            new Ext.form.ComboBox({
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "assistant_title","Asistent");?>', 
                mode: 'local',
                triggerAction: 'all',
                editable: false,
                width: 200,
                hiddenName: 'assistent',
                name: 'assistent',
                id: 'assistentCombo',
                listeners:{
                    focus: function(combo){
                        if(combo.getValue() == 0 || combo.getValue == null)
                            combo.setValue('<?php echo $LangPack->GetLabel("CRM_all", "select_option_title","Izberite...");?>');
                    },
                    select: function(){
                       // <?php echo $windowId; ?>.setHeight(260);
                        Ext.getCmp('izdelek').show();
                    }
                },
                renderer : function(a, metaData, record) {
                    console.log("ttra");
                    var st = Ext.getCmp('assistentCombo').getStore();
                    if(st.find('id',a) != -1){
                        
                        var r = st.getAt(st.find('id',a));
                     //   return r.data.value;
                    }
                    
                },
                lazyRender: true,
                store: new Ext.data.ArrayStore({
                    fields:['id', 'value'],
                    data:[
                        <?php
                        $assistents = array();
						if(isset($_SESSION['CRM_login'])){
							$sql = "SELECT *
								FROM ".DB_WARPIT_WEBCATI_BASE."._Interviewer
								WHERE id IN
								(
								    SELECT id 
								    FROM ".DB_WARPIT_WEBCATI_BASE."._group_link
								    WHERE id_group =
								    (
								    	SELECT presentation_team
								        FROM ".WARPIT_CRM."._PresentatorPermissions
								        WHERE id_project = $projectId
								        AND cati_day = $dan
								        AND cati_hour = $ura
										AND cati_location = ".StringChecker::Check($_POST['cati_location'])."
								     )
								)";
						}else{
							$sql = "SELECT * FROM ".DB_WARPIT_WEBCATI_BASE."._Interviewer";
						}
						$res = $db->SQLexecute($sql);
						
						while($row = $db->fetchAssoc($res)){
							array_push($assistents, "['".$row['id']."', '".$row['username']." (".$row['Firstname']." ".$row['Surname'].")']");
						}
						echo implode(", ", $assistents);
                        ?>
                    ]
                }),
                valueField: 'id',
                displayField: 'value'
        }),
            new Ext.form.ComboBox({
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "item_title","Izdelek");?>', 
                mode: 'local',
                triggerAction: 'all',
                editable: false,
                width: 130,
                hidden:true,
                hiddenName: 'izdelek',
                name: 'izdelek',
                id: 'izdelek',
                renderer : function(a, metaData, record) {
                    var st = Ext.getCmp('tip_narocila').getStore();
                    if(st.find('id',a) != -1){
                        var r = st.getAt(st.find('id',a));
                        return r.data.value;
                    }
                },
                listeners:{
                    focus: function(combo){
                        if(combo.getValue() == 0 || combo.getValue == null)
                            combo.setValue('<?php echo $LangPack->GetLabel("CRM_all", "select_option_title","Izberite...");?>');
                    },
                    select: function(combo, rec){
                        
                        Ext.getCmp('kolicina_izdelkov').show();
                        if(Ext.getCmp('kolicina_izdelkov').isVisible){
                        	 Ext.getCmp('tip_narocila').getStore().load({params: {'id': combo.getValue(), 'quant': Ext.getCmp('kolicina_izdelkov').getValue() }, callback: function(a,b,success){
                        		if(success){
                        			if(Ext.getCmp('order_confirm').isVisible()){
			                       		Ext.getCmp('order_confirm_text').fireEvent('show', Ext.getCmp('order_confirm_text'));
			                       	}
                        		}	 	
                        	 }});
                        }
                    }
                },
                lazyRender: true,
                store: new Ext.data.ArrayStore({
                    fields:['id', 'value', 'code', 'price1', 'price2', 'price3'],
                    data:[
                        <?php $izdelki = array();
                        $sql = "SELECT * FROM ". WARPIT_CRM."._Products WHERE deleted = 0 ORDER BY orderBy";
                        $res = $db->SQLexecute($sql);
                        while($dat=$db->fetchAssoc($res)){
                            array_push($izdelki, '["'.$dat['id'].'", "'.$dat['product_name'].'", "'.$dat['product_code'].'", "'.$dat['cena1'].'", "'.$dat['cena2'].'", "'.$dat['cena3'].'"]');
                        }
                        echo implode(", ", $izdelki);
                        ?>
                    ]
                }),
                valueField: 'id',
                displayField: 'value'
         }),
            new Ext.form.ComboBox({
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "item_number_title","Količina izdelkov");?>', 
                mode: 'local',
                triggerAction: 'all',
                editable: false,
                width: 50,
                hidden:true,
                hiddenName: 'kolicina_izdelkov',
                name: 'kolicina_izdelkov',
                id: 'kolicina_izdelkov',
                lazyRender: true,
                listeners:{
                    focus: function(combo){
                        if(combo.getValue() == 0 || combo.getValue == null)
                            combo.setValue('<?php echo $LangPack->GetLabel("CRM_all", "select_option_title","Izberite...");?>');
                    },
                    select: function(combo){
                      //  <?php echo $windowId; ?>.setHeight(330);
                        Ext.getCmp('tip_narocila').show();
                        
                        Ext.getCmp('tip_narocila').getStore().load({params: {'id': Ext.getCmp('izdelek').getValue(), 'quant': combo.getValue() }, callback: function(a,b,success){
                        	if(success){
                        		if(Ext.getCmp('order_confirm').isVisible()){
		                       		Ext.getCmp('order_confirm_text').fireEvent('show', Ext.getCmp('order_confirm_text'));
		                       	}
                        	}
                        }});
                    }
                   
                },
                store: new Ext.data.ArrayStore({
                    fields:['value'],
                    data:[
                        <?php $n=array(); for($i=1; $i<=10; $i++) { array_push($n, '['.$i.']'); } echo implode(', ', $n); ?>
                    ]
                }),
                valueField: 'value',
                displayField: 'value'
         }),
            new Ext.form.ComboBox({
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "order_type_title","Tip naročila");?>', 
                mode: 'local',
                triggerAction: 'all',
                editable: false,
                width: 220,
                hidden:true,
                hiddenName: 'tip_narocila',
                name: 'tip_narocila',
                id: 'tip_narocila',
                renderer : function(a, metaData, record) {
                    var st = Ext.getCmp('tip_narocila').getStore();
                    if(st.find('id',a) != -1){
                        var r = st.getAt(st.find('id',a));
                        return r.data.value;
                    }
                },
                listeners:{
                    focus: function(combo){
                        if(combo.getValue() == 0 || combo.getValue == null)
                            combo.setValue('<?php echo $LangPack->GetLabel("CRM_all", "select_option_title","Izberite...");?>');
                    },
                    select: function(a,b,c){
                        Ext.getCmp('enkartni_znesek').hide();
                        Ext.getCmp('credit_lon').hide();
                      //  Ext.getCmp('order_confirm').hide();
                      	Ext.getCmp('cena_izdelka').setValue('');
                      	Ext.getCmp('avans_znesek').setValue('');
                      	Ext.getCmp('credit_card_avans_znesek').setValue('');
                      	Ext.getCmp('datum_placila_avansa').reset();
                      	Ext.getCmp('credit_lon_stevilo_obrokov').setValue('');
                        Ext.getCmp('avans_check').setValue('');
                        Ext.getCmp('prikazi_polog').setValue('');
                        
                        
                        if(b.data.id == 1)
                            Ext.getCmp('enkartni_znesek').show();
                        else if(b.data.id == 2){
                            Ext.getCmp('enkartni_znesek').show();
                        }else if(b.data.id == 3){
                        	Ext.getCmp('enkartni_znesek').show();
                        }else if(b.data.id == 4){
                        	Ext.getCmp('enkartni_znesek').show();
                        }else if(b.data.id == 5){
                        	Ext.getCmp('credit_lon').show();
                        }
                        if(Ext.getCmp('enkartni_znesek').isVisible()){
                        	Ext.getCmp('enkartni_znesek').setTitle(b.data.value.split('-')[0]);
                        }
                        if(Ext.getCmp('order_confirm').isVisible()){
                       		Ext.getCmp('order_confirm_text').fireEvent('show', Ext.getCmp('order_confirm_text'));
                       	}
                    }
                },
                lazyRender: true,
            	store: new Ext.data.JsonStore({
                    url : '<?php echo $ajax; ?>',
                    root : 'rows',
                    baseParams: {
                        action: 'getPrices'
                    },
                    fields:[
                             { name:"id", type: 'int' },
                             { name:"value", type: 'string' },
                             { name:"price", type: 'float'},
                             { name:"single", type: 'float'}
                    ]
                }),
                valueField: 'id',
                displayField: 'value'
         }),{
            xtype: 'textfield',
            name: 'cena_izdelka',
            id: 'cena_izdelka',
            hidden: true,
            editable: false,
            fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "item_price_title","Cena izdelka");?>',
            width: 50
        },
        //Enkratni znesek
        {
            hidden: true,
            layout: 'form',
            id: 'enkartni_znesek',
            xtype: 'fieldset',
            title: '<?php echo $LangPack->GetLabel("edit_order_window", "one_time_payment_fieldset_title","Enkratni znesek");?>',
            anchor: '-0',
            items:[
            
            // AVANS CHECK
                new Ext.form.ComboBox({
                    fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "avans_label","Avans");?>', 
                    mode: 'local',
                    triggerAction: 'all',
                    editable: false,
                    //hidden:true,
                    width: 100,
                    hiddenName: 'avans_check',
                    name: 'avans_check',
                    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: 'avans_check',
                    lazyRender: true,
                    store: new Ext.data.ArrayStore({
                        fields:['id', 'value'],
                        data:[
                            ['1', '<?php echo $LangPack->GetLabel("CRM_all", "YES","DA");?>'],
                            ['2', '<?php echo $LangPack->GetLabel("CRM_all", "NO","NE");?>']
                        ]
                    }),
                    valueField: 'id',
                    displayField: 'value',
                    
                    listeners:{
                        select: function(combo,b,c){
                            Ext.getCmp('order_confirm').hide();
                            Ext.getCmp('save_button').disable();
                            if (combo.getValue() == 1) {
                                Ext.getCmp('avans_znesek').show();
                                Ext.getCmp('credit_card_avans_znesek').show();
                                Ext.getCmp('currency_label').show();
                                Ext.getCmp('credit_currency_label').show();
                                Ext.getCmp('avans_label2').show();
                                Ext.getCmp('avansContainer').show();
                                Ext.getCmp('credit_card_avansContainer').show();
                                Ext.getCmp('datum_placila_avansa').reset()
                                
                            } else {
                            
                                Ext.getCmp('avans_znesek').hide();
                                Ext.getCmp('credit_card_avans_znesek').hide();
                                Ext.getCmp('currency_label').hide();
                                Ext.getCmp('credit_currency_label').hide();
                                Ext.getCmp('avans_label2').hide();
                                Ext.getCmp('avansContainer').hide();
                                Ext.getCmp('credit_card_avansContainer').hide();
                                Ext.getCmp('datum_placila_avansa').hide();
                                Ext.getCmp('avans_znesek').setValue("");
                                Ext.getCmp('credit_card_avans_znesek').setValue("");
                                Ext.getCmp('order_confirm').show();
                                Ext.getCmp('order_confirm_text').show();
                            }
                            if(Ext.getCmp('order_confirm').isVisible()){
	                       		Ext.getCmp('order_confirm_text').fireEvent('show', Ext.getCmp('order_confirm_text'));
	                       	}
                        }
                    }
                }),
                {
                	xtype: 'label',
                	text: '<?php echo $LangPack->GetLabel("edit_order_window", "avans_label2", "Znesek avansa");?>',
                	hidden: true,
                	id: 'avans_label2',
                	style: {
                		fontSize: '12px'
                	}
		        },
                {
                	xtype: 'compositefield',
                	hidden: true,
                	id: 'avansContainer',
    				defaults:{
			    		style: 'margin-right: 5px'
			    	},
    				items: [
    					{
    						//gotovinski avans
		                    xtype: 'textfield',
		                    name: 'avans_amount',
		                    fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "cash_avans_payment_amount", "Gotovina");?>',
		                    width: 50,
		                    hidden: true,
		                    enableKeyEvents: true,
		                    id: 'avans_znesek',
		                    maskRe: /^[0-9.]+$/,
		                    editable: true,
		                    listeners:{
		                    	keyup: function(comp, a, b){
		                    		//v primeru sta oba polja prazna               
		           					if(comp.getValue() == "" && Ext.getCmp('credit_card_avans_znesek').getValue() == ""){
			                    		Ext.getCmp('order_confirm').hide();
			                    		Ext.getCmp('datum_placila_avansa').hide();
			                    		Ext.getCmp('datum_placila_avansa').reset();
			                    	} else {
										//v primeru da je eno izmed polj prazno
			                    		if(comp.getValue() != "" || Ext.getCmp('credit_card_avans_znesek').getValue() != ""){
			                    			if(!Ext.getCmp('datum_placila_avansa').isVisible())
				                    			Ext.getCmp('datum_placila_avansa').show();
				                    		if(Ext.getCmp('order_confirm').isVisible()){
					                       		Ext.getCmp('order_confirm_text').fireEvent('show', Ext.getCmp('order_confirm_text'));
					                       	}	
			                    		}else{
			                    			Ext.getCmp('datum_placila_avansa').hide();
			                    			Ext.getCmp('datum_placila_avansa').reset();
			                    		}			                    	
			                    	}         	     		
		                    	}
		                    }
		                },
		                {
		                	xtype: 'label',
		                	name: 'currency_label',
		                	id: 'currency_label',
		                	hidden: true,
		                	text: '<?php echo MONEY_VALUE; ?>'
		                }
    				]
                },{
                	xtype: 'compositefield',
                	hidden: true,
                	id: 'credit_card_avansContainer',
			    	items: [{
			    		//avans z kreditno kartico
	                	xtype: 'textfield',
	                    name: 'credit_card_avans_amount',
	                    fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "credit_card_avans_payment_amount", "Kreditna kartica");?>',
	                    width: 50,
	                    hidden: true,
	                    enableKeyEvents: true,
	                    id: 'credit_card_avans_znesek',
	                    maskRe: /^[0-9.]+$/,
	                    editable: true,
	                    listeners:{
	                    	keyup: function(comp, a, b){
	                    		//v primeru sta oba polja prazna
	                    		if(comp.getValue() == "" && Ext.getCmp('avans_znesek').getValue() == ""){
		                    		Ext.getCmp('order_confirm').hide();
		                    		Ext.getCmp('datum_placila_avansa').hide();
		                    		Ext.getCmp('datum_placila_avansa').reset();
		                    	} else {	                    		
		                    		//v primeru da je eno izmed polj prazno
		                    		if(comp.getValue() != "" || Ext.getCmp('avans_znesek').getValue() != ""){
		                    			if(!Ext.getCmp('datum_placila_avansa').isVisible())
			                    			Ext.getCmp('datum_placila_avansa').show();
			                    		if(Ext.getCmp('order_confirm').isVisible()){
				                       		Ext.getCmp('order_confirm_text').fireEvent('show', Ext.getCmp('order_confirm_text'));
				                       	}
		                    		}else{
		                    			Ext.getCmp('datum_placila_avansa').hide();
		                    			Ext.getCmp('datum_placila_avansa').reset();
		                    		}
	                    		}
	                    	}
	                    }
			    	},{
	                	xtype: 'label',
	                	name: 'currency_label',
	                	id: 'credit_currency_label',
	                	hidden: true,
	                	text: '<?php echo MONEY_VALUE; ?>'
	                }]
                },            
                new Ext.form.DateField({
                    format: 'd.m.Y',
                    editable: false,
                    hidden:true,
                    id: 'datum_placila_avansa',
                    name: 'datum_placila_avansa',
                    width: 100,
                    fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "avans_payment_date","Datum plačila avansa");?>',
                    listeners:{
                        select: function(comp,a,b){
                        	Ext.getCmp('save_button').disable();
                           	Ext.getCmp('order_confirm').show();
                           	Ext.getCmp('order_confirm_text').show();
                           	if(Ext.getCmp('order_confirm').isVisible()){
	                       		Ext.getCmp('order_confirm_text').fireEvent('show', Ext.getCmp('order_confirm_text'));
	                       	}
                        }
                    }
                })
            ]
        },
        //Credit lone
        {
            hidden: true,
            layout: 'form',
            id: 'credit_lon',
            xtype: 'fieldset',
            title: '<?php echo $LangPack->GetLabel("edit_order_window", "credit_lon_fieldset_title","LON KREDITI");?>',
            anchor: '-0',
            items:[
                new Ext.form.ComboBox({
                    fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "payments_number_type_title","ŠTEVILO OBROKOV");?>', 
                    mode: 'local',
                    triggerAction: 'all',
                    editable: false,
                    width: 80,
                    //hiddenName: 'credit_lon_stevilo_obrokov',
                    name: 'credit_lon_stevilo_obrokov',
                    renderer : function(a, metaData, record) {
                        var st = Ext.getCmp('credit_lon_stevilo_obrokov').getStore();
                        if(st.find('id',a) != -1){
                            var r = st.getAt(st.find('id',a));
                            return r.data.value;
                        }
                    },
                    id: 'credit_lon_stevilo_obrokov',
                    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']
                        ]
                    }),
                    listeners:{
                        select: function(combo,a,b){
                            Ext.getCmp('prikazi_polog').show();
                            if(Ext.getCmp('order_confirm').isVisible()){
	                       		Ext.getCmp('order_confirm_text').fireEvent('show', Ext.getCmp('order_confirm_text'));
	                       	}
                        }
                    },
                    valueField: 'id',
                    displayField: 'value'
               }),
               new Ext.form.ComboBox({
                    fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "prikazi_polog_label","Prikazi polog");?>', 
                    mode: 'local',
                    triggerAction: 'all',
                    editable: false,
                    hidden:true,
                    width: 100,
                    hiddenName: 'prikazi_polog',
                    name: 'prikazi_polog',
                    renderer : function(a, metaData, record) {
                        var st = Ext.getCmp('prikazi_polog').getStore();
                        if(st.find('id',a) != -1){
                            var r = st.getAt(st.find('id',a));
                            return r.data.value;
                        }
                    },
                    id: 'prikazi_polog',
                    lazyRender: true,
                    store: new Ext.data.ArrayStore({
                        fields:['id', 'value'],
                        data:[
                            ['1', '<?php echo $LangPack->GetLabel("CRM_all", "YES","DA");?>'],
                            ['2', '<?php echo $LangPack->GetLabel("CRM_all", "NO","NE");?>']
                            
                        ]
                    }),
                    valueField: 'id',
                    displayField: 'value',
                    listeners:{
                        select: function(combo,a,b){
                        	Ext.getCmp('save_button').disable();
                            Ext.getCmp('order_confirm').show();
                            Ext.getCmp('order_confirm_text').show();
                            if(Ext.getCmp('order_confirm').isVisible()){
	                       		Ext.getCmp('order_confirm_text').fireEvent('show', Ext.getCmp('order_confirm_text'));
	                       	}
                        }
                    }
               })
            ]
        },
        {
            xtype: 'fieldset',
            id: 'delivery_fieldset',
            hidden: true,
            anchor: '-0',
            layout: 'form',
            title: '<?php echo $LangPack->GetLabel("edit_order_window", "delivery_fieldset_title","Podatki o dostavi");?>',
            items:[
                new Ext.form.ComboBox({
                    fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "shipping_type_title","Tip dostave");?>', 
                    mode: 'local',
                    triggerAction: 'all',
                    editable: false,
                    width: 130,
                    hiddenName: 'tip_dostave',
                    name: 'tip_dostave',
                    id: 'tip_dostave',
                    renderer : function(a, metaData, record) {
                        var st = Ext.getCmp('tip_dostave').getStore();
                        if(st.find('id',a) != -1){
                            var r = st.getAt(st.find('id',a));
                            return r.data.value;
                        }
                    },
                    lazyRender: true,
                    store: new Ext.data.ArrayStore({
                        fields:['id', 'value'],
                        data:[
                            <?php
                            $tipDostave = array();
                            $sql = "SELECT * FROM ". WARPIT_CRM."._tipDostave WHERE deleted = 0 ORDER BY orderBy";
                            $res = $db->SQLexecute($sql);
                            while($dat=$db->fetchAssoc($res)){
                                array_push($tipDostave, '["'.$dat['id'].'", "'.$dat['naziv_dostave'].'"]');
                            }
                            echo implode(", ", $tipDostave);
                            ?>
                        ]
                    }),
                    listeners:{
                        focus: function(combo){
                            if(combo.getValue() == 0 || combo.getValue == null)
                                combo.setValue('<?php echo $LangPack->GetLabel("CRM_all", "select_option_title","Izberite...");?>');
                        },
                    },
                    valueField: 'id',
                    displayField: 'value'
                }),
                new Ext.form.DateField({
                    format: 'd.m.Y',
                    editable: false,
                    name: 'datum_dostave',
                    width: 100,
                    id: 'datum_dostave',
                    fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "shipping_date_title","Datum dostave");?>',
                    listeners: {
                        select: function(comp,a,b){
                            Ext.getCmp('order_confirm').show();
                            Ext.getCmp('order_confirm_text').show();
                        }
                    }
                }),{
                    xtype: 'textarea',
                    name: 'opomba_datuma_dostave',
                    id: 'opomba_datuma_dostave',
                    fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "shipping_date_comment_title","Opomba za datum dostave");?>',
                    anchor: '95%',
                    height: 70,
                    listeners:{
                        change: function(comp, a,b){                
                        	Ext.getCmp('save_button').disable();
                        	Ext.getCmp('order_confirm').show();            
                            if(Ext.getCmp('tip_narocila').getValue() == 5){
                            	var itemCode = '<?php echo $LangPack->GetLabel("edit_order_window", "item_code_confirm_text","ŠIFRA IZDELKA");?>';
                      			var code = '<?php echo $LangPack->GetLabel("edit_order_window", "code_confirm_text","ima šifro");?>';
                            	
                            	var combo = Ext.getCmp('izdelek');
		                        var comboStore = combo.getStore();
		                        var data = comboStore.getAt(comboStore.findExact('id', combo.getValue())).data;

		                        
	                            var stObrokov = Ext.getCmp('credit_lon_stevilo_obrokov').getRawValue();
	                            
	                            var text = itemCode + ' (' + data.value + ' '+code+':' + data.code + ') / ';
		                        text += data.value +' / ';
		                        text += Ext.getCmp('kolicina_izdelkov').getRawValue() + ' / ' + a +' <br><br> ';
		                        
		                        Ext.Ajax.request({
		                        	url: '<?php echo $ajax;?>',
		                        	params:{
		                        		action: 'getLoanCredit',
		                        		numberOfAnnuities: stObrokov,
		                        		id_product: data.id
		                        	},
		                        	success:function(resp, opt){
		                        		var data = Ext.decode(resp.responseText);
		                        		text += '<b><?php echo $LangPack->GetLabel("delivery_finish_window", "numberOfAnnuities", "Število anuitet"); ?>: '+stObrokov+'</b><br>';
						                text += '<?php echo $LangPack->GetLabel("delivery_finish_window", "CreditPrice", "Znesek kredita znaša"); ?>: '+(parseFloat(data.CreditPrice) * parseFloat(Ext.getCmp('kolicina_izdelkov').getValue())).toFixed(2)+' <?php echo MONEY_VALUE;?><br>';
						                text += '<?php echo $LangPack->GetLabel("delivery_finish_window", "AnnuitiePrice", "Znesek anuitete znaša"); ?>: '+(parseFloat(data.AnnuitiePrice) * parseFloat(Ext.getCmp('kolicina_izdelkov').getValue())).toFixed(2)+' <?php echo MONEY_VALUE;?><br>';
						                text += '<?php echo $LangPack->GetLabel("delivery_finish_window", "DepositePrice", "Polog znaša"); ?>: '+(parseFloat(data.DepositePrice) * parseFloat(Ext.getCmp('kolicina_izdelkov').getValue())).toFixed(2)+' <?php echo MONEY_VALUE;?><br>';
						                text += '<?php echo $LangPack->GetLabel("delivery_finish_window", "ToatlAmount", "Skupni znesek znaša"); ?>: '+((parseFloat(data.CreditPrice) + parseFloat(data.DepositePrice)) * parseFloat(Ext.getCmp('kolicina_izdelkov').getValue())).toFixed(2) + ' <?php echo MONEY_VALUE;?>';
						                
						                var cena = Ext.getCmp('tip_narocila');
		                        		var cenaStore = cena.getStore();
		                        		cenaStore.reload({callback: function(a,b,c){
				                        	if(c){
				                        		Ext.each(a,function(d){
				                        			if(d.data.id == cena.getValue()){
								                        Ext.getCmp('cena_izdelka').setValue(d.data.single);
				                        				Ext.getCmp('order_confirm_text').update(text);
				                        			}
				                        		})
				                        	}
				                        }});		                        		 
		                        	}
		                        });
	                        }else{
	                        	var itemCode = '<?php echo $LangPack->GetLabel("edit_order_window", "item_code_confirm_text","ŠIFRA IZDELKA");?>';
		                        var izdelek = '<?php echo $LangPack->GetLabel("edit_order_window", "product_confirm_text","Izdelek");?>';
		                        var kolicina = '<?php echo $LangPack->GetLabel("edit_order_window", "product_amount_confirm_text","Kos");?>';
		                        var cenaLabel = '<?php echo $LangPack->GetLabel("edit_order_window", "product_price_confirm_text","Cena");?>';
		                        var placano_gotovina = '<?php echo $LangPack->GetLabel("edit_order_window", "cash_product_avans_price_confirm_text","Plačano (gotovina)");?>';
	                        	var placano_kartica = '<?php echo $LangPack->GetLabel("edit_order_window", "credit_card_prodict_avans_price_confirm_text","Plačano (kreditna kartica)");?>';
		                        var zaPlacat = '<?php echo $LangPack->GetLabel("edit_order_window", "avans_to_price_confirm_text","za plačati");?>';
		                        var combo = Ext.getCmp('izdelek');
		                        var comboStore = combo.getStore();
		                        var data = comboStore.getAt(comboStore.findExact('id', combo.getValue())).data;
		                        
		                        var cena = Ext.getCmp('tip_narocila');
		                        var cenaStore = cena.getStore();
		                        cenaStore.reload({callback: function(a,b,c){
	                        	if(c){
	                        		Ext.each(a,function(d){
	                        			if(d.data.id == cena.getValue()){
					                        var text = itemCode + ': ' + data.code+' <br> ';
					                        text += izdelek + ': ' + data.value + '<br>';
					                        text += kolicina + ': '+ Ext.getCmp('kolicina_izdelkov').getRawValue() + '<br>';
					                        text += cenaLabel + ': ' + d.data.price.toString().replace('.', ',') + ' <?php echo MONEY_VALUE;?><br>';
					                        var avans = Ext.getCmp('avans_znesek').getValue();
					                        var creditAvans = Ext.getCmp('credit_card_avans_znesek').getValue();
					                        avans = avans.replace(",",".");
					                        creditAvans = creditAvans.replace(",",".");
					                        if(avans == "") avans = 0;
					                        if(creditAvans == "") creditAvans = 0;
					                        var avansSum = parseInt(avans) + parseInt(creditAvans);
					                        if(avans != null && avans != 0) 
					                        	text += '<span style="color:green">'+placano_gotovina+': '+avans+' <?php echo MONEY_VALUE;?></span><br>';
					                        if(creditAvans != null && creditAvans != 0) 
					                        	text += '<span style="color:green">'+placano_kartica+': '+creditAvans+' <?php echo MONEY_VALUE;?></span><br>'; 
					                        text += '<span style="color:red">'+zaPlacat+': ' +(d.data.price-avansSum).toFixed(2) +' <?php echo MONEY_VALUE;?></span>';
					                        Ext.getCmp('cena_izdelka').setValue(d.data.single);
					                        label.update(text);	
	                        			}
	                        		})
	                        	}
	                        }})
	                        }
                        }
                    }
                }
            ]
        },{
            xtype: 'fieldset',
            id: 'order_confirm',
            hidden: true,
            anchor: '-0',
            layout: 'form',
            title: '<?php echo $LangPack->GetLabel("edit_order_window", "confirm_fieldset_title","Potrditev naročila");?>',
            items:[
            {
                xtype: 'label',
                id: 'order_confirm_text',
                listeners:{
                	'show':function(label){
                		if(Ext.getCmp('tip_narocila').getValue() == 5){
                        	var itemCode = '<?php echo $LangPack->GetLabel("edit_order_window", "item_code_confirm_text","ŠIFRA IZDELKA");?>';
                        	var code = '<?php echo $LangPack->GetLabel("edit_order_window", "code_confirm_text","ima šifro");?>';
                        
                        	var combo = Ext.getCmp('izdelek');
	                        var comboStore = combo.getStore();
	                        var data = comboStore.getAt(comboStore.findExact('id', combo.getValue())).data;
	                        
	                        var stObrokov = Ext.getCmp('credit_lon_stevilo_obrokov').getRawValue();
	                        
                            var text = itemCode + ' (' + data.value + ' '+code+':' + data.code + ') / ';
	                        text += data.value +' / ';
	                        text += Ext.getCmp('kolicina_izdelkov').getRawValue() + ' <br><br> ';
	                        
	                        Ext.Ajax.request({
	                        	url: '<?php echo $ajax;?>',
	                        	params:{
	                        		action: 'getLoanCredit',
	                        		numberOfAnnuities: stObrokov,
	                        		id_product: data.id
	                        	},
	                        	success:function(resp, opt){
	                        		var data = Ext.decode(resp.responseText);
	                        		text += '<b><?php echo $LangPack->GetLabel("delivery_finish_window", "numberOfAnnuities", "Število anuitet"); ?>: '+stObrokov+'</b><br>';
					                text += '<?php echo $LangPack->GetLabel("delivery_finish_window", "CreditPrice", "Znesek kredita znaša"); ?>: '+(parseFloat(data.CreditPrice) * parseFloat(Ext.getCmp('kolicina_izdelkov').getValue())).toFixed(2)+' <?php echo MONEY_VALUE;?><br>';
					                text += '<?php echo $LangPack->GetLabel("delivery_finish_window", "AnnuitiePrice", "Znesek anuitete znaša"); ?>: '+(parseFloat(data.AnnuitiePrice) * parseFloat(Ext.getCmp('kolicina_izdelkov').getValue())).toFixed(2)+' <?php echo MONEY_VALUE;?><br>';
					                text += '<?php echo $LangPack->GetLabel("delivery_finish_window", "DepositePrice", "Polog znaša"); ?>: '+(parseFloat(data.DepositePrice) * parseFloat(Ext.getCmp('kolicina_izdelkov').getValue())).toFixed(2)+' <?php echo MONEY_VALUE;?><br>';
					                text += '<?php echo $LangPack->GetLabel("delivery_finish_window", "ToatlAmount", "Skupni znesek znaša"); ?>: '+((parseFloat(data.CreditPrice) + parseFloat(data.DepositePrice)) * parseFloat(Ext.getCmp('kolicina_izdelkov').getValue())).toFixed(2) + '<?php echo MONEY_VALUE;?>';
					                
					                var cena = Ext.getCmp('tip_narocila');
	                        		var cenaStore = cena.getStore();
	                        		cenaStore.reload({callback: function(a,b,c){
			                        	if(c){
			                        		Ext.each(a,function(d){
			                        			if(d.data.id == cena.getValue()){
							                        Ext.getCmp('cena_izdelka').setValue(d.data.single);
			                        				label.update(text);
			                        			}
			                        		})
			                        	}
			                        }});
	                        	}
	                        });
                        }else{
                        	var itemCode = '<?php echo $LangPack->GetLabel("edit_order_window", "item_code_confirm_text","ŠIFRA IZDELKA");?>';
	                        var izdelek = '<?php echo $LangPack->GetLabel("edit_order_window", "product_confirm_text","Izdelek");?>';
	                        var kolicina = '<?php echo $LangPack->GetLabel("edit_order_window", "product_amount_confirm_text","Kos");?>';
	                        var cenaLabel = '<?php echo $LangPack->GetLabel("edit_order_window", "product_price_confirm_text","Cena");?>';
	                        var placano_gotovina = '<?php echo $LangPack->GetLabel("edit_order_window", "cash_avans_price_confirm_text","Plačano (gotovina)");?>';
	                        var placano_kartica = '<?php echo $LangPack->GetLabel("edit_order_window", "credit_card_avans_price_confirm_text","Plačano (kreditna kartica)");?>';
	                        var zaPlacat = '<?php echo $LangPack->GetLabel("edit_order_window", "avans_to_price_confirm_text","za plačati");?>';
	                        var combo = Ext.getCmp('izdelek');
	                        var comboStore = combo.getStore();
	                        var data = comboStore.getAt(comboStore.findExact('id', combo.getValue())).data;
	                        
	                        var cena = Ext.getCmp('tip_narocila');
	                        var cenaStore = cena.getStore();
	                        cenaStore.reload({callback: function(a,b,c){
	                        	if(c){
	                        		Ext.each(a,function(d){
	                        			if(d.data.id == cena.getValue()){
					                        var text = itemCode + ': ' + data.code+' <br> ';
					                        text += izdelek + ': ' + data.value + '<br>';
					                        text += kolicina + ': '+ Ext.getCmp('kolicina_izdelkov').getRawValue() + '<br>';
					                        text += cenaLabel + ': ' + d.data.price.toString().replace('.', ',') + ' <?php echo MONEY_VALUE;?><br>';
					                        var avans = Ext.getCmp('avans_znesek').getValue();
					                        var creditAvans = Ext.getCmp('credit_card_avans_znesek').getValue();
					                        avans = avans.replace(",",".");
					                        creditAvans = creditAvans.replace(",",".");
					                        if(avans == "") avans = 0;
					                        if(creditAvans == "") creditAvans = 0;
					                        var avansSum = parseInt(avans) + parseInt(creditAvans);
					                        if(avans != null && avans != 0) 
					                        	text += '<span style="color:green">'+placano_gotovina+': '+avans+' <?php echo MONEY_VALUE;?></span><br>';
					                        if(creditAvans != null && creditAvans != 0) 
					                        	text += '<span style="color:green">'+placano_kartica+': '+creditAvans+' <?php echo MONEY_VALUE;?></span><br>'; 
					                        text += '<span style="color:red">'+zaPlacat+': ' +(d.data.price-avansSum).toFixed(2) +' <?php echo MONEY_VALUE;?></span>';
					                        Ext.getCmp('cena_izdelka').setValue(d.data.single);
					                        label.update(text);	
	                        			}
	                        		})
	                        	}
	                        }});
	                       
                        }
                	}
                }
            },
            {
                xtype: 'button',
                name: 'potrditev_narocila_enkratno',
                text: '<?php echo $LangPack->GetLabel("edit_order_window", "avans_confirm_data","Potrdi naročilo");?>',
                handler: function(){
                    Ext.Msg.confirm('<?php echo $LangPack->GetLabel("edit_order_window", "confirm_order_title","Potrditev naročila");?>', '<?php echo $LangPack->GetLabel("edit_order_window", "confirm_order_msg","Ali želite to naročilo potrditi?");?>', function(btn){
                        if(btn == "yes"){
                         /*   Ext.getCmp('tip_dostave').disable();
                            Ext.getCmp('datum_dostave').disable();
                            Ext.getCmp('opomba_datuma_dostave').disable();*/
                            Ext.getCmp('order_confirm').hide();
                            if(firstConfirm){
                            	Ext.getCmp('delivery_location_fieldset').show();
	                            Ext.getCmp('delivery_location_company_fieldset').show();
                            	Ext.getCmp('save_button').enable();
	                            
                            }else{
                            	Ext.getCmp('delivery_fieldset').show();
	                            firstConfirm=true;
                            }
                        }
                    });
                }
            }]
        },{
            xtype: 'fieldset',
            id: 'delivery_location_fieldset',
            hidden: true,
            anchor: '-0',
            layout: 'form',
            collapsible: true,
            collapsed: true,
            title: '<?php echo $LangPack->GetLabel("edit_order_window", "delivery_location_fieldset_title","Podatki o dostavi (Stranka)");?>',
            items:[{
                xtype: 'textfield',
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "surname_title","Priimek");?>',
                name: 'Priimek'
            },{
                xtype: 'textfield',
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "name_title","Ime");?>',
                name: 'Ime'
            },{
                xtype: 'textfield',
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "address_title","Naslov");?>',
                name: 'Naslov'
            },{
                xtype: 'numberfield',
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "post_code_title","Poštna številka");?>',
                name: 'Posta',
                id: 'Posta'
            },{
                xtype: 'combo',
                width: 143,
				hideTrigger: true,
	        	triggerAction: 'all',
	        	mode: 'remote',
	        	store: new Ext.data.JsonStore({
	                url : '<?php echo $zipAjax; ?>',
	                root : 'rows',
	                baseParams: {
	                    action: 'getCity'
	                },
	                autoLoad: true,
	                fields:[
						{ name:"textColumn", type: 'string' },
						{ name:"codeColumn", type: 'int'}
	                ]
	            }),
	            valueField: 'textColumn',
	            displayField: 'textColumn',
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "city_title","Kraj");?>',
                name: 'Kraj',
                id: 'Kraj'
            },{
                xtype: 'textfield',
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "phone_title","Telefonska številka ");?>',
                name: 'Telefonska_stevilka'
            }]
        },
        {
            xtype: 'fieldset',
            id: 'delivery_location_company_fieldset',
            hidden: true,
            anchor: '-0',
            layout: 'form',
            collapsible: true,
            collapsed: true,
            title: '<?php echo $LangPack->GetLabel("edit_order_window", "delivery_location_company_fieldset_title","Podatki o dostavi (Podjetje)");?>',
            items:[{
                xtype: 'textfield',
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "company_title","Naziv podjetja");?>',
                name: 'naziv_podjetja'
            },{
                xtype: 'numberfield',
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "tax_number_title","DAVČNA ŠTEVILKA");?>',
                name: 'davcna_stevilka'
            },{
                xtype: 'textfield',
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "address_title","Naslov");?>',
                name: 'Naslov_podjetja'
            },{
                xtype: 'numberfield',
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "post_code_title","Poštna številka");?>',
                name: 'Posta_podjetja',
                id: 'Posta_podjetja'
            },{
                xtype: 'combo',
                width: 143,
				hideTrigger: true,
	        	triggerAction: 'all',
	        	mode: 'remote',
	        	store: new Ext.data.JsonStore({
	                url : '<?php echo $zipAjax; ?>',
	                root : 'rows',
	                baseParams: {
	                    action: 'getCity'
	                },
	                autoLoad: true,
	                fields:[
						{ name:"textColumn", type: 'string' },
						{ name:"codeColumn", type: 'int'}
	                ]
	            }),
	            valueField: 'textColumn',
	            displayField: 'textColumn',
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "city_title","Kraj");?>',
                name: 'Kraj_podjetja',
                id: 'Kraj_podjetja'
            },{
                xtype: 'textfield',
                fieldLabel: '<?php echo $LangPack->GetLabel("edit_order_window", "phone_title","Telefonska številka ");?>',
                name: 'Telefonska_stevilka_podjetja'
            }]
        }
        ]
    }]
});

Ext.getCmp('<?php echo $gridName;?>').getForm().load({
    url: '<?php echo $ajax;?>',
    params:{
        action: 'get',
        id_tel: '<?php echo $id_tel;?>',
        projectId: '<?php echo $projectId;?>'
    },
    success: function(form, b, c){
        var combo = Ext.getCmp('vzrok');
        var index = combo.getStore().findExact('id', combo.getValue());
        if(index != -1){
            var record = combo.getStore().getAt(index);
            if(record.data.open == 1){
                Ext.getCmp('podatki_narocila').show();
                Ext.getCmp('brez_nakupa_komentar').hide();
               // <?php echo $windowId; ?>.setHeight(600);
                narocnik = true;
                
               var data = Ext.decode(b.response.responseText).data;
       	   		Ext.getCmp('tip_narocila').getStore().load({params: {'id': data.izdelek, 'quant': data.kolicina_izdelkov }, callback: function(resp, a, b){
       	   			if(b){
       	   				Ext.getCmp('tip_narocila').setValue(data.tip_narocila);
       	   				Ext.each(resp, function(d){
       	   					if(data.tip_narocila == d.data.id){
	       	   					Ext.getCmp('cena_izdelka').setValue(d.data.single);
	       	   				}
       	   				});
       	   				Ext.getCmp('enkartni_znesek').setTitle(Ext.getCmp('tip_narocila').getRawValue().split('-')[0]);
       	   			}
       	   		}});
                
               if(data.izdelek != 0)
               {                   
                   Ext.getCmp('izdelek').show();
               }
               if(data.kolicina_izdelkov != 0)
               {
                   Ext.getCmp('kolicina_izdelkov').show();
               } 
               if(data.tip_narocila != 0)
               {
                   Ext.getCmp('tip_narocila').show(); 
                   if(data.tip_narocila == 5)
                   {
	                   Ext.getCmp('credit_lon').show();
	                   if(data.show_deposti != 0){
	                   		Ext.getCmp('prikazi_polog').show();
	                   }
                   }
                   else
                   {
                       Ext.getCmp('enkartni_znesek').show();
                       Ext.getCmp('avans_check').show();
                   }
               }
               if(data.avans_check == 1)
               {
                   Ext.getCmp('avansContainer').show();
                   Ext.getCmp('credit_card_avansContainer').show();
                   
                   Ext.getCmp('avans_znesek').show();
                   Ext.getCmp('credit_card_avans_znesek').show();
                   
                   Ext.getCmp('avans_label2').show();
                   Ext.getCmp('currency_label').show();
                   Ext.getCmp('credit_currency_label').show();
                   
                   Ext.getCmp('datum_placila_avansa').show();
               }
               if(data.tip_dostave == 0)
               {
                    Ext.getCmp('order_confirm_text').show();
                    Ext.getCmp('order_confirm').show();
               }
               if(data.tip_dostave != 0)
               {
                    Ext.getCmp('delivery_fieldset').show();
               }
               if(data.datum_dostave == "0000-00-00")
               {
                   Ext.getCmp('delivery_confirm').show();
                   Ext.getCmp('delivery_confirm_text').show();
               }else if(data.datum_dostave != "0000-00-00")
               {
               	firstConfirm=true;
                 Ext.getCmp('delivery_location_fieldset').show();   
                 Ext.getCmp('delivery_location_company_fieldset').show();
                 Ext.getCmp('save_button').enable();
               }
               if(data.placilo_na_kredit_nacin_placila != 0)
               {
                   Ext.getCmp('placilo_na_kredit_nacin_placila').show();
               }
               
                Ext.getCmp('order_confirm_text').show();
                Ext.getCmp('order_confirm').show();
            }else{
               // <?php echo $windowId; ?>.setHeight(250);
                Ext.getCmp('brez_nakupa_komentar').show();
                if(combo.getValue() == null || combo.getValue() ==0)
                    combo.setValue('<?php echo $LangPack->GetLabel("CRM_all", "select_option_title","Izberite...");?>'); 
            }
        }else{
            //<?php echo $windowId; ?>.setHeight(250);
            if(combo.getValue() == null || combo.getValue() ==0)
                combo.setValue('<?php echo $LangPack->GetLabel("CRM_all", "select_option_title","Izberite...");?>'); 
        }        
    }
});

var <?php echo $windowId;?> = new Ext.Window({
    title:'<?php echo $LangPack->GetLabel("edit_order_window", "window_title","Naročila");?>',
    id      : '<?php echo $windowId;?>',
    width   : 700,
    height  : 500,
    plain   : true,
    layout  : 'border',
    frame: true,
    modal: true,
    items   : [
        <?php echo $gridName;?>
    ],
    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);
            Ext.getCmp('<?php echo $windowId;?>').setSize(700,500);
            
            Ext.Ajax.request({
            	url: '<?php echo $ajax; ?>',
            	params: {
            		action: 'getName',
            		id_tel: '<?php echo $id_tel; ?>'
            	},
            	success: function(resp, opt){
            		var r = Ext.decode(resp.responseText);
            		Ext.getCmp('<?php echo $windowId; ?>').setTitle('<?php echo $LangPack->GetLabel("edit_order_window", "window_title","Naročila");?> (' + r.name + ')');
            	}
            });
        },
        resize: function(window, width, height){
            if(height >= 550){
                window.setHeight(550);
            }
            var X = (screen.width/2) - ((window.getSize().width)/2);
            var Y = (screen.height/2) - ((window.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_save_button","Shrani");?>',
        disabled: true,
        id: 'save_button',
        handler: function(){
            if(Ext.getCmp('<?php echo $gridName;?>').getForm().isValid()){
                
                Ext.getCmp('<?php echo $gridName;?>').getForm().submit({
                    url: '<?php echo $ajax;?>', 
                    params: { action: 'submit', id_tel: <?php echo $id_tel;?>, projectId: '<?php echo $projectId;?>', cati_location: '<?php echo StringChecker::Check($_POST['cati_location']);?>' },
                    clientValidation: true,
                    success: function(form, action) {
                        Ext.Msg.alert('Success', action.result.msg);
                      Ext.getCmp('<?php echo $windowId;?>').close();
                      <?php if(!isset($_SESSION['CRM_login'])){
                      	echo "if(Ext.getCmp('PrisotnostUserGrid$suffix')){Ext.getCmp('PrisotnostUserGrid$suffix').getStore().reload();}";
                      }else{ ?>
                      	Ext.getCmp('StatisticGrid').getEl().mask('<?php echo $LangPack->GetLabel("CRM_all", "loading_mask_text","Posodabljanje..."); ?>');
                        Ext.getCmp('StatisticGrid').getStore().load({
                            params: { 
                                action: 'get',
                                project_id: '<?php echo $projectId; ?>',
                                dan: '<?php echo $dan;?>',
                                ura: '<?php echo $ura;?>',
                                cati_location: '<?php echo $cati_location; ?>'
                            },
                            callback: function(store, opt, success){
                                if(success){
                                    Ext.getCmp('StatisticGrid').getEl().unmask('<?php echo $LangPack->GetLabel("CRM_all", "loading_mask_text","Posodabljanje..."); ?>');
                                }
                            }
                        });
                        if(Ext.getCmp('Orders')){
                        	Ext.getCmp('Orders').getStore().reload();
                        }
                      	<?php
                      } ?>
                    },
                    failure: function(form, action) {
                        switch (action.failureType) {
                            case Ext.form.Action.CLIENT_INVALID:
                                Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
                                break;
                            case Ext.form.Action.CONNECT_FAILURE:
                                Ext.Msg.alert('Failure', 'Ajax communication failed');
                                break;
                            case Ext.form.Action.SERVER_INVALID:
                               Ext.Msg.alert('Failure', action.result.msg);
                       }
                    }
                });
            }
        }
    }]
}).show();
<?php
	$zipChecker1->SetUp();
	$zipChecker2->SetUp();
?>