Ext.apply(Ext.form.VTypes, {
    numbers:  function(v) {
        return /^[0-9]+$/.test(v);
    },
    numbersText: 'Apenas numeros s&atilde;o permitidos.'
});

var form;
var windowx;

function loadMail(){
		var dt=new Date();
		if(!dt.between(new Date, new Date('13/07/2011 23:00'))){
			Ext.MessageBox.show({
				title: 'Aviso',
				msg: 'O Per&iacute;odo de registo j&aacute; terminou!' ,
				buttons: Ext.MessageBox.OK,
				icon: Ext.MessageBox.INFO
			});
			return false;
		}
		form = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth:75,
        url:'inscricao.php',
        defaultType: 'textfield',

        items: [{
                fieldLabel: 'Nome',
                name: 'name',
                allowBlank:false,
				width: 330
				
            },{
                fieldLabel: 'E-Mail',
                name: 'mail',
				vtype:'email',
				width: 330,
				allowBlank: true
				
			}, {
				fieldLabel: 'Telefone',
				name: 'phone',
				vtype: 'numbers',
				width: 120,
				allowBlank: true	
				
			}, new Ext.form.DateField({
					fieldLabel: 'Data Nasc.',
					name: 'nasc',
					minValue: '01/01/1900',
					maxValue: '31/12/2004',
					width: 100,
					format:'d/m/Y',
					allowBlank: true, 
					showToday: false
					
			}), new Ext.form.ComboBox({
					id: 'country',
					width:200,
					store: nasc_store,
					fieldLabel: 'Nacionalidade',
					displayField:'value',
					typeAhead: true,
					mode: 'remote',
					forceSelection: true,
					triggerAction: 'all',
					emptyText:'Seleccione país...',
					selectOnFocus:true,
					valueField: 'key',
					value: 'Portugal',
					allowBlank: false
					
			}),new Ext.form.ComboBox({
					id: 'type',
					width:200,
					store: type_store,
					fieldLabel: 'Escal&#227;o',
					displayField:'value',
					typeAhead: true,
					mode: 'local',
					forceSelection: true,
					triggerAction: 'all',
					emptyText:'Seleccione escalão...',
					selectOnFocus:true,
					valueField: 'key',
					allowBlank: false
								
			}), new Ext.form.ComboBox({
					id: 'title',
					width:200,
					store: master_store,
					fieldLabel: 'T&#237;tulo',
					displayField:'desc',
					typeAhead: true,
					mode: 'local',
					forceSelection: true,
					triggerAction: 'all',
					emptyText:'Seleccione t&iacute;tulo...',
					selectOnFocus:true,
					valueField: 'desc',
					allowBlank: true,
					value: 'Sem Título',
					sort: true
			}),{
				fieldLabel: 'Elo FPX',
				name: 'fpx',
				vtype: 'numbers',
				width:100,
				allowBlank: true
			},{
				fieldLabel: 'Elo FIDE',
				name: 'fide',
				vtype: 'numbers',
				width:100,
				allowBlank: true
			}, new Ext.form.TextArea({
				name: 'comment',
				fieldLabel: 'Coment&aacute;rio',
				width: 330,
				height: 80,
				allowBlank: true
			}),
			new Ext.form.Label({
				html:	'<br><b>Todas as Inscri&ccedil&otilde;es est&atilde;o sujeitas a aprova&ccedil;&atilde;o.</b>',
				name: 'approv'
			})
        ],
		buttons: [{
            text: 'Enviar',
			handler: function(){
				Ext.MessageBox.show({
					title: 'Confirma&ccedil;&atilde;o',
					msg: "Esta prestes a enviar a sua inscri&ccedil;&atilde;o.<br>Posteriormente receber&#225; um E-Mail ou um telefonema de confirma&ccedil;&atilde;o do seu registo.<br>Deseja Enviar?" ,
					buttons: Ext.MessageBox.OKCANCEL,
					icon: Ext.MessageBox.QUESTION,
					fn: function(btn, txt){
						if(btn=="ok"){
				form.getForm().submit({
						method: 'POST',
						timeout: 10000,
						waitTitle: 'Por favor espere...',
						waitMsg: 'A Introduzir informa&ccedil;&atilde;o...',
						success: function() {
							Ext.MessageBox.show({
								title: 'Inscri&ccedil;&atilde;o',
								msg: "Inscri&ccedil;&atilde;o enviada com sucesso.<br>",
								buttons: Ext.MessageBox.OK,
								icon: Ext.MessageBox.INFO
							});
							form.getForm().reset();
							windowx.close();
						},
						failure: function(formx, action) {
							if (action.failureType == 'server') {
								obj = Ext.util.JSON.decode(action.response.responseText);
								var sms=obj.errors.reason;
							} else 
								var sms='Dados Incorrectos!<br>Por Favor verifique os dados introduzidos!';
							
							Ext.MessageBox.show({
								title: 'Aviso',
								msg: sms ,
								buttons: Ext.MessageBox.OK,
								icon: Ext.MessageBox.WARNING
							});
						}
				});
				}
			}
				});
			}
        },{
            text: 'Limpar',
				handler: function(){
					form.getForm().reset();
				}
        }]
    });

	windowx = new Ext.Window({
        title: 'Inscri&ccedil;&atilde;o',
        width: 440,
        height:450,
        minWidth: 300,
        minHeight: 200,
        layout: 'fit',
        plain:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        items: form,
		modal: true
    });
}
