﻿/// <reference path="../extjs/adapter/ext/ext-base.js" />
/// <reference path="../extjs/ext-all-debug.js" />
Ext.QuickTips.init();

///
// Widgets
//////////////////////////////////////////////

///
// Functions
//////////////////////////////////////////////

Ext.onReady(function() {
    var login = new Ext.FormPanel({
        labelWidth: 80
        , url: 'Encuesta.ashx'
        , frame: true
        , title: 'Ingreso'
        , defaultType: 'textfield'
        , monitorValid: true
        , items: [
            {
                fieldLabel: 'Usuario'
                , name: 'loginUsuario'
                , allowBlank: false
            }
            , {
                fieldLabel: 'Contraseña'
                , name: 'loginContrasena'
                , inputType: 'password'
                , allowBlank: false
            }
            , {
                name: 'service'
                , inputType: 'hidden'
                , value: 'Login'
            }            
         ]
         , buttons: [
            {
                text: 'Entrar'
                , formBind: true
                , handler: function() {
                    login.getForm().submit({
                        method: 'POST'
                        , waitTitle: 'Conectando'
                        , waitMsg: 'Enviando datos...'
                        , success: function() {
                            var redirect = 'Encuesta.aspx';
                            window.location = redirect;                        
                        }
                        , failure: function(form, action) {
                            if (action.failureType == 'server') {
                                obj = Ext.util.JSON.decode(action.response.responseText);
                                Ext.Msg.alert('Entrada falló!', obj.errors.reason);
                            } else {
                                Ext.Msg.alert('Advertencia!', action.response.responseText);
                            }
                            login.getForm().reset();
                        }
                    });
                }
            }
         ]
    });

    new Ext.Viewport({
        layout: 'vbox'
        , layoutConfig: { align: 'center' }
        , cls: 'boddddy'
        , items: [
            { border: false, html: '<img src="Content/images/encabezado_enc2.jpg" />', width: 781, height: 106, flex: 0 }
        ]
        , listeners: {
            'show': function() {
                var win = new Ext.Window({
                    layout: 'fit',
                    width: 300,
                    height: 150,
                    closable: false,
                    resizable: false,
                    plain: true,
                    border: false,
                    items: [login]
                });
                win.show();
            }
        }
    }).show();

});
