var AppLembrarSenha = {

    win: null,
    formSystemLembrarSenha: null,

    show: function()
    {

        Ext.QuickTips.init();

	    // turn on validation errors beside the field globally
	    Ext.form.Field.prototype.msgTarget = 'qtip';

        AppLembrarSenha.win = new Ext.Window({
			id: 'JanelaLembrarSenha',
			title: 'Esqueci minha senha',
			width:300,
			height:200,
			modal: true,
			border: false,
			resizable: false,
			items:[
				new Ext.form.FormPanel({
                    id: 'formSystemLembrarSenha',
                    bodyStyle: 'background: transparent;',
                    url: 'RememberPass.php',
                    buttonAlign: 'right',
                    labelAlign: 'top',
                    method: 'post',
                    border: false,
                    fileUpload: false,
                    items: [
                        new Ext.Panel({
                            border: true,
                            bodyStyle: 'background: transparent; background-color:#fffab2',
                            html: '<div style="padding: 10px; font-size: 10px;">O procedimento "lembrar senha" consiste na geração de uma senha temporária, a qual é enviada para o e-mail vinculado a seu usuário. Para prosseguir com o processo, basta informar seu e-mail no campo abaixo e clicar no botão "Enviar Senha".</div>'
                        }),
                        new Ext.Panel({
                            border: false,
                            bodyStyle: 'background: transparent',
                            height: 10
                        }),
                        new Ext.form.TextField({
					    	id: 'Email',
					    	name: 'Email',
					    	fieldLabel: 'Digite seu E-mail',
					    	vtype: 'email',
					    	allowBlank:false,
					    	width: 290
					    })
                    ]
                })
			],
			buttons: [{
				text: 'Enviar Senha',
				cls:'x-btn-text-icon',
	    		icon: APPURL + 'Modules/Application/Images/Icons/style_go.png',
				handler: function()
				{

                    AppLembrarSenha.actionForm();

				}
			},{
				text: 'Sair',
				cls:'x-btn-text-icon',
	    		icon: APPURL + 'Modules/Application/Images/Icons/door_out.png',
				handler: function()
				{

					AppLembrarSenha.win.close();

				}
			}]
		});

		AppLembrarSenha.win.show();

    },

	actionForm: function()
	{

		AppLembrarSenha.formSystemLembrarSenha = Ext.getCmp('formSystemLembrarSenha');

        if (AppLembrarSenha.formSystemLembrarSenha.form.isValid())
		{

			AppLembrarSenha.formSystemLembrarSenha.form.submit({
				waitTitle: 'Processando',
				waitMsg: 'Aguarde enquanto sua nova senha é gerada',
				failure: function(form, action)
				{

					var texto;

					if (action.result != null)
						texto = action.result.text;
					else
						texto = '<b>Erro 404:</b> Arquivo não encontrado ou não disponível.<br><b>Arquivo:</b> ' + AppLembrarSenha.formSystemLembrarSenha.url;

					Ext.Msg.show({
					   title:'Mensagem',
					   msg: texto,
					   buttons: Ext.Msg.OK,
					   icon: Ext.MessageBox.ERROR
					});

				},
				success: function(form, action)
				{

					var texto;

					if (action.result != null)
					{

						texto = action.result.text;

                        AppLembrarSenha.win.close();

                        Ext.Msg.show({
						   title:'Mensagem',
						   msg: texto,
						   buttons: Ext.Msg.OK,
						   icon: Ext.MessageBox.INFO
						});

					}
					else
					{

						texto = '<b>Erro 404:</b> Arquivo não encontrado ou não disponível.<br><b>Arquivo:</b> ' + AppLembrarSenha.formSystemLembrarSenha.url;

						Ext.Msg.show({
						   title:'Mensagem',
						   msg: texto,
						   buttons: Ext.Msg.OK,
						   icon: Ext.MessageBox.ERROR
						});

					}

				}
			});

		}
		else
		{

			// Show a dialog using config options:
			Ext.Msg.show({
			   title:'Erro no processo!!!',
			   msg: 'Preencha corretamente os campos<br>para gerar sua nova senha.',
			   buttons: Ext.Msg.OK,
			   icon: Ext.MessageBox.ERROR
			});

			return false;

		}

	}

}
