blog2j.creaContactWindowConfig = function() {
	Ext.form.Field.prototype.msgTarget = 'side';
	var form = new Ext.form.FormPanel( {
		defaults : {
			anchor :'-20'
		},
		items : [ {
			fieldLabel :'Nome',
			name :'nome',
			allowBlank :false,
			xtype :'textfield'
		}, {
			fieldLabel :'Email',
			name :'email',
			allowBlank :false,
			vtype :'email',
			xtype :'textfield'
		}, {
			fieldLabel :'Soggetto',
			name :'soggetto',
			allowBlank :false,
			xtype :'textfield'
		}, {
			id :'contactHtml',
			region :'center',
			fieldLabel :'Testo',
			name :'testo',
			xtype :'htmleditor',
			allowBlank :false,
			hideLabel :true,
			anchor :'100% -76'
		} ]
	});
	form.addButton( {
		text :'Manda email',
		handler : function() {
			if (!form.getForm().isValid()) {
				Ext.MessageBox.alert('Dati non validi', "Controllare i dati inseriti");
				return;
			} else if (Ext.getCmp('contactHtml').getValue() == '') {
				Ext.MessageBox.alert('Dati non validi', "Inserire un testo della mail");
				return;
			}
			var errMsg = "Puoi contattare l'autore del blog all'indirizzo blog2j@gmail.com";
			form.getForm().submit( {
				url :'_s_e_n_d.php',
				waitMsg :'Invio email in corso',
				success : function(f, resp) {
					if (resp.response && resp.response.statusText == 'OK') {
						var r = Ext.decode(resp.response.responseText);
						if (r.success) {
							Ext.MessageBox.alert('Email spedita', 'Email inviata correttamente', function() {
								blog2j.contactWindow.close();
							});
						} else {
							Ext.MessageBox.alert('Errore invio email', r.error || errMsg);
						}
					} else {
						Ext.MessageBox.alert('Errore invio email', errMsg);
					}
				},
				failure : function(f, resp) {
					if (resp.response && resp.response.statusText == 'OK') {
						var r = Ext.decode(resp.response.responseText);
						Ext.MessageBox.alert('Errore invio email', r.error || errMsg);
					} else {
						Ext.MessageBox.alert('Errore invio email', errMsg);
					}
				}
			});
		}
	});
	return {
		id :'ContactModule-win',
		title :'Contatti',
		width :600,
		height :350,
		layout :'fit',
		items :form,
		iconCls :'contatti-icon',
		shim :false,
		animCollapse :false,
		constrainHeader :true,
		autoScroll :true,
		modal :true
	};
};

blog2j.showContactWindow = function() {
	if (!blog2j.contactWindow) {
		blog2j.contactWindow = new Ext.Window(blog2j.creaContactWindowConfig());
	}
	blog2j.contactWindow.show();
};