// JavaScript Document

Ext.onReady(function() {

	var your_name = new Ext.form.TextField({
		fieldLabel: 'Nombre',
		allowBlank: false,
		name: 'your_name',
		width: 300
	});
	
	var your_email = new Ext.form.TextField({
		fieldLabel: 'E-mail',
		allowBlank: false,
		vtype: 'email',
		name: 'your_email',
		width: 300
	});

	var message = new Ext.form.TextArea({
		fieldLabel: 'Mensaje',
		name: 'message',
		allowBlank: false,
		width: 300
	});
	
	var contact_form = new Ext.form.FormPanel({
		labelAlign: 'right',
		labelWidth: 70,
		url: '/contacto/send',
		defaultType: 'textfield',
		hideBorders: true,
		baseCls: 'panel',
		items: [
			your_name, your_email, message
		],
		buttons: [{
			text: '<span style="font-weight: bold">Enviar mensaje</span>',
			handler: function() {
				if (contact_form.form.isValid()) {
					contact_form.form.submit({			      
						waitMsg: 'Enviando mensaje',
						failure: function(form, action) {
							Ext.MessageBox.alert('Error al enviar', 'Hubo un error al enviar el mensaje. Por favor vuelva a intentarlo.');
						},
						success: function(form, action) {
							Ext.get('contact_form').dom.innerHTML = '<div class="no_content">Gracias por su mensaje</div>';
						}
					});                 
				} else{
					Ext.MessageBox.alert('Error al enviar', 'Algunos campos no han sido llenados o son inv&aacute;lidos. ' +
						'Para m&aacute;s detalles, posicione el rat&oacute;n encima de los s&iacute;mbolos de advertencia ' +
						'que encontrar&aacute; a la derecha de los campos con los errores.');
				}             
			}
		}],
		width: 400
	});
	
	contact_form.render('contact_form');
		
});
