Bill.reg.FormPanel = Ext.extend(Ext.form.FormPanel, {
    initComponent: function() { 
        Ext.apply(this, {
            border: false,
            style: 'margin: 0px 10px 0px 10px; padding: 5px 5px 5px 5px;',  
            monitorValid: true,
            bbar: new Ext.ux.StatusBar({
                style: 'border: 0px; margin: 0px 15px 0px 15px;',
                hidden: true
            }),
            buttons: [{
                text: 'Зарегистрироваться',
                formBind: true,
                handler: this.tryReg,
                scope: this    
            },{
                xtype: 'bill-cancel-button',
                handler: this.cancel,
                scope: this
            }]   
        });
        Bill.reg.FormPanel.superclass.initComponent.apply(this, arguments); 
        this.regButton = this.buttons[0];
        this.statusBar = this.getBottomToolbar();
        this.form = this.getForm();
    },

    cancel: function() {
        window.close();
    },
    
    setStatus: function(msg) { 
        this.statusBar.show(); 
        this.statusBar.setStatus(msg);
    },    

    clear: function() {
        this.getForm().reset(); 
    },

    tryAuth: function() {
        var params = this.form.getValues();                  
        Server.bill.UserStat.auth(params, function(result, e) {    
            if (result.success) {
                window.location = 'http://infolada.ru/web/index.php';
            } else {
                window.location = 'http://infolada.ru/bis/session_err.php';
            }
        }, this);
    },
    
    tryReg: function() {
        var xtype = this.getXType();
        var clientType = xtype.split('-')[2];
        //console.log(clientType);
        var values = this.getForm().getValues();    
        Ext.apply(values, {clientType: clientType});
        //console.log(values);
        
        this.regButton.disable();
        this.statusBar.hide();         
        Server.bill.Client.create(values, function(result, e) {
            if (result.success) {
                Ext.Msg.show({
                    title: 'Сообщение',
                    msg: 'Вы успешно зарегистрировались!',
                    buttons: Ext.Msg.OK,
                    fn: this.tryAuth,
                    scope: this,
                    icon: Ext.MessageBox.INFO
                });        
            } else {
                this.spamFilter.reset();
                this.setStatus(result.msg);
            }
        }, this);
    }
});
Ext.reg('bill-reg-form-panel', Bill.reg.FormPanel);

