/**
 * @author gerardo.lopez
 */
Ext.ns('Ext.ux.clv2');

Ext.ux.clv2.windowForgotLogin = function(config){
    // call parent constructor
    Ext.ux.clv2.windowForgotLogin.superclass.constructor.call(this, config);
    this.on('beforeclose', this.hideSpotlight, this);
    this.on('beforehide', this.hideSpotlight, this);
    this.on('beforeshow', this.showSpotlight, this);
	this.on('collapse', this.showSpotlight, this);
    this.on('move', this.showSpotlight, this);
    this.on('resize', this.showSpotlight, this);
}; 
Ext.extend(Ext.ux.clv2.windowForgotLogin, Ext.Window, {
    width: 370,
    buttonAlign: 'right',
    closable: false,
    resizable: false,
    hideSpotlight: hideSpotlight,
    showSpotlight: showSpotlight
});

Ext.ux.clv2.panelForgotLogin = function(config){
    // call parent constructor
    Ext.ux.clv2.panelForgotLogin.superclass.constructor.call(this, config);
    this.on('beforeclose', this.hideSpotlight, this);
    this.on('beforehide', this.hideSpotlight, this);
    this.on('beforeshow', this.showSpotlight, this);
}; 
Ext.extend(Ext.ux.clv2.panelForgotLogin, Ext.Panel, {});

var showForgotLogin = function(userName){
    var panelError = new Ext.ux.clv2.panelForgotLogin({
        html: '<div id="errorLogin"class="ForgotloginError">Your passwords don\'t match</div>',
		height:20
    });
    var panelUpdateBody = new Ext.ux.clv2.panelForgotLogin({
        height: 55,
        width: 370,
        html: '<div class="body1-ForgotloginError">Update your password:</div><div class="body2-ForgotloginError">You have to replace your temporary password a new one.</div>'
    });
    
    var btnCancel = new Ext.Toolbar.Button({
        // text: 'Send',
        ctCls: 'cancel-btn',
        handler: function(){
            this.window.close();
        }
    });
    var btnSave = new Ext.Toolbar.Button({
        // text: 'Send',
        ctCls: 'save-btn',
        handler: function(){
            var valid = Ext.get('errorLogin');
            if (fieldPassword.getValue() != fieldRePassword.getValue()) {
                valid.addClass('ForgotloginErrorAvaible');
            }
            else {
                valid.removeClass('ForgotloginErrorAvaible');
                var securityUtils = new Ext.clv2.utils.SecurityUtils();
                securityUtils.changePassword(userName, fieldPassword.getValue());
                document.loginForm.submit();
            }
        }
    });
    
    var fieldPassword = new Ext.form.TextField({
        fieldLabel: 'Type your password',
        name: 'first',
        inputType: 'password'
    });
    
    var fieldRePassword = new Ext.form.TextField({
        fieldLabel: 'Retype your Password',
        name: 'pass',
        inputType: 'password'
    });
    var panelErrorButtoms = new Ext.form.FormPanel({
        height: 120,
        labelWidth: 120,
        width: 370,
        cls: 'clv2-btns',
        buttonAlign: 'right',
        defaults: {
            width: 200
        },
        defaultType: 'textfield',
        items: [fieldPassword, fieldRePassword],
        buttons: [btnCancel, btnSave]
    
    });
    var windowUpdatePassword = new Ext.ux.clv2.windowForgotLogin({
        title: 'Update your Password',
        cls: 'clv2-window gear-window  forgotLoginWindow',
        items: [panelError, panelUpdateBody, panelErrorButtoms]
    
    });
    Ext.apply(btnCancel, {
        'window': windowUpdatePassword
    });
    
    windowUpdatePassword.show();
}