Ext.onReady(function() {
	var x = Ext.get('symbol_produktu');
	var fPanel = new Rodium.Shop.FindPanel({width : 300});
	var rPanel = new Ext.Panel({
		border : false
		,width : 400
	});
	
	var panel = new Ext.Panel({
		layout : 'column'
		,border : false
		,items : [fPanel,rPanel]
		,anchor : '100%'          
	});
	
	fPanel.addressCombo.on('select',function(combo, record, index) {
		rPanel.removeAll();
		if(!Ext.isEmpty(record.get('ca_phone'))) {
			rPanel.add({
				border : false
				,html : '<div style="border-bottom: #e1e1e1 solid 1px;margin-bottom:10px;"><p>tel: <span style="font-size:20px">' + record.get('ca_phone') + '</span></p></div>'
			});	
		}
		
		if(!Ext.isEmpty(record.get('ca_email'))) {
			var askForm = new Ext.form.FormPanel({
				border : false
				,labelAlign : 'top'
				,items : [{			
					layout : 'column'
					,border : false
					,items : [{
						xtype : 'hidden'
						,name : 'product_id'
						,value : Ext.get('symbol_produktu').dom.firstChild.data
					},{
						xtype : 'hidden'
						,name : 'ca_id'
						,value : record.get('ca_id')
					},{
						columnWidth : 0.5
						,border : false
						,layout : 'form'
						,bodyStyle : 'padding: 0px 5px 0px 0px'
						,items : {
							xtype : 'textfield'
							,fieldLabel : 'twój e-mail'
							,itemCls : 'x-form-item-required'
							,anchor : '100%'
							,name : 'email'
							,vtype : 'email'
							,allowBlank : false
						} 
					},{
						columnWidth : 0.5
						,layout : 'form'
						,border : false
						,bodyStyle : 'padding: 0px 0px 0px 5px'
						,items : {
							xtype : 'textfield'
							,fieldLabel : 'twój telefon'
							,anchor : '100%'
							,name : 'phone'
						}
					}]
				},{
					xtype : 'textfield'
					,fieldLabel : 'temat wiadomości'
					,value : 'Pytanie o przedmiot z kolekcji Rodium: ' + Ext.get('symbol_produktu').dom.firstChild.data
					,anchor : '100%'
					,name : 'subject'
					,itemCls : 'x-form-item-required'
					,allowBlank : false
				},{
					fieldLabel : 'treść wiadomości'
					,xtype : 'textarea'
					,height : 100
					,anchor : '100%'
					,value : 'Witam!\nProszę o kontakt w sprawie wyżej wymienionego produktu.\nPozdrowienia'
					,name : 'content'
				}]
				,butonAlign : 'center'
				,monitorValid: true
				,buttons : {
					text : 'Wyślij zapytanie'
					,formBind: true
					,handler : function() {
						this.ownerCt.ownerCt.getForm().submit({
							url : '/rodiumjson/askproduct'
							,scope : this
							,success : function() {

								this.ownerCt.ownerCt.ownerCt.remove(this.ownerCt.ownerCt);
								rPanel.add({
									border : false
									,html : '<p class="c"><strong>Twoja wiadomość została wysłana.</strong></p>'
								});
								rPanel.doLayout();
							}
							,failure : function() {
								Ext.Msg.show({
									title : 'Błąd podczas wysyłania wiadomości'
									,msg : 'Twoja wiadomość <strong>nie została</strong> wysłana.'
									,buttons : Ext.MessageBox.OK
									,icon : Ext.MessageBox.ERROR
									,modal : true
								})
							}
						});
					}
				}
			})
			rPanel.add(askForm);
		}
		
		rPanel.doLayout();
	});
	
	panel.render('ask_product');
});
