﻿/// <reference path="ImageButton.js" />

Ext.onReady(function() {
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'qtip';
    
    var FormContato = new Ext.form.FormPanel({
        labelWidth: 100,
        url: 'Fale_Conosco.aspx',
        width: 480,
        border: false,
        frame: false,
        defaultType: 'textfield',
        bodyStyle: "background-color: transparent;",
        renderTo: 'ContIntForm',
        items: [

        {
            fieldLabel: '* Nome',
            name: 'Nome',
            allowBlank: false,
            width: 350,
            tabIndex: 20
        },

        {
            fieldLabel: '* E-mail',
            name: 'Email',
            allowBlank: false,
            vtype: 'email',
            width: 350,
            tabIndex: 21
        },

        {
            fieldLabel: 'Telefone',
            name: 'Telefone',
            width: 165,
            tabIndex: 22
        },

        new Ext.form.TextArea({
            fieldLabel: '* Mensagem',
            name: 'Mensagem',
            allowBlank: false,
            width: 350,
            height: 200,
            tabIndex: 23
        })

    ],
        buttons: [
            new Ext.ImageButton({
            text: 'LIMPAR',
            imgPath: '/img/btn_limpar.jpg',
            tooltip: 'LIMPAR',
            tabIndex: 25,
            handler: function() {
                FormContato.getForm().reset();
            }
        }),

            new Ext.ImageButton({
            text: 'ENVIAR',
            imgPath: '/img/btn_enviar.jpg',
            tooltip: 'ENVIAR',
            tabIndex: 24,
            handler: function() {
                FormContato.getForm().submit({
                    method: 'POST',
                    waitTitle: 'Aguarde..',
                    waitMsg: 'Enviando informações...',
                    success: function() {
                        Ext.Msg.alert('Status', 'Mensagem Enviada com sucesso!', function(btn, text) {
                            if (btn == 'ok') {
                                FormContato.getForm().reset();
                            }
                        });
                    },
                    failure: function(form, action) {
                        if (action.failureType == 'server') {
                            obj = Ext.util.JSON.decode(action.response.responseText);
                            Ext.Msg.alert('Não foi posssivel enviar o e-mail!', obj.errors.reason);
                            FormContato.getForm().reset();
                        }

                    }
                }
            	    );
            }
        })
            ]
    });
});