Ext.ns('Ext.ux.form');
Ext.onReady(function() {
	Ext.QuickTips.init();
	var doRedir = function () {window.location = 'index.php';}
	var thisForm = new Ext.FormPanel({
		id:'ctfrm'
		,title:'Contact'
		,renderTo:'form-ct'
		,monitorValid:true
		,width:420
		,height:490
		,frame:true
		,border:false
		,hideBorders:true
		,labelAlign:'top'
		,bodyStyle:'padding-left:10px;'
		,defaults:{xtype:'textfield',anchor:'-20', width:170}
		,finishAlert:function(action){var _title, _icon;
			if(action.result.success){_title='Bericht verzonden';_icon=Ext.MessageBox.INFO;}
			else {_title='Fout bij verzending';_icon=Ext.MessageBox.ERROR;}
			Ext.Msg.show({title:_title,msg: action.result.reason,buttons: Ext.Msg.OK,icon:_icon,minWidth:300,fn:doRedir});
		}
		/*,layout: 'template'
		,tpl: '<table cellspacing="15">' + 
		    '<tr><td colspan="2">{gender:field}</td></tr>' +
		    '<tr><td>naam<br />{naam:field}</td><td>e-mail<br />{email:field}</td></tr>' +
		    '<tr><td>bedrijf<br />{organisatie:field}</td><td>telefoon<br />{telefoon:field}</td></tr>' +
		    '<tr><td colspan="2">bericht<br />{tekst:field}</td></tr>' +
		    '<tr><td colspan="2">{cc:field}</td></tr>' +
		    '<tr><td colspan="2">{zelf:field}</td></tr>' +
		    '</table>'*/
		,items:[ 
			{
				name:'gender'
				,xtype:'ux-radiogroup'
				,hideLabel:true
				,horizontal:true
				,radios:[
					{value:'M',boxLabel:'de heer',checked:true}
					,{value:'V',boxLabel:'mevrouw'}
				]
			},{
				name:'naam'
				,fieldLabel:'Naam'
				,allowBlank:false
				,blankText: 'Vul uw naam in'
				,emptyText:'verplicht'
			},{
				name:'email'
				,fieldLabel:'E-mail adres'
				,vtype:'email'
				,vtypeText: 'Vul een geldig e-mail adres in (gebruiker@domein.nl)'
				,allowBlank:false
				,blankText: 'Vul uw e-mail adres in'
				,emptyText:'verplicht'
				//,plugins:[new Ext.ux.form.ServerValidator({url:'hndlr.contact.php',params:{cmd: 'validate'}})]
			},{
				name:'organisatie'
				,fieldLabel:'Organisatie'
			},{
				name:'telefoon'
				,fieldLabel:'Telefoon/gsm'
				,xtype: 'numberfield'
				,allowDecimals:false
				,allowNegative:false
				,invalidText:'Voer alleen cijfers in.'
			},{
				name:'tekst'
				,width:355
				,fieldLabel:'Bericht'
				,xtype:'textarea'
				,allowBlank:false
				,blankText: 'U heeft geen bericht ingetypt'
				,emptyText:'verplicht'
				,height:100
			},{
				name:'cc'
				,boxLabel:'Stuur&nbsp;mij&nbsp;een&nbsp;kopie'
				,xtype:'checkbox'
				,labelSeparator:''
				,inputValue: 1
			},/*{
				name:'zelf'
				,xtype:'label'
				,cls:'x-form-introtext'
				,html:'<div class="x-form-introtext">'+n+'&nbsp;&bull;&nbsp;'+a+'&nbsp;&bull;&nbsp;'+p+'<br />'+
					'Telefoon: '+t+'&nbsp;&bull;&nbsp;Fax: '+f+'<br />'+
					bn+': '+br+'&nbsp;&bull;&nbsp;Postbank: '+pr+'<br />'+
					'BTW nr: '+btw+'&nbsp;&bull;&nbsp;KvK '+kp+' '+kr+'</div>'
			},*/{ /* spam trap */
				name:'info'
				,xtype:'textfield'
				,cls:'x-hide-display'
				,hideLabel:true
			}]
		,buttons:[{
			 text: 'Verzenden'
			,formBind:true
			,handler:function() {
				thisForm.getForm().submit({
					url:'hndlr.contact.php?cmd=post'
					,method:'post'
					,failure:function(form, action){thisForm.finishAlert(action);}
					,success:function(form, action){thisForm.finishAlert(action);form.reset();}
				});
			}
		}]
	});

	thisForm.startMonitoring();
	Ext.form.Field.prototype.msgTarget = 'side';
});

