﻿/// <reference path="ImageButton.js" />

Ext.onReady(function() {
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'qtip';
    
    var CarregaTipoNegoc = new Ext.data.SimpleStore({
        fields: ['ValorTipoNegoc', 'NomeTipoNegoc'],
        data: Ext.TipoNegoc.Tipos
    });
    
    var CarregaTipoImoveis = new Ext.data.SimpleStore({
        fields: ['ValorTipoImoveis', 'NomeTipoImoveis'],
        data: Ext.TipoImoveis.Tipos
    });

    var FormAvalie = new Ext.form.FormPanel({
        labelWidth: 100,
        url: 'Avalie_seu_imovel.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: 30
        },

        {
            fieldLabel: 'Telefone',
            name: 'Telefone',
            width: 165,
            tabIndex: 31
        },

        {
            fieldLabel: 'Celular',
            name: 'Celular',
            width: 165,
            tabIndex: 32
        },
        
        {
            fieldLabel: 'E-mail *',
            name: 'Email',
            allowBlank: false,
            vtype: 'email',
            width: 350,
            tabIndex: 33
        },
        new Ext.form.ComboBox({
            store: CarregaTipoImoveis,
            fieldLabel: 'Tipo de Imóvel *',
            name: 'TipoImovel',
            hiddenName: 'TipoImovel',
            displayField: 'NomeTipoImoveis',
            valueField: 'ValorTipoImoveis',
            typeAhead: true,
            mode: 'local',
            listWidth: 163,
            forceSelection: true,
            selectOnFocus: true,
            lazyRender: true,
            listClass: 'listPadrao',
            allowBlank: false,
            emptyText: 'Selecione',
            tabIndex: 34
        }),
        new Ext.form.ComboBox({
            store: CarregaTipoNegoc,
            fieldLabel: 'Tipo de Negociação *',
            name: 'TipoNegoc',
            hiddenName: 'TipoNegoc',
            displayField: 'NomeTipoNegoc',
            valueField: 'ValorTipoNegoc',
            typeAhead: true,
            mode: 'local',
            listWidth: 163,
            forceSelection: true,
            selectOnFocus: true,
            lazyRender: true,
            listClass: 'listPadrao',
            allowBlank: false,
            emptyText: 'Selecione',
            tabIndex: 35
        })

    ],
        buttons: [
            new Ext.ImageButton({
            text: 'LIMPAR',
            imgPath: '/img/btn_limpar.jpg',
            tooltip: 'LIMPAR',
            tabIndex: 37,
            handler: function() {
                FormAvalie.getForm().reset();
            }
        }),

            new Ext.ImageButton({
            text: 'ENVIAR',
            imgPath: '/img/btn_enviar.jpg',
            tooltip: 'ENVIAR',
            tabIndex: 36,
            handler: function() {
                FormAvalie.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') {
                                FormAvalie.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);
                            FormAvalie.getForm().reset();
                        }

                    }
                }
            	    );

            }

        })

            ]

    });

});