﻿Ext.namespace('MSDImages');

MSDImages.ForgottenPasswordApp = function() {

    //private space
    var emailField, btnSubmit;

    function initFields() {

        emailField = new Ext.form.TextField({
            applyTo: 'emailAddress',
            vtype: "email",
            width: 300,
            allowBlank: false
        });

        btnSubmit = new Ext.Button({
            applyTo: 'btnSubmit',
            text: 'Reset password',
            handler: function() {
                if (emailField.isValid()) {
                    document.forms['forgotPass'].submit();
                } else {
                    Ext.Msg.show({
                        title: 'Sorry, unable to reset your password',
                        msg: 'Please enter your email address and try again',
                        buttons: Ext.MessageBox.OK,
                        icon: Ext.MessageBox.ERROR,
                        maxWidth: 50
                    });
                }
            }
        });
    }

    function removeForgottenPasswordLink() {
        var el = Ext.select('#forgottenpasswordlink');

        if (el != null) {
            el.hide();
        }
    }


    //public space
    return {
        init: function() {
            initFields();
            removeForgottenPasswordLink();
        }
    }

} ();