﻿Ext.onReady(function() {
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'qtip';

    var txtPlanoEmpresa = new Ext.form.TextField({
        id: 'txtPlanoEmpresa',
        fieldLabel: '',
        emptyText: '',
        labelSeparator: '',
        width: 65,
        tabIndex: 31,
        anchor: '95%'
    });

    var txtContrato = new Ext.form.TextField({
        id: 'txtContrato',
        fieldLabel: '',
        emptyText: '',
        labelSeparator: '',
        width: 60,
        tabIndex: 32,
        anchor: '96%'
    });

    var txtDependente = new Ext.form.TextField({
        id: 'txtDependente',
        fieldLabel: '',
        labelSeparator: '',
        emptyText: '',
        width: 65,
        tabIndex: 33,
        anchor: '80%'
    });

    var txtDigitoVerificador = new Ext.form.TextField({
        id: 'txtDigitoVerificador',
        fieldLabel: '',
        labelSeparator: '',
        emptyText: '',
        width: 65,
        tabIndex: 33,
        anchor: '80%'
    });

    var FormSegudaVia = new Ext.form.FormPanel({
        id: 'FormSegudaVia',
        labelAlign: 'top',
        frame: false,
        border: false,
        bodyStyle: 'background-color:transparent;',
        renderTo: 'SegundaVia',
        buttonAlign: 'center',
        labelSeparator: '',
        fieldLabel: '',
        width: 174,
        bodyStyle: 'background-color:transparent;',
        items: [
            new Ext.form.Label({
                html: '<div style="text-align:left;">Número do Cartão</div>'
            }),
            {
                layout: 'column',
                border: false,
                bodyStyle: 'background-color:transparent;',
                items: [
                    { columnWidth: .4, border: false, layout: 'form', items: [txtPlanoEmpresa], bodyStyle: 'background-color:transparent;' },
                    { columnWidth: .6, border: false, layout: 'form', items: [txtContrato], bodyStyle: 'background-color:transparent;' }
                ]
            },
            new Ext.form.Label({
                html: '<div style="text-align:left;">Digito do Cartão</div>'
            }),
            {
                layout: 'column',
                border: false,
                bodyStyle: 'background-color:transparent;',
                items: [
                    { columnWidth: .3, border: false, layout: 'form', items: [txtDependente], bodyStyle: 'background-color:transparent;' },
                    { columnWidth: .3, border: false, layout: 'form', items: [txtDigitoVerificador], bodyStyle: 'background-color:transparent;' }
                ]
            },
            new Ext.form.Label({
                html: '<div style="text-align:left;">Opções</div>'
            }),
            new Ext.form.Radio({
                id: 'segunda_via',
                tabIndex: 34,
                name: 'rdg_principal',
                hideLabel: true,
                boxLabel: '2ª Via Boleto'
            }),
            new Ext.form.Radio({
                id: 'informe_rendimento',
                tabIndex: 35,
                name: 'rdg_principal',
                hideLabel: true,
                boxLabel: 'IR 2009'
            })  
        ],
        buttons: [
	        new Ext.Button({
	            id: 'enviarSegundaVia',
	            text: 'Entrar',
	            tooltip: 'Entrar',
	            tabIndex: 36,
	            renderTo: 'div_btn_segundavia',
	            minWidth: 40,
	            handler: function() {
	                var qryStr = '';
                    var cont = 0;

                    if (txtPlanoEmpresa.getValue() != undefined && txtPlanoEmpresa.getValue() != '') {
                        qryStr += 'txtPlanoEmpresa=' + txtPlanoEmpresa.getValue() + '&';
                        cont++;
                    }

                    if (txtContrato.getValue() != undefined && txtContrato.getValue() != '') {
                        qryStr += 'txtContrato=' + txtContrato.getValue() + '&';
                        cont++;
                    }

                    if (txtDependente.getValue() != undefined && txtDependente.getValue() != '') {
                        qryStr += 'txtDependente=' + txtDependente.getValue() + '&';
                        cont++;
                    }

                    if (txtDigitoVerificador.getValue() != undefined && txtDigitoVerificador.getValue() != '') {
                        qryStr += 'txtDigitoVerificador=' + txtDigitoVerificador.getValue();
                        cont++;
                    }
                    
                    if (cont == 4) {
                        if (Ext.getCmp('segunda_via').checked) {
                            window.location.href = 'BoletoLogin.aspx?' + qryStr.toString() + '&autentica_boleto=true&novo=true';
                        } else if (Ext.getCmp('informe_rendimento').checked) {
                            window.location.href = 'Rendimento.aspx?' + qryStr.toString();
                        }
                    } else {
                        Ext.Msg.alert('Bensaúde - Informação', 'Por favor, preencha todos os campos.');
                    }
	            }
	        })
	    ]
    });
});