Ext.onReady(function()
	{
	var win;

	var asunto = new Ext.form.TextField({
		fieldLabel: 'Asunto',
		llowBlank: false,
		name: 'asunto',
		readOnly: true
	});

	var form = new Ext.FormPanel({
		labelWidth: 75,
		url:'enviodatos.php',
		frame:true,
		title: 'Formulario',
		defaults: {width: 263},
		items: [
		{
			xtype : 'fieldset',
			autoHeight : true,
			autoWidth : true,
			style: 'border:0px',
			html : '<img src="formlogo.gif"/>'
                },
		asunto,
		{
			xtype: 'textfield',
			fieldLabel: 'Nombre',
			name: 'nombre',
			allowBlank:false
		},{
			xtype: 'textfield',
			fieldLabel: 'Apellido',
			name: 'apellido',
			allowBlank:false
		},{
			xtype: 'textfield',
			fieldLabel: 'Empresa',
			name: 'empresa',
			allowBlank:false
		},{
			xtype: 'textfield',
			fieldLabel: 'Email',
			name: 'email',
			vtype:'email',
			allowBlank:false
		},{
			xtype: 'textfield',
			fieldLabel: 'Telefono',
			name: 'telefono',
			allowBlank:false
		}],

		buttons: [{
			text:'Aceptar',
			handler: function()
			{
				if( form.form.isValid() )
				{
					form.getForm().submit({
						method:'POST',
						waitTitle:'Conectando',
						waitMsg:'Enviando email...',
						success:function(){
							Ext.Msg.alert('Aviso', 'Los datos fueron enviados.');
							form.getForm().reset();
							win.hide();
						},
						failure: function(form, action)
						{
							if( action.failureType == 'server' )
							{
								obj = Ext.util.JSON.decode(action.response.responseText);
								Ext.Msg.alert('Error', obj.errors.reason );
								login.getForm().reset();
							}
							else
							{
								Ext.Msg.alert('Aviso!', 'Servidor de email invalido.' );
							}
						}
					});
				}
				else
					Ext.Msg.alert('Error', 'Verifique los datos ingresados.');

			}
			},{
			text: 'Cancelar',
			handler: function()
			{
				win.hide();
			}
		}]
	});

	Ext.select('a').on
	(
		'click',
		function(e)
		{
			var banner = Ext.get( e.target );
			if( banner.getValue() )
			{
				if(!win)
				{
					win = new Ext.Window({
						el:'ventana',
			        	        layout:'fit',
			                	width:370,
				                height:340,
				                closeAction:'hide',
			        	        plain: true,
						modal: true,
						resizable: false,
						closable : false,
						items: form
					});
				}
				asunto.setValue( banner.getValue() );
				form.setTitle( banner.getValue() );
				win.show(this);
			}
		}
	);
});

