function currency(anynum) {
	//-- Returns passed number as string in $xxx,xxx.xx format.
	anynum = eval(anynum)
	workNum = Math.abs((Math.round(anynum*100)/100));workStr=""+workNum

	if (workStr.indexOf(".")==-1){
		workStr+=".00"
	}
	
	dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
	pStr=workStr.substr(workStr.indexOf("."))

	while (pStr.length<3){
		pStr+="0"
	}

	//--- Adds comma in thousands place.
	if (dNum>=1000) {
		dLen=dStr.length
		dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
	}

	//-- Adds comma in millions place.
	if (dNum>=1000000) {
		dLen=dStr.length
		dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
	}
	retval = dStr + pStr
	//-- Put numbers in parentheses if negative.
	if (anynum<0) {
		retval="("+retval+")"
	}
	return retval
}

function doCalc(first, second, result) {

	if(parseFloat(first) < 0) {
		first = 0;
	}

	document.getElementById(result).value = parseFloat(first) * parseFloat(second);
	
	doCalcSubtotal();
	doCalcTotal();

}

function doCalcSubtotal() {

	subtotaal = 0;
	subtotaal = subtotaal+parseFloat(document.getElementById('ijsprijs').value);
	subtotaal = subtotaal+parseFloat(document.getElementById('bisquitprijs').value);
	subtotaal = subtotaal+parseFloat(document.getElementById('totaalhandkar').value);
	subtotaal = subtotaal+parseFloat(document.getElementById('totaalgondel').value);

  btw6 = 0.06 * (parseFloat(document.getElementById('ijsprijs').value) + parseFloat(document.getElementById('bisquitprijs').value));
  btw19 = 0.19 * (parseFloat(document.getElementById('totaalhandkar').value) + parseFloat(document.getElementById('totaalgondel').value));

	document.getElementById('subtotaal').value = currency(subtotaal);
	document.getElementById('btw6').value = currency(btw6);
	document.getElementById('btw19').value = currency(btw19);
	document.getElementById('afhaalprijs').value = currency(subtotaal+btw6+btw19);

	subtotaal = 0;
	subtotaal = subtotaal+parseFloat(document.getElementById('totaalijs').value);
	subtotaal = subtotaal+parseFloat(document.getElementById('totaalbisquit').value);
	subtotaal = subtotaal+parseFloat(document.getElementById('totaalloon').value);
	subtotaal = subtotaal+parseFloat(document.getElementById('totaalkm').value);
	subtotaal = subtotaal+parseFloat(document.getElementById('totaalextradag').value);

  btw26 = 0.06 * (parseFloat(document.getElementById('totaalijs').value) + parseFloat(document.getElementById('totaalbisquit').value));
  btw219 = 0.19 * (parseFloat(document.getElementById('totaalloon').value) + parseFloat(document.getElementById('totaalkm').value) + parseFloat(document.getElementById('totaalextradag').value));

	document.getElementById('subtotaal2').value = currency(subtotaal);
	document.getElementById('btw26').value = currency(btw26);
	document.getElementById('btw219').value = currency(btw219);
	document.getElementById('totaal').value = currency(subtotaal+btw26+btw219);

}


function doCalcTotal() {

	totaal = 0;
	totaal = totaal+parseFloat(document.getElementById('ijsprijs').value);
	totaal = totaal+parseFloat(document.getElementById('bisquitprijs').value);
	totaal = totaal+parseFloat(document.getElementById('totaalhandkar').value);
	totaal = totaal+parseFloat(document.getElementById('totaalgondel').value);
	totaal = totaal+parseFloat(document.getElementById('btw6').value);
	totaal = totaal+parseFloat(document.getElementById('btw19').value);

	totaal = totaal+parseFloat(document.getElementById('totaalijs').value);
	totaal = totaal+parseFloat(document.getElementById('totaalbisquit').value);
	totaal = totaal+parseFloat(document.getElementById('btw26').value);
	totaal = totaal+parseFloat(document.getElementById('btw219').value);

	totaal = totaal+parseFloat(document.getElementById('totaalloon').value);
	totaal = totaal+parseFloat(document.getElementById('totaalkm').value);
	totaal = totaal+parseFloat(document.getElementById('totaalextradag').value);

	document.getElementById('totaal').value = currency(totaal);

}

function doCheckIceForm() {
	
	if(document.getElementById('naam').value == "") {
		alert("U heeft geen naam ingevuld");
		return false;
	} else if(document.getElementById('adres').value == "") {
		alert("U heeft geen adres ingevuld");
		return false;
	} else if(document.getElementById('woonplaats').value == "") {
		alert("U heeft geen woonplaats ingevuld");
		return false;
	} else if(document.getElementById('telefoon').value == "") {
		alert("U heeft geen telefoon ingevuld");
		return false;
	} else if(document.getElementById('aflevernaam').value == "") {
		alert("U heeft geen aflever naam ingevuld");
		return false;
	} else if(document.getElementById('afleveradres').value == "") {
		alert("U heeft geen aflever adres ingevuld");
		return false;
	} else if(document.getElementById('afleverwoonplaats').value == "") {
		alert("U heeft geen aflever woonplaats ingevuld");
		return false;
	} else {
		alert("Bedankt voor uw bestelling!");
		return true;
	}

}

function doCheckOrderForm() {
	
	if(document.getElementById('Bedrijfsnaam').value == "") {
		alert("U heeft geen Bedrijfsnaam ingevuld");
		return false;
	} else if(document.getElementById('Adres').value == "") {
		alert("U heeft geen Adres ingevuld");
		return false;
	} else if(document.getElementById('Telefoon').value == "") {
		alert("U heeft geen Telefoon ingevuld");
		return false;
	} else if(document.getElementById('Datum').value == "") {
		alert("U heeft geen Datum ingevuld");
		return false;
	} else if(document.getElementById('Telefoon').value.length != 10) {
		alert("Het telefoonnummer moet 10 cijfers zijn.");
		return false;
	} else {
		alert("Bedankt voor uw bestelling!");
		return true;
	}

}

function doCalcGelato(first, second, result) {

	if(parseFloat(first) < 0) {
		first = 0;
	}

	document.getElementById(result).value = currency(parseFloat(first) * parseFloat(second));

  doCalcSubtotalGelato();
	doCalcTotalGelato();

}

function udatecalc()
{
  doCalcSubtotalGelato();
	doCalcTotalGelato();
}

function getCheckedValue(radioObj) 
{
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function doCalcSubtotalGelato() {

	subtotaal = 0;
	
	subtotaal = subtotaal+parseFloat(document.getElementById('ijsprijs' + getCheckedValue(document.forms['ijskar'].elements['hoeveel'])).value);
	
	//subtotaal = subtotaal+parseFloat(document.getElementById('bisquitprijs').value);
	
	subtotaal = subtotaal+parseFloat(document.getElementById('totaalhandkar').value);
	
	document.getElementById('subtotaal').value = currency(subtotaal);
	
	document.getElementById('btw').value = currency(0.06 * (parseFloat(document.getElementById('ijsprijs' + getCheckedValue(document.forms['ijskar'].elements['hoeveel'])).value)));

	document.getElementById('afhaalprijs').value = currency(parseFloat(document.getElementById('subtotaal').value) + parseFloat(document.getElementById('btw').value));
	
	document.getElementById('vooraf').value = currency(parseFloat(document.getElementById('borg').value) + parseFloat(document.getElementById('afhaalprijs').value));


	subtotaal = 0;
	//subtotaal = subtotaal+parseFloat(document.getElementById('totaalbisquit').value);
	//subtotaal = subtotaal+parseFloat(document.getElementById('totaalijs').value);

	document.getElementById('subtotaal2').value = currency(subtotaal);


	subtotaal = 0;
	subtotaal = subtotaal+parseFloat(document.getElementById('bezorgkostentotaal').value);
	subtotaal = subtotaal+parseFloat(document.getElementById('totaalkm').value);
	subtotaal = subtotaal+parseFloat(document.getElementById('totaalextradag').value);

	document.getElementById('subtotaal3').value = currency(subtotaal);

	doCalcBTW();

}

function doCalcTotalGelato() {

	totaal = 0;
	totaal = totaal+parseFloat(document.getElementById('vooraf').value);
	totaal = totaal+parseFloat(document.getElementById('totaal2').value);
	totaal = totaal+parseFloat(document.getElementById('totaal3').value);

	document.getElementById('totaal').value = currency(totaal);

}

function doCalcBTW() {
	price = parseFloat(document.getElementById('subtotaal2').value);

	document.getElementById('btw2').value = currency(price-(price-price*6/100));
	document.getElementById('totaal2').value = currency(price+price*6/100);

	price = parseFloat(document.getElementById('subtotaal3').value);

	document.getElementById('btw3').value = currency(price-(price-price*19/100));
	document.getElementById('totaal3').value = currency(price+price*19/100);

}

function aantalIceFormSmaken() {
  Aardbeien = parseInt(document.getElementById('Aardbeien').value);
  Appel = parseInt(document.getElementById('Appel').value);
  Banaan = parseInt(document.getElementById('Banaan').value);
  Bosbes = parseInt(document.getElementById('Bosbes').value);
  Chocolade = parseInt(document.getElementById('Chocolade').value);
  Citroen = parseInt(document.getElementById('Citroen').value);
  Mocca = parseInt(document.getElementById('Mocca').value);
  Pistache = parseInt(document.getElementById('Pistache').value);
  Rodebessen = parseInt(document.getElementById('Rodebessen').value);
  Sinaasappel = parseInt(document.getElementById('Sinaasappel').value);
  Straciataellavanille = parseInt(document.getElementById('Straciataellavanille').value);
  Vanille = parseInt(document.getElementById('Vanille').value);
  Meloen = parseInt(document.getElementById('Meloen').value);
  Yoghurtkersen = parseInt(document.getElementById('Yoghurtkersen').value);
  Malaga = parseInt(document.getElementById('Malaga').value);
  Walnoot = parseInt(document.getElementById('Walnoot').value);
  Hazelnoot = parseInt(document.getElementById('Hazelnoot').value);
  Tiramisu = parseInt(document.getElementById('Tiramisu').value);

  col1 = Aardbeien+Appel+Banaan+Bosbes+Chocolade+Citroen;
  col2 = Mocca+Pistache+Rodebessen+Sinaasappel+Straciataellavanille+Vanille;
  col3 = Meloen+Yoghurtkersen+Malaga+Walnoot+Hazelnoot+Tiramisu;
  aantalijs = (col1+col2+col3) - 3;

  if(aantalijs < 0) aantalijs = 0;
  document.getElementById('aantalijs').value = aantalijs;
  doCalc(aantalijs, 38, 'totaalijs');
}

function aantalGelatoSmaken() {
  Aardbeien = parseInt(document.getElementById('Aardbeien').value);
  Appel = parseInt(document.getElementById('Appel').value);
  Banaan = parseInt(document.getElementById('Banaan').value);
  Bosbes = parseInt(document.getElementById('Bosbes').value);
  Chocolade = parseInt(document.getElementById('Chocolade').value);
  Citroen = parseInt(document.getElementById('Citroen').value);
  Mocca = parseInt(document.getElementById('Mocca').value);
  Pistache = parseInt(document.getElementById('Pistache').value);
  Rodebessen = parseInt(document.getElementById('Rodebessen').value);
  Sinaasappel = parseInt(document.getElementById('Sinaasappel').value);
  Straciataellavanille = parseInt(document.getElementById('Straciataellavanille').value);
  Vanille = parseInt(document.getElementById('Vanille').value);
  Meloen = parseInt(document.getElementById('Meloen').value);
  Yoghurtkersen = parseInt(document.getElementById('Yoghurtkersen').value);
  Malaga = parseInt(document.getElementById('Malaga').value);
  Walnoot = parseInt(document.getElementById('Walnoot').value);
  Hazelnoot = parseInt(document.getElementById('Hazelnoot').value);
  Tiramisu = parseInt(document.getElementById('Tiramisu').value);

  col1 = Aardbeien+Appel+Banaan+Bosbes+Chocolade+Citroen;
  col2 = Mocca+Pistache+Rodebessen+Sinaasappel+Straciataellavanille+Vanille;
  col3 = Meloen+Yoghurtkersen+Malaga+Walnoot+Hazelnoot+Tiramisu;
  aantalijs = Math.ceil((col1+col2+col3) / 2);

  document.getElementById('aantalijs').value = aantalijs;
  doCalcGelato(aantalijs, '91.77', 'totaalijs');
}