Ext.onReady(function(){

    var win;
    var link = Ext.get('gmaps-link');

	var infoPanel = new Ext.Panel({
			region:'north',
            padding:10,
			height:90,
			bodyStyle:'text-align:left;',
			html:'<img src="img/contact-form.jpg" style="float:left; padding:0 5px; vertical-align:bottom;" />Poniżej proszę wpisać swoje dane teleadresowe i ewentualne pytania. Postaramy się odpowiedzieć na Państwa zapytanie tak szybko jak będzie to możliwe.'
        });


	 var requestForm = new Ext.FormPanel({
	
	 region:'center',
	 labelWidth: 100,
     //url:'save-form.php',
     frame:true,
	 labelAlign: 'top',
	 renderTo: 'contact-form',
     width: '100%',
     buttons: [{
         text:'Wyślij',
			handler: function(){
				requestForm.form.submit({
					url: 'request-send.php',
					method: 'POST',
					params: {
						action: 'new'
						//modify date
						//date_value1: getDateValue(Ext.get('date_start'), 'Ymd')
					},
					waitMsg: 'Wysyłanie...',
					success: function(form, action){
						        Ext.MessageBox.show({
								   title:'Kontakt',
								   msg: 'Wiadomość została wysłana!',
								   buttons: Ext.MessageBox.OK,
								   icon: Ext.MessageBox.INFO
							   });
							form.reset();
					},
					failure: function(form, action){
						        Ext.MessageBox.show({
								   title:'Kontakt',
								   msg: 'Wystąpił błąd podczas wysyłania wiadomości!',
								   buttons: Ext.MessageBox.OK,
								   icon: Ext.MessageBox.ERROR
							   });
					}
				});
		}


     }],
     items: [{
            layout:'column',
            items:[{
                columnWidth:.5,
                layout: 'form',
				labelSeparator:'&nbsp;',
                items: [{
                    xtype:'textfield',
					labelStyle: 'font-weight:bold;',
                    fieldLabel: 'Imię i nazwisko',
                    name: 'first_last',
					allowBlank:false,
                    anchor:'95%'
                }, {
                    xtype:'textfield',
                    fieldLabel: 'Firma',
                    name: 'company',
                    anchor:'95%'
                }]
            },{
                columnWidth:.5,
                layout: 'form',
				labelSeparator:'&nbsp;',
                items: [{
                    xtype:'textfield',
                    fieldLabel: 'Telefon kontaktowy',
					labelStyle: 'font-weight:bold;',
                    name: 'telephone',
					allowBlank:false,
                    anchor:'95%'
                },{
                    xtype:'textfield',
                    fieldLabel: 'Email',
					labelStyle: 'font-weight:bold;',
                    name: 'email',
                    vtype:'email',
					allowBlank:false,
                    anchor:'95%'
                }]
            }]
        },{
            xtype:'textarea',
            id:'query',
            height:200,
            anchor:'98%'
        }]
 

	 });

    link.on('click', function(){
        // create the window on the first click and reuse on subsequent clicks
        if(!win){
            win = new Ext.Window({
				layout: 'fit',
                title: 'Partner Travel - Lokalizacja',
                closeAction: 'hide',
                width:600,
                height:400,
                items: {
                    xtype: 'gmappanel',
                    region: 'center',
                    zoomLevel: 17,
                    gmapType: 'map',
                    mapConfOpts: ['enableScrollWheelZoom','enableDoubleClickZoom','enableDragging'],
                    mapControls: ['GSmallMapControl','GMapTypeControl','NonExistantControl'],
                    setCenter: {
                        geoCodeAddr: 'Krakowska 16, 33-100 Tarnów, Poland',
                        marker: {title: 'Partner Travel'}
                    }
                }

            });
        }
        win.show(this);
    });
    

});
