Ext.onReady(function(){
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'side'; // pozicija ikone ob "fail" client side validaciji

	var dsStarost = new Ext.data.SimpleStore({
		fields: ['starost'],
		data: [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],
			[21],[22],[23],[24],[25],[26],[27],[28],[29],[30],[31],[32],[33],[34],[35],[36],[37],[38],[39],[40],
			[41],[42],[43],[44],[45],[46],[47],[48],[49],[50],[51],[52],[53],[54],[55],[56],[57],[58],[59],[60],
			[61],[62],[63],[64],[65],[66],[67],[68],[69],[70],[71],[72],[73],[74],[75],[76],[77],[78],[79],[80],
			[81],[82],[83],[84],[85],[86],[87],[88],[89],[90],[91],[92],[93],[94],[95],[96],[97],[98],[99]]
	});

	var dsPijaca = new Ext.data.SimpleStore({
		fields: ['pijaca'],
		data: [[0],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20]]
	});

    var anketaPunca = new Ext.FormPanel({
		id: 'anketaPunca',
        labelWidth: 100,
		onSubmit: Ext.emptyFn,
		resizable: false,
		closable: false,
        frame: true,
        title: 'PUNCE&nbsp;&nbsp;:&nbsp;&nbsp;Ena pijača = ena enota = 10 g alkohola = 0,25 litra piva ali 1 dcl vina ali 0,3 dcl žgane pijače',
        width: 602,
        defaultType: 'textfield',
        items: [{
			xtype: 'fieldset',
			labelAlign: 'left',
			border: true,
			title: 'Starost',
			labelWidth: 95,
			autoHeight: true,		
			items: [{
				id: Ext.id(),
				mode: 'local',
				labelStyle: 'text-align: right;',
				labelSeparator: '',
				name: 'starost',
				allowBlank: false,
				displayField: 'starost',
				xtype: 'combo',
				store: dsStarost,
				triggerAction: 'all',
				editable: true,
				blankText: 'Prosim, izberi svojo starost.',
				forceSelection: true,
				width: 50
			}]
		}, {
			xtype: 'fieldset',
			labelAlign: 'left',
			title: 'Status',
			border: true,
			labelWidth: 95,
			autoHeight: true,		
			items: [{
				xtype: 'radiogroup',
				title: 'Status',
				labelStyle: 'text-align: right;',
				labelSeparator: '',
				autoHeight: true,
				defaultType: 'radio',			
				allowBlank: false,
				width: 302,
				autoWidth: false,	
				columns: 1,
				items: [{
					id: Ext.id(),
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: 'Učenka',
					name: 'status',
					inputValue: 'Učenec'
				}, {
					id: Ext.id(),
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: 'Dijakinja',
					name: 'status',
					inputValue: 'Dijak'
				}, {
					id: Ext.id(),
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: 'Študentka',
					name: 'status',
					inputValue: 'Študent'
				}, {
					id: Ext.id(),
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: 'Zaposlena',
					name: 'status',
					inputValue: 'Zaposlen'
				}, {
					id: Ext.id(),
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: 'Drugo',
					name: 'status',
					inputValue: 'Drugo'
				}]
			}]
		}, {
			xtype: 'fieldset',
			labelAlign: 'left',
			border: true,
			labelWidth: 95,
			title: 'Anketo rešujem',
			autoHeight: true,		
			items: [{
				xtype: 'radiogroup',
				title: 'Anketo rešujem',
				labelStyle: 'text-align: right;',
				labelSeparator: '',
				autoHeight: true,
				defaultType: 'radio',			
				allowBlank: false,
				width: 302,
				autoWidth: false,	
				columns: 1,
				items: [{
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: 'Prvič',
					name: 'anketo_resujem',
					inputValue: 'Prvič'
				}, {
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: 'Sem že reševala',
					name: 'anketo_resujem',
					inputValue: 'Sem že reševal'
				}]
			}]
		}, {
			xtype: 'fieldset',
			labelAlign: 'left',
			border: true,
			title: 'Kaj meniš, kakšna naj bi bila primerna starost?',
			labelWidth: 260,
			autoHeight: true,		
			items: [{
				id: Ext.id(),
				mode: 'local',
				fieldLabel: 'Ob prvem uživanju alkoholnih pijač?',
				labelSeparator: '',
				name: 'prvo_uzivanje',
				allowBlank: false,
				displayField: 'starost',
				xtype: 'combo',
				store: dsStarost,
				triggerAction: 'all',
				editable: true,
				blankText: 'Prosim, izberi starost.',
				forceSelection: true,
				width: 50
			}, {
				id: Ext.id(),
				mode: 'local',
				fieldLabel: 'Ob prvi pijanosti (ko se prvič opiješ)?',
				labelSeparator: '',
				name: 'prva_opitost',
				allowBlank: false,
				displayField: 'starost',
				xtype: 'combo',
				store: dsStarost,
				triggerAction: 'all',
				editable: true,
				blankText: 'Prosim, izberi starost.',
				forceSelection: true,
				width: 50
			}, {
				id: Ext.id(),
				mode: 'local',
				fieldLabel: 'Ob začetku rednega uživanja alkoholnih pijač<br />(vsaj enkrat tedensko)?',
				labelSeparator: '',
				name: 'redno_pitje',
				allowBlank: false,
				displayField: 'starost',
				xtype: 'combo',
				store: dsStarost,
				triggerAction: 'all',
				editable: true,
				blankText: 'Prosim, izberi starost.',
				forceSelection: true,
				width: 50
			}]
		}, {
			xtype: 'fieldset',
			labelAlign: 'left',
			border: true,
			title: 'Kaj priporočaš vrstnikom?',
			labelWidth: 300,
			autoHeight: true,		
			items: [{
				id: Ext.id(),
				mode: 'local',
				fieldLabel: 'Da lahko ob koncu tedna popijejo [X] pijač na dan.',
				labelSeparator: '',
				name: 'pijac_konec_tedna',
				allowBlank: false,
				displayField: 'pijaca',
				xtype: 'combo',
				store: dsPijaca,
				triggerAction: 'all',
				editable: true,
				blankText: 'Prosim, izberi število pijač.',
				forceSelection: true,
				width: 50
			}, {
				id: Ext.id(),
				mode: 'local',
				fieldLabel: 'Da lahko v času pouka popijejo [X] pijač.',
				labelSeparator: '',
				name: 'pijac_med_poukom',
				allowBlank: false,
				displayField: 'pijaca',
				xtype: 'combo',
				store: dsPijaca,
				triggerAction: 'all',
				editable: true,
				blankText: 'Prosim, izberi število pijač.',
				forceSelection: true,
				width: 50
			}, {
				id: Ext.id(),
				mode: 'local',
				fieldLabel: 'Da lahko pred poljubljanjem popijejo [X] pijač.',
				labelSeparator: '',
				name: 'pijac_pred_poljubljanjem',
				allowBlank: false,
				displayField: 'pijaca',
				xtype: 'combo',
				store: dsPijaca,
				triggerAction: 'all',
				editable: true,
				blankText: 'Prosim, izberi število pijač.',
				forceSelection: true,
				width: 50
			}]
		}, {
			xtype: 'fieldset',
			labelAlign: 'left',
			border: true,
			labelWidth: 320,
			autoHeight: true,
			title: 'Izberi eno od možnosti',
			items: [{
				xtype: 'radiogroup',
				labelStyle: 'text-align: left; padding: 20px 30px 0 0;',
				autoHeight: true,
				defaultType: 'radio',			
				allowBlank: false,
				width: 217,
				autoWidth: false,
				fieldLabel: 'Kakšno je tveganje za prometno nezgodo v primerjavi s treznostjo, če pred vožnjo popiješ 7 ali 8 alkoholnih pijač?',
				columns: 1,
				items: [{
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '9 - krat večje',
					name: 'tveganje',
					inputValue: 'A'
				}, {
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '6 - krat večje',
					name: 'tveganje',
					inputValue: 'B'
				}, {
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: '3 - krat večje',
					name: 'tveganje',
					inputValue: 'C'
				}]
			}]
		}, {
			xtype: 'fieldset',
			labelAlign: 'left',
			border: true,
			labelWidth: 160,
			autoHeight: true,
			title: 'Možnih je več odgovorov',
			items: [{
				xtype: 'checkboxgroup',
				labelStyle: 'text-align: left; padding: 0px 30px 0 0;',
				autoHeight: true,
				defaultType: 'checkbox',			
				allowBlank: false,
				width: 377,
				autoWidth: false,
				fieldLabel: 'Če si ženska in tehtaš približno 60 kg, po kolikih alkoholnih pijačah boš imela v krvi več kot 0,5 gramov alkohola na kilogram krvi (0,5 promila)?',
				columns: 1,
				items: [{
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: 'Če v eni uri spijem dve mali pivi',
					name: 'nula_pet1',
					inputValue: 'A'
				}, {
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: 'Če v eni uri spijem tri decilitre vina',
					name: 'nula_pet2',
					inputValue: 'B'
				}, {
					fieldLabel: '',
					labelSeparator: '',
					boxLabel: 'Če v eni uri spijem tri žgane pijače po 0,3 dcl',
					name: 'nula_pet3',
					inputValue: 'C'
				}]
			}]
		}, {
			xtype: 'fieldset',
			labelAlign: 'right',
			border: true,
			title: 'Email',
			labelWidth: 95,
			autoHeight: 40,
			items: [{
				id: Ext.id(),
				labelStyle: 'text-align: right;',
				labelSeparator: '',
				name: 'email',
				xtype: 'textfield',
				vtype: 'email',
				vtypeText: 'Email mora biti oblike jasna@domena.com',
				blankText: 'Prosim, vpiši svoj email.',
				allowBlank: false,
				labelWidth: 95,
				width: 380
			}]
		}],
        buttons: [{
            text: 'Pošlji',
			handler: function(){
				if (anketaPunca.getForm().isValid()) {
					Ext.Ajax.request({
						url: 'modAnketaProcess.php',
						method: 'POST',
						success: function(response, options) {
							o = Ext.decode(response.responseText);
							Ext.Msg.alert('Obvestilo', o.Msg);
							anketaPunca.getForm().reset();
						},
						failure: function(form, action) {
							Ext.Msg.alert('Napaka', 'Pošiljanje ankete žal ni bilo uspešno.');
						},
						params: {
							spol: 'Punca', 
							starost: anketaPunca.getForm().findField('starost').getValue(), 
							status: Ext.DomQuery.selectValue('input[name=status]:checked/@value'), 
							anketo_resujem: Ext.DomQuery.selectValue('input[name=anketo_resujem]:checked/@value'), 
							prvo_uzivanje: anketaPunca.getForm().findField('prvo_uzivanje').getValue(), 
							prva_opitost: anketaPunca.getForm().findField('prva_opitost').getValue(), 
							redno_pitje: anketaPunca.getForm().findField('redno_pitje').getValue(), 
							pijac_konec_tedna: anketaPunca.getForm().findField('pijac_konec_tedna').getValue(), 
							pijac_med_poukom: anketaPunca.getForm().findField('pijac_med_poukom').getValue(), 
							pijac_pred_poljubljanjem: anketaPunca.getForm().findField('pijac_pred_poljubljanjem').getValue(),
							tveganje: Ext.DomQuery.selectValue('input[name=tveganje]:checked/@value'), 
							nula_pet1: Ext.DomQuery.selectValue('input[name=nula_pet1]:checked/@value'), 
							nula_pet2: Ext.DomQuery.selectValue('input[name=nula_pet2]:checked/@value'), 
							nula_pet3: Ext.DomQuery.selectValue('input[name=nula_pet3]:checked/@value'), 
							email: anketaPunca.getForm().findField('email').getValue()
						}
					});
				} else {
					Ext.Msg.alert('Napaka', 'Prosim, izpolni manjkajoče podatke.');
				} // if..else
            } // handler
        }, {
            text: 'Resetiraj',
			handler: function() {
				anketaPunca.getForm().reset();
			} // handler
        }]
    });
    anketaPunca.render(Ext.getDom('anketaPunceContainer'));
});
