function checkForm() {
	var selectedEv = document.forms.frmChoose3EVs.frmErkendeVerhuizer; 
	var counter = 0;
	for (i = 0; i < selectedEv.length; ++ i) {
		if (selectedEv[i].checked) {
			counter++;
	  	}
	}
	if (counter == 0 || counter > 3) {
		$('contentleft_contentbottom').appear({ duration: 2.0, from: 0, to: 1 });
		return false;
	} else {
		return true;
	}
}

function countSelectedEVs() {
	var selectedEv = document.forms.frmChoose3EVs.frmErkendeVerhuizer;
	var counter = 0;
	for (i = 0; i < selectedEv.length; ++ i) {
		if (selectedEv[i].checked) {
	    	counter++;
			if (counter > 3) {
				$('contentleft_contentbottom').appear({ duration: 2.0, from: 0, to: 1 });
				//selectedEv[i].checked = false;
			} else if (counter == 3) {
				$('contentleft_contentbottom').hide({ duration: 2.0, from: 0, to: 1 });
			}
	  	}
	}
}

function sendForm() {
	if ($F('typeverhuizing') == 'particulier') {
		if (checkPersonaliaForm()) { 
			document.forms.personalia.submit(); 
		}
	} else if ($F('typeverhuizing') == 'bedrijf') {
		if (checkCompanyForm()) {
			document.forms.company.submit();
		}
	} 
}

function checkPersonaliaForm() {
	if ($F('achternaam') == '' || $F('achternaam') == 'Achternaam') {
		$('achternaam').setStyle({ 'color' : '#F66013' })
		var error = true;
	} 
	if ($F('telefoon') == '' || $F('telefoon') == 'Telefoonnummer') {
		$('telefoon').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('email') == '' || $F('email') == 'E-mail') {
		$('email').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('postcode') == '' || $F('postcode') == 'Postcode') {
		$('postcode').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('huisnr') == '' || $F('huisnr') == 'Huisnr') {
		$('huisnr').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('aantal') == '' || $F('aantal') == 'Aantal') {
		$('aantal').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('straat') == '' || $F('straat') == 'Straat') {
		$('straat').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('plaats') == '' || $F('plaats') == 'Plaats') {
		$('plaats').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('nieuwstraat') == '' || $F('nieuwstraat') == 'Straat') {
		$('nieuwstraat').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('nieuwhuisnr') == '' || $F('nieuwhuisnr') == 'Huisnr') {
		$('nieuwhuisnr').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('nieuwpostcode') == '' || $F('nieuwpostcode') == 'Postcode') {
		$('nieuwpostcode').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('nieuwplaats') == '' || $F('nieuwplaats') == 'Plaats') {
		$('nieuwplaats').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	
	if (error) {
		$('contentleft_contentbottom').appear({ duration: 2.0, from: 0, to: 1 });
		return false;
	} else {
		return true;
	}
}

function checkCompanyForm() {
	if ($F('bedrijfsnaam') == '' || $F('bedrijfsnaam') == 'Bedrijfsnaam') {
		$('bedrijfsnaam').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('bedrijfsachternaam') == '' || $F('bedrijfsachternaam') == 'Achternaam') {
		$('bedrijfsachternaam').setStyle({ 'color' : '#F66013' })
		var error = true;
	} 
	if ($F('bedrijfstelefoon') == '' || $F('bedrijfstelefoon') == 'Telefoonnummer') {
		$('bedrijfstelefoon').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('bedrijfsemail') == '' || $F('bedrijfsemail') == 'E-mail') {
		$('bedrijfsemail').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('bedrijfspostcode') == '' || $F('bedrijfspostcode') == 'Postcode') {
		$('bedrijfspostcode').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('bedrijfshuisnr') == '' || $F('bedrijfshuisnr') == 'Huisnr') {
		$('bedrijfshuisnr').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('bedrijfsstraat') == '' || $F('bedrijfsstraat') == 'Straat') {
		$('bedrijfsstraat').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('bedrijfsplaats') == '' || $F('bedrijfsplaats') == 'Plaats') {
		$('bedrijfsplaats').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('bedrijfsnieuwstraat') == '' || $F('bedrijfsnieuwstraat') == 'Straat') {
		$('bedrijfsnieuwstraat').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('bedrijfsnieuwhuisnr') == '' || $F('bedrijfsnieuwhuisnr') == 'Huisnr') {
		$('bedrijfsnieuwhuisnr').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('bedrijfsnieuwpostcode') == '' || $F('bedrijfsnieuwpostcode') == 'Postcode') {
		$('bedrijfsnieuwpostcode').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	if ($F('bedrijfsnieuwplaats') == '' || $F('bedrijfsnieuwplaats') == 'Plaats') {
		$('bedrijfsnieuwplaats').setStyle({ 'color' : '#F66013' })
		var error = true;
	}
	
	if (error) {
		$('contentleft_contentbottom').appear({ duration: 2.0, from: 0, to: 1 });
		return false;
	} else {
		return true;
	}
}

function getAllDataFromZipcode(fieldstraat, fieldplaats, fieldpostcode, spinner) {
	$(spinner).show();
	var zipcode = $F(fieldpostcode);
	new Ajax.Request('../scripts/get_all_data_from_zipcode.php?zipcode=' + zipcode, {
		method: 'get',
	  	requestHeaders: {Accept: 'application/json'},
	  	onSuccess: function(transport) {
	    	var json = transport.responseText.evalJSON(true);
			if (json.street != '') {
				$(fieldstraat).setValue(json.street);
			}
			if (json.city != '') {
				$(fieldplaats).setValue(json.city);
			}
			$(spinner).hide();
		}
	});
}

function switchForm(type) {
	if (type == 'bedrijf') {
		$('typeverhuizing').setValue('bedrijf');
		$('bedrijfsverhuizingnee').checked = 'checked';
		$('containerformparticulier').hide();
		$('containerformbedrijf').appear({ duration: 1.5 });
		$('txtConsumer').hide({ duration: 1.5 });
		$('txtBusiness').appear({ duration: 1.5 });
	} else if (type = 'particulier') {
		$('typeverhuizing').setValue('particulier');
		$('verhuizingnee').checked = 'checked';		
		$('containerformbedrijf').hide();
		$('containerformparticulier').appear({ duration: 1.5 });
		$('txtBusiness').hide({ duration: 1.5 });
		$('txtConsumer').appear({ duration: 1.5 });
	}
}

function checkEnter(e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
	   document.forms.frmsearch.submit();
	   return false;
	} else {
	   return true;
	}
}