/*
 * Ext JS Library 2.2.1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

Ext.onReady(function(){

    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

      var top = new Ext.FormPanel({
        style:'border:2px solid #cccac9; margin:0 0 5px 0',
        labelAlign: 'top',
        frame:true,
        title: 'Contattaci - Inserisci i dati richiesti e invia il form',
        bodyStyle:'padding:5px 5px 0 0;',
        width: 428,
        url:'/about/contacts-form.php',
        items: [{
            layout:'column',
            items:[{
                columnWidth:.5,
                layout: 'form',
                items: [{
                    xtype:'textfield',
                    fieldLabel: 'Nome',
                    name: 'first',
                    anchor:'95%',
					tabIndex:1,
					vtype: 'alpha',
					allowBlank:false
                }, {
                    xtype:'textfield',
                    fieldLabel: 'Società',
                    name: 'company',
                    anchor:'95%',
					tabIndex:3
                }]
            },{
                columnWidth:.5,
                layout: 'form',
                items: [{
                    xtype:'textfield',
                    fieldLabel: 'Cognome',
                    name: 'last',
                    anchor:'95%',
					vtype: 'alpha',
					allowBlank:false,
					tabIndex:2
                },{
                    xtype:'textfield',
                    fieldLabel: 'Indirizzo Email',
                    name: 'email',
                    vtype:'email',
                    anchor:'95%',
					tabIndex:4,
                    vtype:'email',
					allowBlank:false
                }]
            }]
        },{
            xtype:'htmleditor',
            id:'bio',
            fieldLabel:'Messaggio da inviarci',
            height:87,
            anchor:'98%'
        }],

      buttons: [{
            text: 'Invia',			
			handler: function () {
				// when this button clicked, sumbit this form
				top.getForm().submit({
					waitMsg: 'Spedizione Messaggio...',		// Wait Message
					success: function () {		// When saving data success
						Ext.MessageBox.alert ('Messaggio','Il messaggio è stato inviato.');
						// clear the form
						simpleForm.getForm().reset();
					},
					failure: function () {		// when saving data failed
						Ext.MessageBox.alert ('Messaggio','Problemi riscontrati durante invio. Riprovare più tardi.');
					}
				});
			}
        },{
            text: 'Cancella',
			handler: function () {
				top.getForm().reset();
			}
        }]

    });

    top.render('simple-form');
});