/*
 * Ext JS Library 2.2
 * Copyright(c) 2006-2008, 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 bd = Ext.getBody();

    /*
     * ================  Formuário de reserva  =======================
     */
    var simple = new Ext.FormPanel({
        labelWidth: 100, // label settings here cascade unless overridden
        url:'contato.php',
        frame:true,
        title: 'Formu&aacute;rio de contato',
        bodyStyle:'padding:5px 5px 0',
        width: 450,
        defaults: {width: 240},
        defaultType: 'textfield',

        items: [{
                fieldLabel: 'Nome',
                name: 'nome',
                allowBlank:false
            },{
                fieldLabel: 'Telefone',
                name: 'telefone'
            }, {
                fieldLabel: 'Email',
                name: 'email',
                vtype:'email'
            },new Ext.form.TextArea({
                fieldLabel: 'Mensagem',
                name: 'mensagem'
			})
        ],
		
		buttons: [{
			text: 'Enviar',
            handler: function() {
                if(simple.getForm().isValid()) {
	                simple.getForm().submit({
	                    url: 'contato.php',
	                    waitMsg: 'Enviando...',
						waitTitle: 'Espere por favor...',
	                    success: function(simple, o){
							Ext.MessageBox.alert('Sucesso', 'Mensagem enviada com sucesso!');
	                    },
	                    failure: function(simple, o){
							Ext.MessageBox.alert('Falha', 'Error ao enviar a mensagem, tente novamente!');
	                    }
	                });
                }
            }
        },{
			text: 'Limpar',
			handler: function() {
				simple.getForm().reset();
			}
        }]
    });

    simple.render('formularioContato');
    
});
