/**
 * @author zkutlic
 */
var Zamfir = {
    version: "1.0-beta2"
}
Zamfir.jamstvo = {}
/*
 Zamfir.jamstvo.unos=false
 Zamfir.jamstvo.brisanje=false
 Zamfir.jamstvo.storno=false
 Zamfir.osiguranje.unos=false
 Zamfir.osiguranje.brisanje=false
 Zamfir.osiguranje.storno=false
 */
Zamfir.jamstvo.onJamstvoUnosClick = function(item){

    var simple = new Ext.FormPanel({
        labelWidth: 135, // label settings here cascade unless overridden
        labelAlign: 'right',
        frame: true,
        bodyStyle: 'padding:5px 5px 0',
        width: 500,
        autoHeight: true,
        //defaults: {
        //	width: 250
        //},
        defaultType: 'textfield',
        
        // configure how to read the XML Data
        waitMsgTarget: true,
        
        // configure how to read the XML Data
        // reusable eror reader class defined at the end of this file
        errorReader: new Ext.data.XmlReader({
            record: 'field',
            success: '@success'
        }, ['id', 'msg']),
        
        items: [{
            fieldLabel: 'CI prijave',
            name: 'ci_prij',
            maxLength: 5,
            minLength: 5,
            allowBlank: false,
            width: 60,
            autoHeight: true,
            invalidText: 'Obavezan unos šifre carinarnice'
        }, {
            fieldLabel: 'CI odredišta',
            name: 'ci_odr',
            format: '99999',
            maxLength: 5,
            allowBlank: false,
            width: 60,
            autoHeight: true,
            invalidText: 'Obavezan unos šifre carinarnice'
        }, new Ext.form.DateField({
            fieldLabel: 'Datum prijave',
            name: 'datum',
            format: 'd.m.Y',
            altFormats: 'dmY',
            allowBlank: false,
            autoWidth: true,
            autoHeight: true,
            invalidText: 'Obavezan unos datuma prijave'
        }), {
            fieldLabel: 'Osiguranje',
            name: 'osiguranje',
            maxLength: 31,
            allowBlank: false,
            width: 200,
            autoHeight: true,
            invalidText: 'Obavezan unos oznake osiguranja u obliku 11002/broj/godina/tip/MB-JMBG'
        }, {
            fieldLabel: 'Broj JCD-a',
            name: 'car_br_jcd',
            maxLength: 15,
            width: 160,
            autoHeight: true,
            allowBlank: false
        }, {
            fieldLabel: 'Opis robe',
            name: 'roba',
            allowBlank: false,
            autoHeight: true,
            width: 250
        }, {
            fieldLabel: 'Brutto (kg)',
            name: 'brutto',
            maxLength: 15,
            width: 150,
            autoHeight: true,
            allowBlank: false
        }, {
            fieldLabel: 'Vrijednost robe (Kn)',
            name: 'vr_ro_do',
            maxLength: 15,
            width: 150,
            autoHeight: true,
            allowBlank: false
        }, {
            fieldLabel: 'Iznos mogućeg duga',
            name: 'izngardavu',
            maxLength: 15,
            width: 150,
            autoHeight: true,
            allowBlank: false
        }, new Ext.form.DateField({
            fieldLabel: 'Datum razduženja',
            name: 'datum_razd',
            format: 'd.m.Y',
            altFormats: 'dmY',
            allowBlank: true,
            autoHeight: true,
            autoWidth: true
        })],
        
        buttons: [{
            text: 'Snimi',
            handler: function(){
                simple.getForm().submit({
                    url: 'defaultxml.asp',
                    params: {
                        scope: 'jamstvo',
                        action: 'unos',
                        returnformat: 'xml'
                    },
                    waitMsg: 'Snimam...',
                    success: function(form, action){
                        alert('Snimanje uspješno');
                        window1.close();
                    }
                    /*,
                     
                     failure :function(form, action) {
                     alert('Operacija odbijena : ' + action.failureType+'\n'+action.response.responseText);
                     }
                     */
                });
            }
        }, {
            text: 'Odustani',
            handler: function(){
                window1.close();
            }
        }]
    });
    
    
    
    var window1 = new Ext.Window({
        title: 'Unos/Ispravak podataka o izdanom jamstvu',
        width: 600,
        //height: 400,
        layout: 'fit',
        autoHeight: true,
        //autoWidth: true,
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: simple
    });
    window1.show();
}

Zamfir.jamstvo.onJamstvoRazdClick = function(item){

    var simple = new Ext.FormPanel({
        labelWidth: 120, // label settings here cascade unless overridden
        frame: true,
        bodyStyle: 'padding:5px 5px 0',
        width: 350,
        labelAlign: 'right',
        defaultType: 'textfield',
        autoHeight: true,
        // configure how to read the XML Data
        waitMsgTarget: true,
        
        // configure how to read the XML Data
        // reusable eror reader class defined at the end of this file
        errorReader: new Ext.data.XmlReader({
            record: 'field',
            success: '@success'
        }, ['id', 'msg']),
        
        items: [{
            fieldLabel: 'CI prijave',
            name: 'ci_prij',
            maxLength: 5,
            minLength: 5,
            allowBlank: false,
            autoHeight: true,
            invalidText: 'Obavezan unos šifre carinarnice',
            width: 60
        }, {
            fieldLabel: 'Broj JCD-a',
            name: 'car_br_jcd',
            allowBlank: false,
            autoHeight: true,
            width: 200
        }, new Ext.form.DateField({
            fieldLabel: 'Datum razduženja',
            name: 'datum_razd',
            format: 'd.m.Y',
            altFormats: 'dmY',
            allowBlank: true,
            autoHeight: true,
            autoWidth: true
        })],
        
        buttons: [{
            text: 'Snimi',
            handler: function(){
                simple.getForm().submit({
                    url: 'defaultxml.asp',
                    params: {
                        scope: 'jamstvo',
                        action: 'razd',
                        returnformat: 'xml'
                    },
                    waitMsg: 'Radim...',
                    success: function(form, action){
                        alert('Razduženje uspješno');
                        window1.close();
                    }
                    /*,
                     
                     failure :function(form, action) {
                     alert('Operacija odbijena : ' + action.failureType+'\n'+action.response.responseText);
                     }
                     */
                });
            }
        }, {
            text: 'Odustani',
            handler: function(){
                window1.close();
            }
        }]
    });
    
    // A reusable error reader class for XML forms
    
    
    var window1 = new Ext.Window({
        title: 'Razduženje izdanog jamstva',
        width: 500,
        //height: 300,
        minWidth: 300,
        //minHeight: 100,
        autoHeight: true,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: simple
    });
    window1.show();
}


Zamfir.jamstvo.onJamstvoBrisiClick = function(item){

    var simple = new Ext.FormPanel({
        labelWidth: 120, // label settings here cascade unless overridden
        frame: true,
        bodyStyle: 'padding:5px 5px 0',
        width: 350,
        labelAlign: 'right',
        defaultType: 'textfield',
        autoHeight: true,
        // configure how to read the XML Data
        waitMsgTarget: true,
        
        // configure how to read the XML Data
        // reusable eror reader class defined at the end of this file
        errorReader: new Ext.data.XmlReader({
            record: 'field',
            success: '@success'
        }, ['id', 'msg']),
        
        items: [{
            fieldLabel: 'CI prijave',
            name: 'ci_prij',
            maxLength: 5,
            minLength: 5,
            allowBlank: false,
            autoHeight: true,
            invalidText: 'Obavezan unos šifre carinarnice',
            width: 60
        }, {
            fieldLabel: 'Broj JCD-a',
            name: 'car_br_jcd',
            allowBlank: false,
            autoHeight: true,
            width: 200
        }],
        
        buttons: [{
            text: 'Snimi',
            handler: function(){
                simple.getForm().submit({
                    url: 'defaultxml.asp',
                    params: {
                        scope: 'jamstvo',
                        action: 'brisi',
                        returnformat: 'xml'
                    },
                    waitMsg: 'Brišem...',
                    success: function(form, action){
                        alert('Brisanje uspješno');
                        window1.close();
                    }
                    /*,
                     
                     failure :function(form, action) {
                     alert('Operacija odbijena : ' + action.failureType+'\n'+action.response.responseText);
                     }
                     */
                });
            }
        }, {
            text: 'Odustani',
            handler: function(){
                window1.close();
            }
        }]
    });
    
    // A reusable error reader class for XML forms
    
    
    var window1 = new Ext.Window({
        title: 'Brisanje izdanog jamstva',
        width: 500,
        //height: 300,
        minWidth: 300,
        //minHeight: 100,
        autoHeight: true,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: simple
    });
    window1.show();
}
Zamfir.jamstvo.onPregledSveClick = function(item){

    // create the Data Store
    var store = new Ext.data.Store({
        // load using HTTP
        url: 'defaultxml.asp?scope=jamstvo&action=getall',
        
        // the return will be XML, so lets set up a reader
        reader: new Ext.data.XmlReader({
            // records will have an "cjamstva" tag
            record: 'cjamstva',
            id: 'uq_id',
            totalRecords: '@total'
        }, [{
            name: 'ci_prij',
            mapping: 'ci_prij'
        }, 'ci_odr', {
			name:'datum',
			mapping:'datum',
			type: 'date', 
			dateFormat: 'Y-m-d'
		}, 'osiguranje', 'car_br_jcd', 'brutto', 'vr_ro_do', 'roba', 'izngardavu', {
			name:'datum_razd',
			mapping:'datum_razd',
			type: 'date', 
			dateFormat: 'Y-m-d'
		}])
    
    });
    
    // create the grid
    var grid = new Ext.grid.GridPanel({
        store: store,
        columns: [{
            header: "CI prijave",
            width: 60,
            dataIndex: 'ci_prij',
            sortable: true
        }, {
            header: "CI odredišta",
            width: 60,
            dataIndex: 'ci_odr',
            sortable: true
        }, {
            header: "Datum",
            width: 60,
            dataIndex: 'datum',
            sortable: true
        }, {
            header: "Osiguranje",
            width: 160,
            dataIndex: 'osiguranje',
            sortable: true
        }, {
            header: "Broj JCD-a",
            width: 160,
            dataIndex: 'car_br_jcd',
            sortable: true
        }, {
            header: "Opis robe",
            width: 220,
            dataIndex: 'roba',
            sortable: true
        }, {
            header: "Brutto (kg)",
            width: 60,
            dataIndex: 'brutto',
            sortable: true
        }, {
            header: "Vrijednost robe (Kn)",
            width: 60,
            dataIndex: 'vr_ro_do',
            sortable: true
        }, {
            header: "Iznos mogućeg duga",
            width: 100,
            dataIndex: 'izngardavu',
            sortable: true
        }, {
            header: "Datum razduženja",
            width: 80,
            dataIndex: 'datum_razd',
            sortable: true
        }],
        width: 900,
        height: 400
    });
    
    var window1 = new Ext.Window({
        title: 'Pregled izdanih jamstava',
        width: 950,
        height: 450,
        minWidth: 300,
        minHeight: 250,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: grid
    });
    
    store.load();
    window1.show();
}

Zamfir.jamstvo.onPregledIzdanaClick = function(item){
	var ps = 50;
	// create the Data Store
	var store = new Ext.data.Store({
		// load using HTTP
		url: 'defaultxml.asp',
		baseParams: {
			scope: 'jamstvo',
			action: 'getizdana'
		},
		remoteSort: true,
		// the return will be XML, so lets set up a reader
		reader: new Ext.data.XmlReader({
			// records will have an "cjamstva" tag
			record: 'cjamstva',
			id: 'uq_id',
			totalRecords: 'totalcount'
		}, [{
			name: 'ci_prij',
			mapping: 'ci_prij'
		}, 'ci_odr', {
			name: 'datum',
			mapping: 'datum',
			type: 'date',
			dateFormat: 'Y-m-d'
		}, 'osiguranje', 'car_br_jcd', 'roba', 'brutto', 'vr_ro_do', 'izngardavu', {
			name: 'datum_razd',
			mapping: 'datum_razd',
			type: 'date',
			dateFormat: 'Y-m-d'
		}])
	});
	store.setDefaultSort('datum', 'DESC');
	store.load({
		params: {
			start: 0,
			limit: ps
		}
	});
	
	var cm = new Ext.grid.ColumnModel([{
		header: "CI prijave",
		width: 60,
		dataIndex: 'ci_prij',
		sortable: true
	}, {
		header: "CI odredišta",
		width: 60,
		dataIndex: 'ci_odr',
		sortable: true
	}, {
		header: "Datum",
		width: 80,
		dataIndex: 'datum',
		renderer: Ext.util.Format.dateRenderer('d.m.Y'),
		sortable: true
	}, {
		header: "Osiguranje",
		width: 160,
		dataIndex: 'osiguranje',
		sortable: true
	}, {
		header: "Broj JCD-a",
		width: 160,
		dataIndex: 'car_br_jcd',
		sortable: true
	}, {
		header: "Opis robe",
		width: 220,
		dataIndex: 'roba',
		sortable: true
	}, {
		header: "Brutto (kg)",
		width: 60,
		dataIndex: 'brutto',
		sortable: true
	}, {
		header: "Vrijednost robe (Kn)",
		width: 60,
		dataIndex: 'vr_ro_do',
		sortable: true
	}, {
		header: "Iznos mogućeg duga",
		width: 100,
		dataIndex: 'izngardavu',
		sortable: true
	}, {
		header: "Datum razduženja",
		width: 80,
		dataIndex: 'datum_razd',
		renderer: Ext.util.Format.dateRenderer('d.m.Y'),
		sortable: true
	}]);
	
	
	
	var bbar = new Ext.PagingToolbar({
		pageSize: ps,
		store: store,
		displayInfo: true,
		displayMsg: '        Zapisi {0} - {1}         od {2}',
		emptyMsg: "Nema podataka         ",
		items:[
                '-', {
                pressed: false,
                enableToggle:false,
                text: 'Pregled za ispis',
                cls: 'x-btn-text-icon details',
                handler: previewPage
            }]
	});
	

	
	var filterMenuItems = ['<b class="menu-title">Filtriranje po koloni</b>', new Ext.menu.CheckItem({
		text: 'CI prijave',
		checked: true,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'CI odredišta',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Datum',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Osiguranje',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Broj JCD-a',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Opis robe',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Brutto (kg)',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Vrijednost robe (Kn)',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Iznos mogućeg duga',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Datum razduženja',
		checked: false,
		group: 'filter'
	})];
	
	var filterMenuItemsColumns = ['', 'ci_prij', 'ci_odr', 'datum', 'osiguranje', 'car_br_jcd', 'roba', 'brutto', 'vr_ro_do', 'izngardavu', 'datum_razd']
	
	var filterMenu = new Ext.menu.Menu({
		id: 'filterMenu',
		items: filterMenuItems
	});
	
	var filterStore = new Ext.data.SimpleStore({
		fields: ['query'],
		data: []
	});
	//filterStore.loadData([{'pero'}]);
	
	var quickMenuItems = ['<b class="menu-title">Brzo traženje po kolonama</b>', new Ext.menu.CheckItem({
		text: 'CI prijave',
		checked: true,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'CI odredišta',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Datum',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Osiguranje',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Broj JCD-a',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Opis robe',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Brutto (kg)',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Vrijednost robe (Kn)',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Iznos mogućeg duga',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Datum razduženja',
		checked: false,
		hideOnClick: false
	})];
	
	var quickMenuItemsColumns = ['', 'ci_prij', 'ci_odr', 'datum', 'osiguranje', 'car_br_jcd', 'roba', 'brutto', 'vr_ro_do', 'izngardavu', 'datum_razd']
	
	var quickMenu = new Ext.menu.Menu({
		id: 'quickMenu',
		items: quickMenuItems
	});
	
	
	
	var tbar = new Ext.Toolbar(['-']);
	
	
	
	// create the grid
	var grid = new Ext.grid.GridPanel({
		store: store,
		cm: cm,
		width: 900,
		height: 400,
		tbar: tbar,
		bbar: bbar
	});
	
		function previewPage(btn, pressed){
        var wp = window.location.host;
		var w = window.open();
		var d = w.document; 
		var gv=grid.getView();
		var rc=grid.getStore().getCount();
		var gr={}
		var gc={}
		d.open();
		d.write('<link rel="stylesheet" type="text/css" href="'+'../../kontrolnikr/css/ext-all.css"/>');
		d.write('<table>');
		gr =gv.getRow(0).childNodes;
		d.write('<thead>');
		var gh =grid.getColumnModel();
		var ghl =gh.getColumnCount();
		d.write('<td></td>');
		for (var i = 0; i < ghl; i++) {
			d.write('<td>'+gv.getHeaderCell(i).innerHTML+'</td>');
		}
		d.write('</thead>');
		d.write('<tbody>');
		for (var j = 0; j < rc; j++) {
			d.write('<tr>');
			gr =gv.getRow(j).childNodes;
		for (var i = 0; i < gr.length; i++) {
			d.write('<td>'+gr[i].childNodes[0].firstChild.innerHTML+'</td>');
		}
			d.write('</tr>');
		}
		d.write('</tbody>');
		d.write('</table>');	
		d.close()
    }
	
	var window1 = new Ext.Window({
		title: 'Pregled izdanih jamstava',
		width: 950,
		height: 450,
		minWidth: 300,
		minHeight: 250,
		layout: 'fit',
		plain: true,
		bodyStyle: 'padding:5px;',
		buttonAlign: 'center',
		items: grid
	});
	
	
	
	window1.show();
	// ovi elementi se moraju definirati poslije renderiranja prozora u kojem se prikazuju
	
	tbar.add({
		text: 'Filter',
		tooltip: 'Filtrira podatke koji se šalju sa servera.',
		icon: '/static/m.png',
		cls: 'x-btn-text-icon btn-search-icon',
		menu: filterMenu
	});
	
	var ssFilterBox = new Ext.form.TextField({
		emptyText: "",
		//	triggerAction: "query",
		//	typeAhead: false,
		mode: 'local',
		//dummyData: true,
		//store: filterStore,
		//type: 'text',
		size: 60,
		//value: '',
		style: 'background: #F0F0F9;'
	});
	
	tbar.add(ssFilterBox);
	
	tbar.addDom({
		tag: 'div',
		id: 'ssfilterlabel'
	});
	
	tbar.addSeparator();
	tbar.add({
		text: 'Brzo traženje',
		tooltip: 'Brzo traženje po podacima unutar strane.',
		icon: '/static/m.png',
		cls: 'x-btn-text-icon btn-search-icon',
		menu: quickMenu
	});
	
	/*	
	 var searchBox =new Ext.form.ComboBox({
	 hideTrigger: true,
	 size: 30,
	 mode:'local',
	 emptyText: "Type to quicksearch",
	 //rememberOn: 'all'
	 rememberOn: 'delay',
	 style: 'background: #F0F0F9;'
	 }) ;
	 */
	var searchBox = new Ext.form.TextField({
		hideTrigger: true,
		size: 60,
		mode: 'local',
		emptyText: "",
		//rememberOn: 'all'
		rememberOn: 'delay',
		style: 'background: #F0F0F9;'
	});
	tbar.add(searchBox);
	
	
	var searchRec = Ext.data.Record.create([{
		name: 'query',
		type: 'string'
	}]);
	
	var onFilteringBeforeQuery = function(e){
		//grid.getSelectionModel().clearSelections();
		var value = searchBox.getValue();
		if (value.length == 0) {
			store.clearFilter();
		}
		else {
			value = value.replace(/^\s+|\s+$/g, "");
			if (value == "") 
				return;
			store.filterBy(function(r){
				// filter operator AND on all keywords for defined columns
				valueArr = value.split(/\ +/);
				for (var j = 0; j < valueArr.length; j++) {
					re = new RegExp(Ext.escapeRe(valueArr[j]), "i");
					keep = false;
					for (var i = 0, items = quickMenuItems, len = items.length, itemsColumns = quickMenuItemsColumns; i < len; i++) {
						if (items[i].checked) {
							if (re.test(r.data[itemsColumns[i].toLowerCase()]) == true) {
								keep = true;
							}
						}
					}
					if (!keep) {
						return false;
					}
				}
				return true;
			});
		}
		
	};
	
	
	var setSSFilter = function(e){
		var filterCol = ''
		for (var i = 0, items = filterMenuItems, len = items.length, itemsColumns = filterMenuItemsColumns; i < len; i++) {
			if (items[i].checked) {
				filterCol = itemsColumns[i].toLowerCase()
				break
			}
		}
		
		var value = ssFilterBox.getValue();
		if ((!value || value == '') && !store.baseParams['fvalue']) {
			//return;
		}
		else 
			if (value.length > 0) {
				store.baseParams = {
					scope: 'jamstvo',
					action: 'getizdana',
					"fcolumn": filterCol,
					"fvalue": value
				};
				//alert("scope: 'jamstvo',action: 'getizdana','fcolumn'" + filterCol + "fvalue" + value);
			//Ext.get('ssfilterlabel').update("- filter on "+value);
			}
			else {
				store.baseParams = {
					scope: 'jamstvo',
					action: 'getizdana'
				};
			// Ext.get('ssfilterlabel').update("");
			}
		//alert("scope: 'jamstvo',action: 'getizdana','filter_col'" + filterCol + "filter_name" + value);	
		bbar.cursor = 0; // reset cursor on new filter
		store.load({
			params: {
				start: bbar.cursor,
				limit: bbar.pageSize
			}
		});
	};
	
	
	quickMenu.on('click', onFilteringBeforeQuery);
	
	//searchBox.on("change", onFilteringBeforeQuery);
	searchBox.on("valid", onFilteringBeforeQuery);
	filterMenu.on('click', setSSFilter);
	ssFilterBox.on("valid",setSSFilter);
	//ssFilterBox.on("change",setSSFilter);
}
 /*
    ssFilterBox.on("valueChange", function(e) {
	var filterCol = filterMenuItems.filter(function(element, index, array) {
	    return element.checked;
	})[0].text;
	var value = ssFilterBox.getValue();
	if ((!value || value=='') && !store.baseParams['filter_name']) {
	    return;
	} else if (value.length>0) {
	    store.baseParams = {scope: 'jamstvo',action: 'getizdana',"filter_col":filterCol,"filter_name":value};
	    //Ext.get('ssfilterlabel').update("- filter on "+value);
	} else {
	    store.baseParams = {scope: 'jamstvo',action: 'getizdana'};
	   // Ext.get('ssfilterlabel').update("");
	}
	bbar.cursor = 0; // reset cursor on new filter
	store.load({params:{start: bbar.cursor, limit: bbar.pageSize}});
    });
	store.load({params:{start:0,limit:ps}});
}
*/

Zamfir.jamstvo.onPregledNerazdClick = function(item){
    var ps = 50;
	// create the Data Store
    var store = new Ext.data.Store({
    
		// load using HTTP
       // url: 'defaultxml.asp?scope=jamstvo&action=getactive',
        url: 'defaultxml.asp',
		baseParams: {
			scope: 'jamstvo',
			action: 'getactive'
		},
		remoteSort: true,
        // the return will be XML, so lets set up a reader
        reader: new Ext.data.XmlReader({
            // records will have an "cjamstva" tag
            record: 'cjamstva',
            id: 'uq_id',
            totalRecords: 'totalcount'
        }, [ // set up the fields mapping into the xml doc
        // The first needs mapping, the others are very basic
        {
            name: 'ci_prij',
            mapping: 'ci_prij'
        }, 'ci_odr', {
			name:'datum',
			mapping:'datum',
			type: 'date', 
			dateFormat: 'Y-m-d'
		}, 'osiguranje', 'car_br_jcd', 'brutto', 'vr_ro_do', 'roba', 'izngardavu', {
			name:'datum_razd',
			mapping:'datum_razd',
			type: 'date', 
			dateFormat: 'Y-m-d'
		}])
    
    });
  	store.setDefaultSort('datum', 'DESC');
	store.load({
		params: {
			start: 0,
			limit: ps
		}
	});
	var cm = new Ext.grid.ColumnModel([{
		header: "CI prijave",
		width: 60,
		dataIndex: 'ci_prij',
		sortable: true
	}, {
		header: "CI odredišta",
		width: 60,
		dataIndex: 'ci_odr',
		sortable: true
	}, {
		header: "Datum",
		width: 80,
		dataIndex: 'datum',
		renderer: Ext.util.Format.dateRenderer('d.m.Y'),
		sortable: true
	}, {
		header: "Osiguranje",
		width: 160,
		dataIndex: 'osiguranje',
		sortable: true
	}, {
		header: "Broj JCD-a",
		width: 160,
		dataIndex: 'car_br_jcd',
		sortable: true
	}, {
		header: "Opis robe",
		width: 220,
		dataIndex: 'roba',
		sortable: true
	}, {
		header: "Brutto (kg)",
		width: 60,
		dataIndex: 'brutto',
		sortable: true
	}, {
		header: "Vrijednost robe (Kn)",
		width: 60,
		dataIndex: 'vr_ro_do',
		sortable: true
	}, {
		header: "Iznos mogućeg duga",
		width: 100,
		dataIndex: 'izngardavu',
		sortable: true
	}, {
		header: "Datum razduženja",
		width: 80,
		dataIndex: 'datum_razd',
		renderer: Ext.util.Format.dateRenderer('d.m.Y'),
		sortable: true
	}]);
	
	
	
	var bbar = new Ext.PagingToolbar({
		pageSize: ps,
		store: store,
		displayInfo: true,
		displayMsg: '        Zapisi {0} - {1}         od {2}',
		emptyMsg: "Nema podataka         ",
		items:[
                '-', {
                pressed: false,
                enableToggle:false,
                text: 'Pregled za ispis',
                cls: 'x-btn-text-icon details',
                handler: previewPage
            }]
	});
	

	
	var filterMenuItems = ['<b class="menu-title">Filtriranje po koloni</b>', new Ext.menu.CheckItem({
		text: 'CI prijave',
		checked: true,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'CI odredišta',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Datum',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Osiguranje',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Broj JCD-a',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Opis robe',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Brutto (kg)',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Vrijednost robe (Kn)',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Iznos mogućeg duga',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Datum razduženja',
		checked: false,
		group: 'filter'
	})];
	
	var filterMenuItemsColumns = ['', 'ci_prij', 'ci_odr', 'datum', 'osiguranje', 'car_br_jcd', 'roba', 'brutto', 'vr_ro_do', 'izngardavu', 'datum_razd']
	
	var filterMenu = new Ext.menu.Menu({
		id: 'filterMenu',
		items: filterMenuItems
	});
	
	var filterStore = new Ext.data.SimpleStore({
		fields: ['query'],
		data: []
	});
	//filterStore.loadData([{'pero'}]);
	
	var quickMenuItems = ['<b class="menu-title">Brzo traženje po kolonama</b>', new Ext.menu.CheckItem({
		text: 'CI prijave',
		checked: true,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'CI odredišta',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Datum',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Osiguranje',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Broj JCD-a',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Opis robe',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Brutto (kg)',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Vrijednost robe (Kn)',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Iznos mogućeg duga',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Datum razduženja',
		checked: false,
		hideOnClick: false
	})];
	
	var quickMenuItemsColumns = ['', 'ci_prij', 'ci_odr', 'datum', 'osiguranje', 'car_br_jcd', 'roba', 'brutto', 'vr_ro_do', 'izngardavu', 'datum_razd']
	
	var quickMenu = new Ext.menu.Menu({
		id: 'quickMenu',
		items: quickMenuItems
	});
	
	
	
	var tbar = new Ext.Toolbar(['-']);
	
	
	  
 	// create the grid
	var grid = new Ext.grid.GridPanel({
		store: store,
		cm: cm,
		width: 900,
		height: 400,
		tbar: tbar,
		bbar: bbar
	});
	function previewPage(btn, pressed){
        var wp = window.location.host;
		var w = window.open();
		var d = w.document; 
		var gv=grid.getView();
		var rc=grid.getStore().getCount();
		var gr={}
		var gc={}
		d.open();
		d.write('<link rel="stylesheet" type="text/css" href="'+'../../kontrolnikr/css/ext-all.css"/>');
		d.write('<table>');
		gr =gv.getRow(0).childNodes;
		d.write('<thead>');
		var gh =grid.getColumnModel();
		var ghl =gh.getColumnCount();
		d.write('<td></td>');
		for (var i = 0; i < ghl; i++) {
			d.write('<td>'+gv.getHeaderCell(i).innerHTML+'</td>');
		}
		d.write('</thead>');
		d.write('<tbody>');
		for (var j = 0; j < rc; j++) {
			d.write('<tr>');
			gr =gv.getRow(j).childNodes;
		for (var i = 0; i < gr.length; i++) {
			d.write('<td>'+gr[i].childNodes[0].firstChild.innerHTML+'</td>');
		}
			d.write('</tr>');
		}
		d.write('</tbody>');
		d.write('</table>');	
		d.close()
    }
    
    var window1 = new Ext.Window({
        title: 'Pregled nerazduženih jamstava',
        width: 950,
        height: 450,
        minWidth: 300,
        minHeight: 250,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: grid
    });
    
 	window1.show();
	// ovi elementi se moraju definirati poslije renderiranja prozora u kojem se prikazuju
	
	tbar.add({
		text: 'Filter',
		tooltip: 'Filtrira podatke koji se šalju sa servera.',
		icon: '/static/m.png',
		cls: 'x-btn-text-icon btn-search-icon',
		menu: filterMenu
	});
	
	var ssFilterBox = new Ext.form.TextField({
		emptyText: "",
		//	triggerAction: "query",
		//	typeAhead: false,
		mode: 'local',
		//dummyData: true,
		//store: filterStore,
		//type: 'text',
		size: 60,
		//value: '',
		style: 'background: #F0F0F9;'
	});
	
	tbar.add(ssFilterBox);
	
	tbar.addDom({
		tag: 'div',
		id: 'ssfilterlabel'
	});
	
	tbar.addSeparator();
	tbar.add({
		text: 'Brzo traženje',
		tooltip: 'Brzo traženje po podacima unutar strane.',
		icon: '/static/m.png',
		cls: 'x-btn-text-icon btn-search-icon',
		menu: quickMenu
	});
	
	/*	
	 var searchBox =new Ext.form.ComboBox({
	 hideTrigger: true,
	 size: 30,
	 mode:'local',
	 emptyText: "Type to quicksearch",
	 //rememberOn: 'all'
	 rememberOn: 'delay',
	 style: 'background: #F0F0F9;'
	 }) ;
	 */
	var searchBox = new Ext.form.TextField({
		hideTrigger: true,
		size: 60,
		mode: 'local',
		emptyText: "",
		//rememberOn: 'all'
		rememberOn: 'delay',
		style: 'background: #F0F0F9;'
	});
	tbar.add(searchBox);
	
	
	var searchRec = Ext.data.Record.create([{
		name: 'query',
		type: 'string'
	}]);
	
	var onFilteringBeforeQuery = function(e){
		//grid.getSelectionModel().clearSelections();
		var value = searchBox.getValue();
		if (value.length == 0) {
			store.clearFilter();
		}
		else {
			value = value.replace(/^\s+|\s+$/g, "");
			if (value == "") 
				return;
			store.filterBy(function(r){
				// filter operator AND on all keywords for defined columns
				valueArr = value.split(/\ +/);
				for (var j = 0; j < valueArr.length; j++) {
					re = new RegExp(Ext.escapeRe(valueArr[j]), "i");
					keep = false;
					for (var i = 0, items = quickMenuItems, len = items.length, itemsColumns = quickMenuItemsColumns; i < len; i++) {
						if (items[i].checked) {
							if (re.test(r.data[itemsColumns[i].toLowerCase()]) == true) {
								keep = true;
							}
						}
					}
					if (!keep) {
						return false;
					}
				}
				return true;
			});
		}
		
	};
	
	
	var setSSFilter = function(e){
		var filterCol = ''
		for (var i = 0, items = filterMenuItems, len = items.length, itemsColumns = filterMenuItemsColumns; i < len; i++) {
			if (items[i].checked) {
				filterCol = itemsColumns[i].toLowerCase()
				break
			}
		}
		
		var value = ssFilterBox.getValue();
		if ((!value || value == '') && !store.baseParams['fvalue']) {
			//return;
		}
		else 
			if (value.length > 0) {
				store.baseParams = {
					scope: 'jamstvo',
					action: 'getactive',
					"fcolumn": filterCol,
					"fvalue": value
				};
				//alert("scope: 'jamstvo',action: 'getizdana','fcolumn'" + filterCol + "fvalue" + value);
			//Ext.get('ssfilterlabel').update("- filter on "+value);
			}
			else {
				store.baseParams = {
					scope: 'jamstvo',
					action: 'getactive'
				};
			// Ext.get('ssfilterlabel').update("");
			}
		//alert("scope: 'jamstvo',action: 'getizdana','filter_col'" + filterCol + "filter_name" + value);	
		bbar.cursor = 0; // reset cursor on new filter
		store.load({
			params: {
				start: bbar.cursor,
				limit: bbar.pageSize
			}
		});
	};
	
	
	quickMenu.on('click', onFilteringBeforeQuery);
	
	//searchBox.on("change", onFilteringBeforeQuery);
	searchBox.on("valid", onFilteringBeforeQuery);
	filterMenu.on('click', setSSFilter);
	ssFilterBox.on("valid",setSSFilter);
	//ssFilterBox.on("change",setSSFilter);
}


Zamfir.osiguranje = {}


/*
 Zamfir.jamstvo.unos=false
 Zamfir.jamstvo.brisanje=false
 Zamfir.jamstvo.storno=false
 Zamfir.osiguranje.unos=false
 Zamfir.osiguranje.brisanje=false
 Zamfir.osiguranje.storno=false
 */
Zamfir.osiguranje.onOsiguranjeUnosClick = function(item){

    var simple = new Ext.FormPanel({
        labelWidth: 135, // label settings here cascade unless overridden
        labelAlign: 'right',
        frame: true,
        bodyStyle: 'padding:5px 5px 0',
        width: 500,
        autoHeight: true,
        //defaults: {
        //	width: 250
        //},
        defaultType: 'textfield',
        
        // configure how to read the XML Data
        waitMsgTarget: true,
        
        // configure how to read the XML Data
        // reusable eror reader class defined at the end of this file
        errorReader: new Ext.data.XmlReader({
            record: 'field',
            success: '@success'
        }, ['id', 'msg']),
        
        items: [{
            fieldLabel: 'Osiguranje',
            name: 'osiguranje',
            maxLength: 31,
            allowBlank: false,
            width: 200,
            autoHeight: true,
            invalidText: 'Obavezan unos oznake osiguranja u obliku 11002/broj/godina/tip'
        }, {
            fieldLabel: 'Referentni iznos',
            name: 'refiznos',
            maxLength: 15,
            width: 150,
            autoHeight: true,
            allowBlank: false
        }],
        
        buttons: [{
            text: 'Snimi',
            handler: function(){
                simple.getForm().submit({
                    url: 'defaultxml.asp',
                    params: {
                        scope: 'osiguranje',
                        action: 'unos',
                        returnformat: 'xml'
                    },
                    waitMsg: 'Snimam...',
                    success: function(form, action){
                        alert('Snimanje uspješno');
                        window1.close();
                    }
                    /*,
                     
                     failure :function(form, action) {
                     alert('Operacija odbijena : ' + action.failureType+'\n'+action.response.responseText);
                     }
                     */
                });
            }
        }, {
            text: 'Odustani',
            handler: function(){
                window1.close();
            }
        }]
    });
    
    
    
    var window1 = new Ext.Window({
        title: 'Unos/Ispravak podataka o osiguranju',
        width: 600,
        //height: 400,
        layout: 'fit',
        autoHeight: true,
        //autoWidth: true,
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: simple
    });
    window1.show();
}


Zamfir.osiguranje.onOsiguranjeBrisiClick = function(item){

    var simple = new Ext.FormPanel({
        labelWidth: 120, // label settings here cascade unless overridden
        frame: true,
        bodyStyle: 'padding:5px 5px 0',
        width: 350,
        labelAlign: 'right',
        defaultType: 'textfield',
        autoHeight: true,
        // configure how to read the XML Data
        waitMsgTarget: true,
        
        // configure how to read the XML Data
        // reusable eror reader class defined at the end of this file
        errorReader: new Ext.data.XmlReader({
            record: 'field',
            success: '@success'
        }, ['id', 'msg']),
        
        items: [{
            fieldLabel: 'Osiguranje',
            name: 'osiguranje',
            maxLength: 31,
            allowBlank: false,
            width: 200,
            autoHeight: true,
            invalidText: 'Obavezan unos oznake osiguranja u obliku 11002/broj/godina/tip'
        }],
        
        buttons: [{
            text: 'Snimi',
            handler: function(){
                simple.getForm().submit({
                    url: 'defaultxml.asp',
                    params: {
                        scope: 'osiguranje',
                        action: 'brisi',
                        returnformat: 'xml'
                    },
                    waitMsg: 'Brišem...',
                    success: function(form, action){
                        alert('Brisanje uspješno');
                        window1.close();
                    }
                    /*,
                     
                     failure :function(form, action) {
                     alert('Operacija odbijena : ' + action.failureType+'\n'+action.response.responseText);
                     }
                     */
                });
            }
        }, {
            text: 'Odustani',
            handler: function(){
                window1.close();
            }
        }]
    });
    
    // A reusable error reader class for XML forms
    
    
    var window1 = new Ext.Window({
        title: 'Brisanje osiguranja',
        width: 500,
        //height: 300,
        minWidth: 300,
        //minHeight: 100,
        autoHeight: true,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: simple
    });
    window1.show();
}
Zamfir.osiguranje.onPregledSveClick = function(item){

    // create the Data Store
    var store = new Ext.data.Store({
        // load using HTTP
        url: 'defaultxml.asp?scope=osiguranje&action=getall',
        
        // the return will be XML, so lets set up a reader
        reader: new Ext.data.XmlReader({
            // records will have an "cgarancij" tag
            record: 'cgarancij',
            id: 'uq_id',
            totalRecords: '@total'
        }, [ // set up the fields mapping into the xml doc
        // The first needs mapping, the others are very basic
        'osiguranje', 'refiznos'])
    
    });
    
    // create the grid
    var grid = new Ext.grid.GridPanel({
        store: store,
        columns: [{
            header: "Osiguranje",
            width: 160,
            dataIndex: 'osiguranje',
            sortable: true
        }, {
            header: "Referentni iznos",
            width: 100,
            dataIndex: 'refiznos',
            sortable: true
        }],
        width: 300,
        height: 400
    });
    
    var window1 = new Ext.Window({
        title: 'Pregled osiguranja',
        width: 350,
        height: 450,
        minWidth: 300,
        minHeight: 250,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: grid
    });
    
    store.load();
    window1.show();
}

Zamfir.osiguranje.onPregledStanjaClick = function(item){

    // create the Data Store
    var store = new Ext.data.Store({
        // load using HTTP
        url: 'defaultxml.asp?scope=osiguranje&action=getbalance',
        
        // the return will be XML, so lets set up a reader
        reader: new Ext.data.XmlReader({
            // records will have an "cgarancij" tag
            record: 'cgarancij',
            id: 'uq_id',
            totalRecords: '@total'
        }, [ // set up the fields mapping into the xml doc
        // The first needs mapping, the others are very basic
        'osiguranje', 'refiznos', 'stanje'])
    
    });
    
    // create the grid
    var grid = new Ext.grid.GridPanel({
        store: store,
        columns: [{
            header: "Osiguranje",
            width: 160,
            dataIndex: 'osiguranje',
            sortable: true
        }, {
            header: "Referentni iznos",
            width: 100,
            dataIndex: 'refiznos',
            sortable: true
        }, {
            header: "Stanje",
            width: 100,
            dataIndex: 'stanje',
            sortable: true
        }],
        width: 400,
        height: 400
    });
    
    var window1 = new Ext.Window({
        title: 'Pregled raspoloživih iznosa po osiguranju',
        width: 450,
        height: 450,
        minWidth: 300,
        minHeight: 250,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: grid
    });
    
    store.load();
    window1.show();
}
Zamfir.CURH = {}

Zamfir.CURH.onClick = function(item) {
	/*
	var upform = new Ext.ux.UploadForm2('form-ct-in', {
				url: 'upload.php',
				method: 'post',
				maxFileSize: 1048570,
				iconPath: '../../../icons',
				pgCfg: {
					uploadIdName: 'UPLOAD_IDENTIFIER',
					uploadIdValue: 'auto',
					progressBar: true,
					progressTarget: 'under',
					interval: 1000,
					maxPgErrors: 10,
					options: {
						url: 'progress.php',
						method: 'post'
					}
				}
			});


  var window1 = new Ext.Window({
        title: 'Pregled raspoloživih iznosa po osiguranju',
        width: 450,
        height: 450,
        minWidth: 300,
        minHeight: 250,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: upForm
    });
    

    window1.show();
*/
dialog = new Ext.ux.UploadDialog.Dialog({
   url: 'default.asp?action=upload2',
   base_params: {
        returnformat: 'json'
        },
  reset_on_hide: false,
  allow_close_on_upload: true,
  upload_autostart: false
});
dialog.show('show-button');
}				
				
Zamfir.CURH.onPregledNeupisanaClick = function(item){
    var ps = 50;
	// create the Data Store
    var store = new Ext.data.Store({
    
		// load using HTTP
        url: 'defaultxml.asp',
		baseParams: {
			scope: 'curh',
			action: 'getneupisana'
		},
		remoteSort: true,
        // the return will be XML, so lets set up a reader
        reader: new Ext.data.XmlReader({
            // records will have an "ccurhevi" tag
            record: 'ccurhevi',
            id: 'uq_id',
            totalRecords: 'totalcount'
        }, [ // set up the fields mapping into the xml doc
        // The first needs mapping, the others are very basic
        {
            name: 'ci_zad',
            mapping: 'ci_zad'
        }, 'ci_razd', {
			name:'dat_zad',
			mapping:'dat_zad',
			type: 'date', 
			dateFormat: 'Y-m-d'
		}, 'osiguranje', 'jcd_zad', {
			name:'dat_razd',
			mapping:'dat_razd',
			type: 'date', 
			dateFormat: 'Y-m-d'
		}, 'izn_zad','pozicija'])

    });
  	store.setDefaultSort('dat_zad', 'DESC');
	store.load({
		params: {
			start: 0,
			limit: ps
		}
	});
	var cm = new Ext.grid.ColumnModel([{
		header: "CI prijave",
		width: 60,
		dataIndex: 'ci_zad',
		sortable: true
	}, {
		header: "CI odredišta",
		width: 60,
		dataIndex: 'ci_razd',
		sortable: true
	}, {
		header: "Datum",
		width: 80,
		dataIndex: 'dat_zad',
		renderer: Ext.util.Format.dateRenderer('d.m.Y'),
		sortable: true
	}, {
		header: "Osiguranje",
		width: 160,
		dataIndex: 'osiguranje',
		sortable: true
	}, {
		header: "Broj JCD-a",
		width: 160,
		dataIndex: 'jcd_zad',
		sortable: true
	},  {
		header: "Datum razduženja",
		width: 80,
		dataIndex: 'dat_razd',
		renderer: Ext.util.Format.dateRenderer('d.m.Y'),
		sortable: true
	}, {
		header: "Iznos",
		width: 160,
		dataIndex: 'izn_zad',
		sortable: true
	}, {
		header: "Pozicija",
		width: 160,
		dataIndex: 'pozicija',
		sortable: true
	}]);
	
	
	
	var bbar = new Ext.PagingToolbar({
		pageSize: ps,
		store: store,
		displayInfo: true,
		displayMsg: '        Zapisi {0} - {1}         od {2}',
		emptyMsg: "Nema podataka         ",
		items:[
                '-', {
                pressed: false,
                enableToggle:false,
                text: 'Pregled za ispis',
                cls: 'x-btn-text-icon details',
                handler: previewPage
            }]
	});
	

	
	var filterMenuItems = ['<b class="menu-title">Filtriranje po koloni</b>', new Ext.menu.CheckItem({
		text: 'CI prijave',
		checked: true,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'CI odredišta',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Datum',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Osiguranje',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Broj JCD-a',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Datum razduženja',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Izn_zad',
		checked: false,
		group: 'filter'
	}), new Ext.menu.CheckItem({
		text: 'Pozicija',
		checked: false,
		group: 'filter'
	})];
	
	var filterMenuItemsColumns = ['', 'ci_zad', 'ci_razd', 'dat_zad', 'osiguranje', 'jcd_zad', 'dat_razd','izn_zad','pozicija']
	
	var filterMenu = new Ext.menu.Menu({
		id: 'filterMenu',
		items: filterMenuItems
	});
	
	var filterStore = new Ext.data.SimpleStore({
		fields: ['query'],
		data: []
	});
	//filterStore.loadData([{'pero'}]);
	
	var quickMenuItems = ['<b class="menu-title">Brzo traženje po kolonama</b>', new Ext.menu.CheckItem({
		text: 'CI prijave',
		checked: true,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'CI odredišta',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Datum',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Osiguranje',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Broj JCD-a',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Datum razduženja',
		checked: false,
		hideOnClick: false
	}), new Ext.menu.CheckItem({
		text: 'Pozicija',
		checked: false,
		hideOnClick: false
	})];
	
	var quickMenuItemsColumns = ['', 'ci_zad', 'ci_razd', 'dat_zad', 'osiguranje', 'jcd_zad', 'dat_razd','pozicija']
	
	var quickMenu = new Ext.menu.Menu({
		id: 'quickMenu',
		items: quickMenuItems
	});
	
	
	
	var tbar = new Ext.Toolbar(['-']);
	
	
	  
 	// create the grid
	var grid = new Ext.grid.GridPanel({
		store: store,
		cm: cm,
		width: 900,
		height: 400,
		tbar: tbar,
		bbar: bbar
	});
	function previewPage(btn, pressed){
        var wp = window.location.host;
		var w = window.open();
		var d = w.document; 
		var gv=grid.getView();
		var rc=grid.getStore().getCount();
		var gr={}
		var gc={}
		d.open();
		d.write('<link rel="stylesheet" type="text/css" href="'+'../../kontrolnikr/css/ext-all.css"/>');
		d.write('<table>');
		d.write('<thead>')
		var gh =grid.getColumnModel();
		var ghl =gh.getColumnCount();
		d.write('<td></td>');
		for (var i = 0; i < ghl; i++) {
			d.write('<td>'+gv.getHeaderCell(i).innerHTML+'</td>');
		}
		d.write('</thead>');
		d.write('<tbody>');
		gr =gv.getRow(0).childNodes;
		
		for (var j = 0; j < rc; j++) {
			d.write('<tr>');
			gr =gv.getRow(j).childNodes;
		for (var i = 0; i < gr.length; i++) {
			d.write('<td>'+gr[i].childNodes[0].firstChild.innerHTML+'</td>');
		}
			d.write('</tr>');
		}
		d.write('</tbody>')
		d.write('</table>');	
		d.close()
    }
    
    var window1 = new Ext.Window({
        title: 'Pregled neupisanih jamstava',
        width: 950,
        height: 450,
        minWidth: 300,
        minHeight: 250,
        layout: 'fit',
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: grid
    });
    
 	window1.show();
	// ovi elementi se moraju definirati poslije renderiranja prozora u kojem se prikazuju
	
	tbar.add({
		text: 'Filter',
		tooltip: 'Filtrira podatke koji se šalju sa servera.',
		icon: '/static/m.png',
		cls: 'x-btn-text-icon btn-search-icon',
		menu: filterMenu
	});
	
	var ssFilterBox = new Ext.form.TextField({
		emptyText: "",
		//	triggerAction: "query",
		//	typeAhead: false,
		mode: 'local',
		//dummyData: true,
		//store: filterStore,
		//type: 'text',
		size: 60,
		//value: '',
		style: 'background: #F0F0F9;'
	});
	
	tbar.add(ssFilterBox);
	
	tbar.addDom({
		tag: 'div',
		id: 'ssfilterlabel'
	});
	
	tbar.addSeparator();
	tbar.add({
		text: 'Brzo traženje',
		tooltip: 'Brzo traženje po podacima unutar strane.',
		icon: '/static/m.png',
		cls: 'x-btn-text-icon btn-search-icon',
		menu: quickMenu
	});
	
	/*	
	 var searchBox =new Ext.form.ComboBox({
	 hideTrigger: true,
	 size: 30,
	 mode:'local',
	 emptyText: "Type to quicksearch",
	 //rememberOn: 'all'
	 rememberOn: 'delay',
	 style: 'background: #F0F0F9;'
	 }) ;
	 */
	var searchBox = new Ext.form.TextField({
		hideTrigger: true,
		size: 60,
		mode: 'local',
		emptyText: "",
		//rememberOn: 'all'
		rememberOn: 'delay',
		style: 'background: #F0F0F9;'
	});
	tbar.add(searchBox);
	
	
	var searchRec = Ext.data.Record.create([{
		name: 'query',
		type: 'string'
	}]);
	
	var onFilteringBeforeQuery = function(e){
		//grid.getSelectionModel().clearSelections();
		var value = searchBox.getValue();
		if (value.length == 0) {
			store.clearFilter();
		}
		else {
			value = value.replace(/^\s+|\s+$/g, "");
			if (value == "") 
				return;
			store.filterBy(function(r){
				// filter operator AND on all keywords for defined columns
				valueArr = value.split(/\ +/);
				for (var j = 0; j < valueArr.length; j++) {
					re = new RegExp(Ext.escapeRe(valueArr[j]), "i");
					keep = false;
					for (var i = 0, items = quickMenuItems, len = items.length, itemsColumns = quickMenuItemsColumns; i < len; i++) {
						if (items[i].checked) {
							if (re.test(r.data[itemsColumns[i].toLowerCase()]) == true) {
								keep = true;
							}
						}
					}
					if (!keep) {
						return false;
					}
				}
				return true;
			});
		}
		
	};
	
	
	var setSSFilter = function(e){
		var filterCol = ''
		for (var i = 0, items = filterMenuItems, len = items.length, itemsColumns = filterMenuItemsColumns; i < len; i++) {
			if (items[i].checked) {
				filterCol = itemsColumns[i].toLowerCase()
				break
			}
		}
		
		var value = ssFilterBox.getValue();
		if ((!value || value == '') && !store.baseParams['fvalue']) {
			//return;
		}
		else 
			if (value.length > 0) {
				store.baseParams = {
					scope: 'curh',
					action: 'getneupisana',
					"fcolumn": filterCol,
					"fvalue": value
				};

			//Ext.get('ssfilterlabel').update("- filter on "+value);
			}
			else {
				store.baseParams = {
					scope: 'curh',
					action: 'getneupisana'
				};
			// Ext.get('ssfilterlabel').update("");
			}

		bbar.cursor = 0; // reset cursor on new filter
		store.load({
			params: {
				start: bbar.cursor,
				limit: bbar.pageSize
			}
		});
	};
	
	
	quickMenu.on('click', onFilteringBeforeQuery);
	

	searchBox.on("valid", onFilteringBeforeQuery);
	filterMenu.on('click', setSSFilter);
	ssFilterBox.on("valid",setSSFilter);

}		

Zamfir.izvjestaji = {}

Zamfir.izvjestaji.onPregledIzdanihClick = function(item){
	
	var data =[
        ['xml', 'XML '],
        ['xls', 'Excel - XLS '],
		['pdf', 'PDF ']
		] ;
		
	var store = new Ext.data.SimpleStore({
    	fields: ['format', 'desc'],
    	data : data
	});

	
	var simple = new Ext.FormPanel({
		labelWidth: 135, // label settings here cascade unless overridden
		labelAlign: 'right',
		frame: true,
		bodyStyle: 'padding:5px 5px 0',
		width: 500,
		autoHeight: true,
		
		defaultType: 'textfield',
		
		// configure how to read the XML Data
		waitMsgTarget: true,
		
		// configure how to read the XML Data
		// reusable eror reader class defined at the end of this file
		errorReader: new Ext.data.XmlReader({
			record: 'field',
			success: '@success'
		}, ['id', 'msg']),
		
		items: [{
			fieldLabel: 'Osiguranje',
			name: 'osiguranje',
			maxLength: 31,
			allowBlank: false,
			width: 200,
			autoHeight: true,
			invalidText: 'Obavezan unos oznake osiguranja u obliku 11002/broj/godina/tip/MB ili JMBG'
		}, new Ext.form.DateField({
			fieldLabel: 'Početni datum',
			name: 'startdate',
			format: 'd.m.Y',
			altFormats: 'dmY',
			allowBlank: true,
			autoHeight: true,
			autoWidth: true
		}), new Ext.form.DateField({
			fieldLabel: 'Završni datum',
			name: 'enddate',
			format: 'd.m.Y',
			altFormats: 'dmY',
			allowBlank: true,
			autoHeight: true,
			autoWidth: true
		}), new Ext.form.ComboBox({
    		fieldLabel: 'Format izvještaja',
			name: 'reportformat',
			store: store,
    		displayField:'format',
    		typeAhead: true,
    		mode: 'local',
    		triggerAction: 'all',
    		emptyText:'Odaberite format',
    		selectOnFocus:true,
			autoWidth: true
    		
		})
		],
		buttons: [{
			text: 'Kreiraj izvještaj',
			handler: function(){
				simple.getForm().submit({
					url: 'defaultxml.asp',
					params: {
						scope: 'jamstvo',
						action: 'getizdanaevi',
						returnformat: 'xml'
					},
					waitMsg: 'Kreiram izvjestaj ...',
					success: function(form, action){
						//alert('Snimanje uspjesno');
						previewPage(action.response.responseXML.getElementsByTagName("response")[0].getAttribute("url"));
						window1.close();
					}
					/*, failure :function(form, action) {
					 	alert('Operacija odbijena : ' + action.failureType+'\n'+action.response.responseText);
					 	}
					 */
				});
			}
		}, {
			text: 'Odustani',
			handler: function(){
				window1.close();
			}
		}]
	});
	
	
	function previewPage(url){
        var wp = window.location.host;
		var w = window.open(url);
		/*
		var d = w.document; 
		d.open();
		d.write('<a href="'+url+'">Otvori dokument</a>');
		d.close();
		*/
    }

	var window1 = new Ext.Window({
		title: 'Izdana provozna jamstva',
		width: 600,
		//height: 400,
		layout: 'fit',
		autoHeight: true,
		//autoWidth: true,
		plain: true,
		bodyStyle: 'padding:5px;',
		buttonAlign: 'center',
		items: simple
	});
	window1.show();
}

Zamfir.parametri = {}
Zamfir.parametri.onFirmaUnosClick = function(item){

    var simple = new Ext.FormPanel({
        labelWidth: 135, // label settings here cascade unless overridden
        labelAlign: 'right',
        frame: true,
        bodyStyle: 'padding:5px 5px 0',
        width: 500,
        autoHeight: true,
        //defaults: {
        //	width: 250
        //},
        defaultType: 'textfield',
        
        // configure how to read the XML Data
        waitMsgTarget: true,
        
        // configure how to read the XML Data
        // reusable eror reader class defined at the end of this file
        errorReader: new Ext.data.XmlReader({
            record: 'field',
            success: '@success'
        }, ['id', 'msg']),
        
        items: [{
            fieldLabel: 'Naziv',
            name: 'naziv',
            maxLength: 31,
            allowBlank: true,
            width: 200,
            autoHeight: true,
            invalidText: 'Obavezan unos naziva'
        },{
            fieldLabel: 'Adresa',
            name: 'adresa',
            maxLength: 31,
            allowBlank: true,
            width: 200,
            autoHeight: true,
            invalidText: 'Neispravni podaci'
        },{
            fieldLabel: 'Mjesto',
            name: 'mjesto',
            maxLength: 31,
            allowBlank: true,
            width: 200,
            autoHeight: true,
            invalidText: ''
        },{
            fieldLabel: 'Poštanski broj',
            name: 'postbr',
            maxLength: 5,
            allowBlank: true,
            autoWidth: true,
            autoHeight: true,
            invalidText: ''
        },{
            fieldLabel: 'Matični broj',
            name: 'matbr',
            maxLength: 13,
            allowBlank: true,
            //width: 200,
			autoWidth: true,
            autoHeight: true,
            invalidText: ''
        }
		],
        
        buttons: [{
            text: 'Snimi',
            handler: function(){
                f=simple.getForm()
				f.timeout=120
				f.submit({
                    url: 'defaultxml.asp',
                    params: {
                        scope: 'company',
                        action: 'unos',
                        returnformat: 'xml'
                    },
                    waitMsg: 'Snimam...',
                    success: function(form, action){
                        alert('Snimanje uspješno');
						window1.close();
                    }
                    /*,
                     
                     failure :function(form, action) {
                     alert('Operacija odbijena : ' + action.failureType+'\n'+action.response.responseText);
                     }
                     */
                });
            }
        }, {
            text: 'Odustani',
            handler: function(){
                window1.close();
            }
        }]
    });
    
    
    
    var window1 = new Ext.Window({
        title: 'Unos/Ispravak podataka o poduzeću',
        width: 600,
        //height: 400,
        layout: 'fit',
        autoHeight: true,
        //autoWidth: true,
        plain: true,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: simple
    });
    window1.show();
}
