function countCheckboxes( targetElement, maxAmount ) {
	var checkboxes = targetElement.form[ targetElement.name ];
	var checkboxCounter = 0;
	for ( var counter = 0; counter < checkboxes.length; counter++ ) {
		var checkbox = checkboxes[ counter ];
		if ( checkbox.checked === true ) {
			checkboxCounter++;
				// if ( checkboxCounter > 5 ) <-- deze regel is fout
			if ( checkboxCounter > maxAmount )	{
				alert( 'Je kunt maximaal ' + maxAmount + ' toppings toevoegen.' );
				targetElement.checked = false;
				break;
			}
		}
	}
	return;
}

function verlaag(topping) {
	var huidig = document.getElementById('topping'+topping).value;
	if(huidig < 1) {
		// Maximaal twee per topping
	} else {
		var nieuw = parseInt(huidig) - 1;
		document.getElementById('topping'+topping).value = nieuw;
		if(nieuw == 0) {
			document.getElementById('topping'+topping).className = "text_s";
			document.getElementById('naam'+topping).className = "input_label";
			//document.getElementById('topping'+topping).style.color = "#0078ae";
			//document.getElementById('topping'+topping).style.backgroundColor = "white";
			//$('#topping'.topping).css('background-color', '#FF6600');
		}
	}
}

function verhoog(topping, max) {
	inputArray = document.getElementsByTagName("input");
	var aantal = 0;
	for (var index = 0; index < inputArray.length; index++)
		if (inputArray[index].type == 'text')
			aantal = aantal + parseInt(inputArray[index].value);

	if(aantal == max) {
		alert("Je kunt er maximaal "+ max +" kiezen.");
	} else {
		var huidig = document.getElementById('topping'+topping).value;
		if(huidig > 1) {
			// Maximaal twee per topping
		} else {
			var nieuw = parseInt(huidig) + 1;
			document.getElementById('topping'+topping).value = nieuw;
			if(nieuw == 1) {
				document.getElementById('topping'+topping).className = "text_s b";
				document.getElementById('naam'+topping).className = "input_label bd";
				//document.getElementById('topping'+topping).style.color = "white";
				//document.getElementById('topping'+topping).style.backgroundColor = "#0078ae";
				//$('#topping'.topping).css('background-color', '#FF6600');
			}
		}
	}		
}

function registreren() {
	var error_string = "";
	if(document.regiform.emailadres == "")
		error_string = "E-mailadres\n";
	if(document.regiform.wawchtwoord == "")
		error_string = "Wachtwoord\n";
	if(error_string == "")
		document.inlogform.submit();
	else
		alert("Geef onderstaande gegevens op om in te loggen:\n\n"+error_string);
}

function bestelling() {
	var error_string = "";
	if(document.post.voornaam.value == "")
		error_string += "- Voornaam\n";
	if(document.post.achternaam.value == "")
		error_string += "- Achternaam\n";
	if(document.post.telefoon.value == "")
		error_string += "- Telefoonnummer\n";
	if(document.post.straat.value == "")
		error_string += "- Straat\n";
	if(document.post.nummer.value == "")
		error_string += "- Nummer\n";
	if(document.post.postcode.value == "")
		error_string += "- Postcode\n";
	if(document.post.plaats.value == "")
		error_string += "- Plaats\n";

	if(document.post.betalingswijze.value == "")
		error_string += "- Betalingswijze\n";
	if(document.post.bezorgtijd.value == "")
		error_string += "- Bezorgtijd\n";

	if(document.post.controle.checked == false)
		error_string += "\nVink aan dat je de gegevens hebt gecontroleerd.\n";
	
	if(error_string == ""){
		var objToTest = document.post.ref;
		if (objToTest == null || objToTest == undefined) {
			document.post.submit()
		} else {
			if(document.post.ref.checked == true){
				document.post.submit();
			}
			else if(confirm('U heeft nog niet aangegeven te willen mee doen voor de GRATIS WEDSTRIJD KAARTEN\n\nKlik op ANNULEREN en zet een vinkje in het vakje "Ik wil kans maken op..." als u alsnog mee wilt doen.')){
				document.post.submit();
			}
			
		}
	}
	else { 
		alert("Je hebt niet alle verplichten velden ingevuld:\n\n"+error_string);
	}
}

function ganaarthuisbezorgd(postcode) {
	window.location = "http://dominos.thuisbezorgd.nl/frameright.php?pc="+postcode;
}
