
var regFormConverted;

Ext.onReady(function() {

    regFormConverted = new Ext.form.BasicForm('regSubscriberForm');

    var subscribeNameConverted = new Ext.form.TextField({
                    applyTo: 'subscribeName',
                    name: 'subscribeName',
                    value: '',
                    emptyText: 'Name',
                    width: 180,
                    allowBlank: true,
                    blankText: 'Name: This field is required'
                });
    regFormConverted.add(subscribeNameConverted);

    var subscribeEmailConverted = new Ext.form.TextField({
                    applyTo: 'subscribeEmail',
                    name: 'subscribeEmail',
                    value: '',
                    vtype: 'email', emptyText: 'Email',
                    width: 180,
                    allowBlank: true,
                    blankText: 'Email address: This field is required'
                });
    regFormConverted.add(subscribeEmailConverted);

});


function sendSubscriber() {
    regFormConverted.submit({
        method: 'POST',
        waitTitle: 'Connecting',
        waitMsg: 'Sending data...',

        success: function(form, action) {
            // open new page that was created
            obj = Ext.util.JSON.decode(action.response.responseText);

            Ext.MessageBox.show({
                title: 'Registration',
                msg: 'You have received an activation message. Please go to your email and follow instruction to complete registration.',
                buttons: Ext.MessageBox.OK,
                icon: Ext.MessageBox.INFO,
                fn: function() {
                    window.location.href = redirectUrl;
                }
            });

        },

        failure: function(form, action) {

            switch (action.failureType) {
                case Ext.form.Action.CLIENT_INVALID:
                    Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values!');
                    break;
                case Ext.form.Action.CONNECT_FAILURE:
                    Ext.Msg.alert('Failure', 'Ajax communication failed!');
                    break;
                case Ext.form.Action.SERVER_INVALID:
                    obj = Ext.util.JSON.decode(action.response.responseText);
                    Ext.MessageBox.show({
                        title: 'Failed!',
                        msg: obj.errors.reason,
                        buttons: Ext.MessageBox.OK,
                        icon: Ext.MessageBox.ERROR
                    });
//                            if (obj.register != null) {
//                                window.location.href = '';
//                            }
                    break;
            }
        }
    });
}


