/*
 * Ext JS Library 2.0
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

Ext.onReady(function(){

				Ext.QuickTips.init();

    // E-mail
				var email = new Ext.form.TextField({
								//labelStyle: 'color: #5B7C83; font-weight:bold; font-size:100%;',
								fieldLabel: 'Newsletter',
								id: 'email',
								name: 'email',
								allowBlank: false,
								emptyText: 'Digite seu e-mail',
								//width: 250,
								maxLength: 255,
								vtype: 'email',
								msgTarget: 'qtip',
								anchor: '98%'
				});

    // Form ----------------------------------------------------
    var formPanel = new Ext.FormPanel({
								url: url + '/modulos/newsletter/newsletter.cadastrar.php',
								el: 'div-newsletter',
								bodyStyle: 'background-color:transparent;',
								autoWidth: true,
								labelAlign: 'top',
								border: false,
								autoWidth: true,
								autoHeight: true,
								items: [{
												layout: 'column',
												baseCls: 'x-plain',
												anchor: '100% 100%',
												items:[{
																columnWidth: .8,
																layout: 'form',
																border: false,
																bodyStyle: 'background-color:transparent;',
																anchor: '100% 100%',
																items: [email]
												},{
																columnWidth: .2,
																baseCls: 'x-plain',
																border: false,
																style: {'margin-top':'18px', 'text-align':'right'},
																anchor: '100% 100%',
																items: new Ext.Button({
																				text: '',
																				iconCls: 'ok',
																				handler: function() {
																								if (formPanel.form.isValid()) {
                            Ext.get('div-newsletter').mask('Aguarde...');
																												formPanel.form.submit({	
																																params: {loja:lojaId, acao:'newsletter', 'email':email},
																																failure: function(form, action) {
																																				Ext.MessageBox.show({
																																								title: 'Erro',
																																								msg: action.result.msg.clientCode,
																																								buttons: Ext.MessageBox.OK,
																																								icon: Ext.MessageBox.ERROR
																																				});
																																				Ext.get('div-newsletter').unmask();
																																},
																																success: function(form, action) {
																																				Ext.MessageBox.show({
																																								title: 'informa&ccedil;&atilde;o',
																																								msg: action.result.msg.clientCode,
																																								buttons: Ext.MessageBox.OK,
																																								icon: Ext.MessageBox.INFO
																																				});
																																				Ext.get('div-newsletter').unmask();
																																				formPanel.form.reset();
																															 }
																											 });                   
																								} else {
																												Ext.MessageBox.show({
																																title: 'Erro',
																																msg: '<b>Por favor, verifique os erros.</b>',
																																buttons: Ext.MessageBox.OK,
																																icon: Ext.MessageBox.ERROR			
																												});
																								}             
																				}
																})
												}]
								}]
				});

				formPanel.render();
});