/*
 * Ext JS Library 2.2
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

Ext.onReady(function(){

    Ext.QuickTips.init();

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

    var bd = Ext.getBody();

    /*
     * ================  Formuário de reserva  =======================
     */
	 
    var simple = new Ext.FormPanel({
        labelWidth: 100, // label settings here cascade unless overridden
        url:'reserva.php',
        frame:true,
        title: 'Solicita&ccedil;&atilde;o de reserva',
        bodyStyle:'padding:5px 5px 0',
        width: 450,
        defaults: {width: 240},
        defaultType: 'textfield',

        items: [{
                fieldLabel: 'Nome',
                name: 'nome',
                allowBlank:false
            },{
                fieldLabel: 'Telefone (DDD)',
                name: 'telefone',
				allowBlank:false
            }, {
                fieldLabel: 'Email',
                name: 'email',
                vtype:'email',
				allowBlank:false
            }, new Ext.form.DateField({
                fieldLabel: 'Data chegada',
                name: 'dataChegada',
				allowBlank:false
			}), new Ext.form.DateField({
                fieldLabel: 'Data sa&iacute;da',
                name: 'dataSaida'
            }),new Ext.form.ComboBox({
				fieldLabel: 'Tipo de su&iacute;te',
				name: 'tipoDeSuite',
				store: new Ext.data.SimpleStore({
					fields: ['tipoDeSuite'],
					data : [
							['Single - 1 adulto'],
							['Duplo - 2 adultos'],
							['Casal - 2 adultos'],
							['Triplo - 3 adultos'],
							['Qu&aacute;druplo - 4 adultos'],
							['Qu&iacute;ntuplo - 5 adultos']
						   ]
				}),
				displayField: 'tipoDeSuite',
				typeAhead: true,
				mode: 'local',
				triggerAction: 'all',
				selectOnFocus:true,
				width:190,
				editable:false
            }),
			{
				 xtype: 'checkbox',
                fieldLabel: 'Opcionais',
                boxLabel: 'Ar condicionado',
                name: 'arCondicionado',
                inputValue: 'Sim'
            }, {
				 xtype: 'checkbox',
                fieldLabel: '',
                labelSeparator: '',
                boxLabel: 'Garagem',
                name: 'garagem',
                inputValue: 'Sim'
            },
			{
                fieldLabel: 'Crian&ccedil;as at&eacute; 7 anos',
                name: 'quantidadeCriancasAte7'
            }, {
                fieldLabel: 'Crian&ccedil;as acima de 7 anos',
                name: 'quantidadeCriancasAcima7'
            },new Ext.form.TextArea({
                fieldLabel: 'Observa&ccedil;&otilde;es',
                name: 'observacoes'
			})
        ],

		buttons: [{
			text: 'Enviar',
            handler: function() {
                if(simple.getForm().isValid()) {
	                simple.getForm().submit({
	                    url: 'reservas.php',
	                    waitMsg: 'Enviando...',
						waitTitle: 'Espere por favor...',
	                    success: function(simple, o){
							Ext.MessageBox.alert('Sucesso', 'Solicita&ccedil;&atilde;o de reserva enviada com sucesso, aguarde a confirma&ccedil;&atilde;o!');
	                    },
	                    failure: function(simple, o){
							Ext.MessageBox.alert('Falha', 'Error ao enviar a solicita&ccedil;&atilde;o de reserva, tente novamente!');
	                    }
	                });
                }
            }
        },{
			text: 'Limpar',
			handler: function() {
				simple.getForm().reset();
			}
        }]
    });

    simple.render('formularioReserva');
    
});
