﻿/// <reference path="ImageButton.js" />

Ext.onReady(function() {
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'qtip';

    var CarregaEstados = new Ext.data.SimpleStore({
        fields: ['Sigla', 'NomeEstado'],
        data: Ext.DataEstado.Estados
    });
    
    
    var FormContato = new Ext.form.FormPanel({
        labelWidth: 100,
        url: 'Contato.aspx',
        width: 480,
        border: false,
        frame: false,
        defaultType: 'textfield',
        renderTo: 'ContIntForm',
        bodyStyle: "background-color: transparent;",
        items: [
        

        {
            fieldLabel: '* Nome',
            name: 'Nome',
            allowBlank: false,
            width: 350,
            tabIndex: 10
        },
        
        {
            fieldLabel: '   Fazenda',
            name: 'Fazenda',
            width: 350,
            tabIndex: 11
        },

        {
            fieldLabel: '* Endereço',
            name: 'Endereco',
            allowBlank: false,
            width: 350,
            tabIndex: 12
        },

        {
            fieldLabel: '* Cidade',
            name: 'Cidade',
            allowBlank: false,
            width: 350,
            tabIndex: 13
        },


        // Combo Estados
         new Ext.form.ComboBox({
            store: CarregaEstados,
            fieldLabel: '  Estado',
            name: 'Estado',
            hiddenName: 'Estado',
            displayField: 'NomeEstado',
            valueField: 'NomeEstado',
            typeAhead: true, 
            mode: 'local',
            listWidth: 165,
            forceSelection: true,
            selectOnFocus: true,
            lazyRender: true,
            listClass: 'ajusta_lista',
            emptyText: 'Selecione um estado',
            tabIndex: 14
        }),

        {
            fieldLabel: '  Telefone',
            name: 'Telefone',
            width: 165,
            tabIndex: 15
        },

        {
            fieldLabel: '   Fax',
            name: 'Fax',
            width: 165,
            tabIndex: 16
        },

        {
            fieldLabel: '* E-mail',
            name: 'Email',
            allowBlank: false,
            vtype:'email',
            width: 350,
            tabIndex: 17
        },
        
        new Ext.form.TextArea({
            fieldLabel: '* Mensagem',
            name: 'Mensagem',
            allowBlank: false,
            width: 350,
            height: 100,
            tabIndex: 18
        })

    ],
        buttons:
        [
            {
                text: 'Limpar',
                tooltip: 'Limpar',
                tabIndex: 20,
                handler: function()
                {
                    FormContato.getForm().reset();
                }
            },
            {
                text: 'Enviar',
                tooltip: 'Enviar',
                tabIndex: 19,
            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();                            
                        } 
                        
                    }
                }
            	    );
            
            }
            }
        ]

    });

});