function refresh() {
	window.location.reload(true);
}

function aftellen(secs, spanid, dispmin, divje) {
	spantje = document.getElementById(spanid);
	divje2 = document.getElementById(divje);
	
	if(dispmin) {
		mins = parseInt(secs / 60);
		secs = (secs % 60);
	} else {
		mins = 0;
	}

	teldoor(mins, secs, spantje, dispmin, divje2);
}

function borg(borg, spanid, prijs) {
	span2 = document.getElementById(spanid);
	borgteller(borg, span2, prijs);
}

function borgteller(borg, span, prijs) {
	stop = 0;
	borg = borg-prijs;
	secs = borg/prijs;
	if ( secs == 0 ) {
		stop = 1;
	}
	span.innerHTML = '&euro;' + number_format(borg, 0, ',', '.') + ',-';
	if(!stop) {
		setTimeout(function(){borgteller(borg, span, prijs)}, 1000);
	}
}

function teldoor(mins, secs, span, dispmin, div) {
	stop = 0;
	secs--;
	
	if(!dispmin){
		if(secs <= 0){
			stop = 1;
			div.style.display = 'none';
		}
	} else {
		if(secs == 0 && mins == 0) {
			refresh();
			return;
		}
	}
	
	if(dispmin) {
		if(secs < 0) {
			mins--;
			secs = 59;
		}
	}
	
	if(dispmin) { 
		span.innerHTML = mins + (mins!=1?' minuten en ':' minuut en ') + secs + (secs!=1?' seconden':' seconde') + '&nbsp;';
	} else {
		span.innerHTML = secs + ' sec';
	}

	if(!stop) {
		setTimeout(function(){teldoor(mins, secs, span, dispmin, div)}, 1000);
	}
}

/* Made by Mathias Bynens <http://mathiasbynens.be/> */
function number_format(a, b, c, d) {
 a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
 e = a + '';
 f = e.split('.');
 if (!f[0]) {
  f[0] = '0';
 }
 if (!f[1]) {
  f[1] = '';
 }
 if (f[1].length < b) {
  g = f[1];
  for (i=f[1].length + 1; i <= b; i++) {
   g += '0';
  }
  f[1] = g;
 }
 if(d != '' && f[0].length > 3) {
  h = f[0];
  f[0] = '';
  for(j = 3; j < h.length; j+=3) {
   i = h.slice(h.length - j, h.length - j + 3);
   f[0] = d + i +  f[0] + '';
  }
  j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  f[0] = j + f[0];
 }
 c = (b <= 0) ? '' : c;
 return f[0] + c + f[1];
}