/*
 * Ext JS Library 2.1
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

Ext.apply(Ext.form.VTypes, {
	postcode: function(v){
		return /^\d{4}\w{2}$/.test(v);
	},
	postcodeMask: /[\d\w]/,
	postcodeText: 'De postcode moet in het formaat 0000XX',
	telefoon: function(v){ return /((^06\s{0,1}[0-9]{8}$)|(^[0-9]{3,4}\s{0,1}[0-9]{6,7}$)|(^\+{1}[0-9]{2}\s{0,1}[0-9]{2,3}\s{0,1}[0-9]{6,7}$))/.test(v); },
	telefoonMask: /[\d\s]/,
	telefoonText: '10-cijferig telefoonnummer in het formaat: kerngetal-nummer (012 3456789)'	
});

var fp = null;

Ext.onReady(function(){

    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'under';
    
    var bouwjaren = [];
    var jaar = (new Date()).getFullYear();
    for (var i=0;i<20;i++) {
    	bouwjaren.push([jaar - i]);
    }
    
    var y = (new Date()).getFullYear() - 18;
    var maxDate = new Date();
    maxDate.setFullYear(y);

    fp = new Ext.FormPanel({
        labelAlign: 'bottom',
		url: baseUrl + '/inc.save_mailing.php',
        frame: false,
		border: false,
		labelWidth: 155,
		defaults: { 
			width: 300
		},
        items: [{
			border: false,
			labelSeparator: '',
			style: 'font-size: 12px; color: #656262; margin: 0 0 10px 0;',
			html: '<div>Wilt u ook op de hoogte blijven?<br />Meld u aan voor &eacute;&eacute;n van de nieuwsbrieven.</div>'
		},{
			id :'mailing_plantenteelt',
			name :'mailing_plantenteelt',
			xtype :'checkbox',
			width :'auto',
			fieldLabel :'',
			labelSeparator :'',
			boxLabel : '<span style="color: #656262;">Plantenteelt</span>'
		},{
			id :'mailing_groen_infra',
			name :'mailing_groen_infra',
			xtype :'checkbox',
			width :'auto',
			fieldLabel :'',
			labelSeparator :'',
			boxLabel : '<span style="color: #656262;">Groen, grond en infra</span>'
		},{
			id :'mailing_groen',
			name :'mailing_groen',
			xtype :'checkbox',
			width :'auto',
			fieldLabel :'',
			labelSeparator :'',
			boxLabel : '<span style="color: #656262;">Groen</span>'
		},{
			id :'mailing_bloemdesign',
			name :'mailing_bloemdesign',
			xtype :'checkbox',
			width :'auto',
			fieldLabel :'',
			labelSeparator :'',
			boxLabel : '<span style="color: #656262;">Bloemdesign</span>'
		},{
			id :'mailing_veehouderij',
			name :'mailing_veehouderij',
			xtype :'checkbox',
			width :'auto',
			fieldLabel :'',
			labelSeparator :'',
			boxLabel : '<span style="color: #656262;">Veehouderij</span>'
		},{
			id :'mailing_cursusonderwijs',
			name :'mailing_cursusonderwijs',
			xtype :'checkbox',
			width :'auto',
			fieldLabel :'',
			labelSeparator :'',
			boxLabel : '<span style="color: #656262;">Cursusonderwijs & Contractactiviteiten</span>'
		},{
			xtype:'textfield',
			fieldLabel: 'Bedrijfsnaam *',
			name: 'company',
			blankText: '- Het veld Bedrijfsnaam is niet correct ingevuld',
			msgTarget: 'error-panel1',
			allowBlank: false
		},{
			xtype:'textfield',
			fieldLabel: 'Contactpersoon *',
			name: 'contact',
			blankText: '- Het veld Contactpersoon is niet correct ingevuld',
			msgTarget: 'error-panel1',
			allowBlank: false
		},{
			xtype:'textfield',
			fieldLabel: 'E-mailadres *',
			name: 'email',
			vtype:'email',
			blankText: '- Het veld E-mailadres is niet correct ingevuld',
			msgTarget: 'error-panel2',
			allowBlank: false
        },{
			border: false,
			labelSeparator: '',
			style: 'font-size: 12px; color: #656262; margin: 20px 0 0 160px;',
			html: '<div>Velden met een <span style="color: #13aa66;">*</span> gemarkeerd zijn verplicht.</div>'
		}]
    });
	
	fp.render('formulier');
});

function verstuur() {
	var form = fp.getForm();
	if (form.isValid()) {
		form.submit({
			success:function() {
			    Ext.get('formBox').setVisibilityMode(Ext.Element.DISPLAY).hide(true);
			    Ext.get('bedankt').show();
			},
			failure: function() {
				alert('Er is iets mis gegaan bij het verzenden van het formulier.');
			}
		});
	} else {
		alert('Het formulier is niet correct ingevuld.');
	}
}
