/**
 * InterNLnet, 2008 (C)
 */

/**
 * Custom Vtypes
 */

Ext.apply(Ext.form.VTypes, {
	password: function(val, field) {
		if (field.initialPassField) {
			var pwd = Ext.getCmp(field.initialPassField);
			return (val == pwd.getValue());
		}
		return true;
	},
	passwordText: 'Passwords do not match',
	
	postcode: function(v){
		return /^\d{4}\w{2}$/.test(v);
	},
	postcodeMask: /[\d\w]/,
	postcodeText: 'De postcode moet in het formaat 0000XX',

	//contactnummer: function(v){ return /^\d{2,3,4}-\d{6,7,8}$/.test(v); },
	contactnummer: function(v){ return /((^06\-{1}[0-9]{8}$)|(^[0-9]{3,4}\-{1}[0-9]{6,7}$)|(^\+{1}[0-9]{2}\-{1}[0-9]{2,3}\-{1}[0-9]{6,7}$))/.test(v); },
	contactnummerMask: /[\d\-]/,
	contactnummerText: '10-cijferig telefoonnummer in het formaat: kerngetal-nummer (012-3456789)'
	
});

Ext.onReady(function(){
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'under';

	var store_aanhef = new Ext.data.SimpleStore({
		fields: ['abbr', 'state'],
		data: [['heer', 'heer'], ['mevr','mevr']]
	});

	var anwbform = new Ext.FormPanel({
		labelWidth: 150,
		cls: 'shadow',
		method: 'POST',
		frame: false,
		title: 'ADSL Shop Aanmeld formulier',
		bodyStyle: 'padding:5px 5px 0',
		items: [{
			xtype:'fieldset',
			autoHeight: true,
			defaults: {width: 270},
			defaultType: 'textfield',
			collapsed: false,
			items: [{
				xtype: 'panel',
				html: '<h2>Contact gegevens</h2>'
			},
			new Ext.form.ComboBox({
				fieldLabel: 'Aanhef',
				store: new Ext.data.SimpleStore({
					fields: ['aanhef'],
					data: [['Heer','heer'],['Mevr','mevr']]
				}),
				editable: false,
				displayField: 'aanhef',
				value: 'Heer',
				hiddenName: 'aanhef',
				typeAhead: false,
				triggerAction: 'all',
				emptyText: 'Kies uw aanhef...',
				mode: 'local',
				selectOnFocus: true
			}),
			{
				fieldLabel: 'Initialen',
				name: 'initialen',
				allowBlank: false
			},{
				fieldLabel: 'Achternaam',
				name: 'achternaam',
				allowBlank: false
			},
			new Ext.form.TextField({
				fieldLabel: 'Straatnaam',
				name: 'straatnaam',
				allowBlank: false
			}),
			new Ext.form.TextField({
				fieldLabel: 'Huisnummer',
				name: 'huisnummer',
				allowBlank: false,
				vtype:'alphanum'
			}),
			new Ext.form.TextField({
				fieldLabel: 'nr. toevoeging',
				name: 'toevoeging',
				allowBlank: true,
				vtype:'alphanum'
			}),
			new Ext.form.TextField({
				fieldLabel: 'Postcode',
				name: 'Postcode',
				allowBlank: false,
				vtype: 'postcode'
			}),

			new Ext.form.TextField({
				fieldLabel: 'Woonplaats',
				name: 'woonplaats',
				allowBlank: false
			}),
			new Ext.form.DateField({
				fieldLabel: 'Geboortedatum',
				name: 'gdate',
				allowBlank: false,
				format: 'd/m/Y'
			}),
			new Ext.form.TextField({
				fieldLabel: 'E-Mail',
				name: 'email',
				allowBlank: false,
				vtype: 'email'
			}),
			new Ext.form.TextField({
				fieldLabel: 'Mobiel nummer',
				name: 'mobielnummer',
				allowBlank: false,
				vtype: 'contactnummer'
			})
		]},{
		xtype:'fieldset',
    	autoHeight: true,
    	defaults: {width: 270},
    	defaultType: 'textfield',
    	collapsed: false,
    	items: [{
				xtype: 'panel',
				html: '<h2>Product informatie</h2>'
			},
				new Ext.form.ComboBox({
					fieldLabel: 'Producttype',
					store: new Ext.data.SimpleStore({
						fields: ['producttype'],
						data: [
							['Alice Comfort'],
							['Alice Easy']
						]
					}),
					editable: false,
					displayField: 'producttype',
					name: 'producttype',
					hiddenfield: 'producttype',
					emptyText: 'Kies uw producttype...',
					allowBlank: false,
					triggerAction: 'all',
					mode: 'local',
					typeAhead: false
				}),
				new Ext.form.ComboBox({
					fieldLabel: 'Huidig nummer behouden',
					store: new Ext.data.SimpleStore({
						fields: ['nummerbehouden'],
						data: [
							['Zet mijn huidige lijn om naar Alice'],
							['Ik wil een nieuwe lijn 69,-'],
							['Ik heb ISDN, een nieuwe lijn kost 69,-']
						]
					}),
					editable: false,
					displayField: 'nummerbehouden',
					name: 'nummerbehouden',
					hiddenfield: 'nummerbehouden',
					emptyText: 'Maak uw keuze...',
					allowBlank: false,
					triggerAction: 'all',
					mode: 'local',
					typeAhead: false
				}),
				new Ext.form.TextField({
					fieldLabel: 'Te behouden telefoonnummer',
					name: 'behoudennummer',
					vtype: 'contactnummer'
				}),
				new Ext.form.TextField({
					fieldLabel: 'Huidige telefoonnummer',
					name: 'huidigenummer',
					vtype: 'contactnummer'
				}),
				new Ext.form.ComboBox({
					fieldLabel: 'Type telefoon',
					store: new Ext.data.SimpleStore({
						fields: ['typetelefoon'],
						data: [
							['analoog via KPN'],
							['ISDN via KPN'],
							['telefonie via andere aanbieder'],
							['geen lijn']
						]
					}),
					editable: false,
					displayField: 'typetelefoon',
					name: 'typetelefoon',
					hiddenfield: 'typetelefoon',
					triggerAction: 'all',
					emptyText: 'Maak uw keuze...',
					mode: 'local'
				}),
				new Ext.form.ComboBox({
					fieldLabel: 'Vermelding nummer',
					store: new Ext.data.SimpleStore({
						fields: ['vermeldingnummer'],
						data: [
							['gids en inlichtingen'],
							['alleen inlichtingen'],
							['geen vermeldingen']
						]
					}),
					editable: false,
					displayField: 'vermeldingnummer',
					name: 'vermeldingnummer',
					hiddenfield: 'vermeldingnummer',
					triggerAction: 'all',
					emptyText: 'Maak uw keuze...',
					mode: 'local'
				}),
				new Ext.form.ComboBox({
					fieldLabel: 'Type installatie',
					store: new Ext.data.SimpleStore({
						fields: ['monteur'],
						data: [
							['Nee, Geen monteur'],
							['Ja, monteur (a 69,90 euro)']
						]
					}),
					editable: false,
					displayField: 'monteur',
					hiddenfield: 'monteur',
					name: 'monteur',
					triggerAction: 'all',
					emptyText: 'Maak uw keuze...',
					mode: 'local'
				}),
				new Ext.form.DateField({
					fieldLabel: 'Overstapdatum',
					name: 'overstapdatum',
					allowBlank: true,
					minValue: (new Date(new Date().valueOf() + (28*86400000))),
					maxValue: (new Date(new Date().valueOf() + (90*86400000))),
					format: 'd/m/Y'
				}),
				new Ext.form.Checkbox({
					fieldLabel: 'Internet',
					checked: true,
					disabled: true,
					value: 'ja',
					boxLabel: ' ',
					name: 'internet'
				}),
				new Ext.form.Checkbox({
					fieldLabel: 'Automatische incasso',
					checked: true,
					disabled: true,
					value: 'on',
					boxLabel: ' ',
					name: 'autoincasso'
				}),
				new Ext.form.Checkbox({
					fieldLabel: 'Factuur per post (2,50 euro/factuur)',
					boxLabel: ' ',
					value: 'off',
					name: 'factuurpost'
				}),
				new Ext.form.TextField({
					fieldLabel: 'Rekeningnummer',
					name: 'rekeningnummer',
					allowBlank: false
				}),
				new Ext.form.Checkbox({
					fieldLabel: 'Ik ga akkoord met de <a onclick="popUp(\'voorwaarden.php\');">voorwaarden</a> ADSLshop',
					boxLabel: ' ',
					value: 'off',
					name: 'akkoord',
					validate: function() {
						if (this.checked) {
							return true;
						} else {
							alert('U moet akkoord gaan met de voorwaarden.');
							return false;
						}
					}
				}),
				
			]
		}],

		buttons: [{
			handler: function (){
				anwbform.form.submit({
					waitMsg:'Verzenden Data...',
					url: 'save-form.php',
					success: function(e) {
						var values = anwbform.form.getValues();
						if (values.producttype == 'Alice Comfort') {
							window.location.replace("bedankt-comfort.php");
						} else {
							window.location.replace("bedankt-easy.php");
						}
					}
				});
			},
			text: 'Verzenden',
			cls: 'formBtn'
		},{
			handler: function (){
				anwbform.form.reset();
			},
			text: 'Opnieuw',
			cls: 'formBtn'
		}],
		renderto: 'form-div'
	});

	anwbform.render('form-div');
});

