<!--
Ext.onReady(function()
{	
		  Ext.BLANK_IMAGE_URL = url + '/bibliotecas/extjs/resources/images/default/s.gif';
				
				Ext.QuickTips.init();

				var radioLogin = new Ext.form.Radio({
								labelStyle: 'font-size: 100%;',
								hideLabel: true,
								boxLabel: 'J&aacute; sou cadastrado',
								name: 'tipo',
								checked: true
				});
				
			 radioLogin.on('check', function(checkbox, checked) {
								if (checked == true) {
													email.enable();
													senha.enable();
													email.focus();
													cep.reset();
													cep.disable();
													radioNovo.setValue(false);
								}
				});

				var radioNovo = new Ext.form.Radio({
								labelStyle: 'font-size: 100%;',
								hideLabel: true,
								boxLabel: 'Minha 1&ordf; compra',
								name: 'tipo'
				});
				
				radioNovo.on('check', function(checkbox, checked) {
								if (checked == true) {
													email.reset();
													email.disable();
													senha.reset();
													senha.disable();
													cep.enable();
													cep.focus();
													radioLogin.setValue(false);
								}
				});
				
    // E-mail
				var email = new Ext.form.TextField({
								labelStyle: 'width:50px; font-weight: bold; font-size: 100%;',
								fieldLabel: 'E-mail',
								name: 'email',
								allowBlank: false,
								maxLength: 255,
								minLength: 3,
								vtype: 'email',
								msgTarget: 'qtip',
								anchor: '100%'
				});
				
				// Senha
				var senha = new Ext.form.TextField({
								labelStyle: 'width:50px; font-weight: bold; font-size: 100%;',
								fieldLabel: 'Senha',
								name: 'senha',
								inputType: 'password',
								allowBlank: false,
								maxLength: 10,
								minLength: 6,
								vtype: 'alphanum',
								//readOnly: true,
								//style: {'color':'#999999'},
							 msgTarget: 'qtip',
								width: 150,
								minWidth: 150
				})	

				// CEP
				var cep = new Ext.form.TextField({
								labelStyle: 'width:50px; font-weight: bold; font-size: 100%;',
								fieldLabel: 'CEP',
								name: 'cep',
								allowBlank:false,
								maxLength: 9,
								minLength: 9,
								plugins: [new Ext.ux.InputTextMask('99999-999', true)],
								msgTarget: 'qtip',
								width: 150,
								minWidth: 150
				});

    // Login
			 var formLogin = new Ext.form.FormPanel({
								baseCls: 'x-plain',
        labelWidth: 50,
        defaultType: 'textfield',
        items: [radioLogin, email, senha, radioNovo, cep],
								buttonAlign: 'right'
    });

    var painelLogin = new Ext.Panel({
								el: 'div-login',
								title: 'J&aacute; sou cadastrado',
								bodyStyle: 'padding:10px; margin-bottom:10px; font-size:100%;',
								//border: false,
								height: 210,
								monitorResize:true,
								items: formLogin,
        buttons: [{
            text: 'Continuar', 
            handler: function() { enviaForm(); }
        },{
            text: 'Lembrar senha',
            handler: function() { lembraSenha(); }
        }]
				});
    
				painelLogin.render();
				
				email.focus();

				// Mapeia tecla ENTER para submeter o formulário de login
				var map = new Ext.KeyMap(Ext.get(document.body), [
								{
												key: Ext.EventObject.ENTER,
												fn: function() { enviaForm(); }
								}
				]);

				function enviaForm() {
								if (radioLogin.getValue() === true) {
								    var acao   = 'login';
								} else {
									   var acao   = 'novo';
												Ext.Ajax.request({
															timeout: 15000,
															url: url + '/modulos/cliente/cliente.listar.php',
															params: {acao:'guardacep', 'cep':cep.getValue(), loja:lojaId, 'PHPSESSID':sessionId},
															method: 'GET',
															disableCaching: true,
															success: function(result, request) {
														     window.location = url + '/?loja=' + lojaId + '&PHPSESSID=' + sessionId + '&modulo=cadastro&mostrar=cadastro&acao=' + acao;
															},
															failure: function() {
																			return false;
															}
												});
												return;
								}

								formLogin.form.url = url + '/modulos/cliente/cliente.listar.php';
								
								if (formLogin.form.isValid()) {
												formLogin.form.submit({
																params: {'PHPSESSID':sessionId, 'acao':acao, loja:lojaId},
																waitTitle: 'Aguarde',
																waitMsg: 'Autenticando...',
																failure: function(form, action) {
																				Ext.MessageBox.show({
																								title: 'Erro',
																								msg: action.result.msg.clientCode,
																								buttons: Ext.MessageBox.OK,
																								animEl: 'Botao',
																								icon: Ext.MessageBox.ERROR			
																				});	
																},
																success: function(form, action) {
																				if(action) {
																								//Seta cookie token
																								//var value = action.result.msg.clientCode;
																								//Cookies.set('token', value);
																								//Url redirecionamento
																								window.location = url + '/?loja=' + lojaId + '&PHPSESSID=' + sessionId + '&modulo=' + modulo + '&mostrar=' + mostrar;
																				}
																}
													});                   
								} else {
													Ext.MessageBox.show({
																	title: 'Erro',
																	msg: '<b>Por favor, verifique os erros.</b>',
																	buttons: Ext.MessageBox.OK,
																	animEl: 'Botao',
																	icon: Ext.MessageBox.ERROR			
													});
								}             
				}

    function lembraSenha() {

								// E-mail
								var email = new Ext.form.TextField({
												labelStyle: 'width:50px; font-weight: bold; font-size: 100%;',
												fieldLabel: 'E-mail',
												name: 'email',
												allowBlank: false,
												maxLength: 255,
												minLength: 3,
												vtype: 'email',
												msgTarget: 'qtip',
												anchor: '100%'
								});

								var formLogin = new Ext.form.FormPanel({
												baseCls: 'x-plain',
												labelWidth: 50,
												url: url + '/modulos/cliente/cliente.listar.php',
												defaultType: 'textfield',
												items: [email]
								});
														
								// Janela
								var lembrar = new Ext.Window({
												title: 'Informe o e-mail cadastrado',
												width: 400,
												height: 105,
												minWidth: 400,
												minHeight: 105,
												layout: 'fit',
												plain:true,
												modal: true,
												constrain: true,
												maskDisabled: false,
												closable: false,
												resizable: false,
												draggable: false,
												bodyStyle:'padding:5px;',
												buttonAlign:'center',
												items: formLogin,
												buttons: [{
																text: 'Enviar', 
																handler: function() {
																				// check form value 
																				if (formLogin.form.isValid()) {
																								formLogin.form.submit({
																												params: {acao:'lembrar', 'PHPSESSID':sessionId, loja:lojaId},
																												waitTitle: 'Aguarde',
																												waitMsg: 'Enviando...',
																												failure: function(form, action) {
																																Ext.MessageBox.show({
																																				title: 'Erro',
																																				msg: action.result.msg.clientCode,
																																				buttons: Ext.MessageBox.OK,
																																				animEl: 'Botao',
																																				icon: Ext.MessageBox.ERROR			
																																});	
																												},
																												success: function(form, action) {
																																Ext.MessageBox.show({
																																				title: 'Informação',
																																				msg: action.result.msg.clientCode,
																																				buttons: Ext.MessageBox.OK,
																																				animEl: 'Botao',
																																				icon: Ext.MessageBox.INFO			
																																});	
																																lembrar.hide();
																												}
																									});                   
																						} else{
																									Ext.MessageBox.show({
																													title: 'Erro',
																													msg: '<b>Por favor, verifique os erros.</b>',
																													buttons: Ext.MessageBox.OK,
																													animEl: 'Botao',
																													icon: Ext.MessageBox.ERROR			
																									});
																						}             
																		}
												},{
																text: 'Cancelar',
																handler: function(){lembrar.hide()}
												}]
								});
								lembrar.show();
				}
});
//-->
