var oldamount;

function swtch(objMenu) {
	if (objMenu.style.display == 'none') {
		objMenu.style.display = '';
	} else {
		objMenu.style.display = 'none';
	}
}

function formatCurrency(num) {
	if (num<0)
		num=0;
	cents = num%100; //MODULO
	num = Math.floor(num/100).toString();
	if (cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+'.'+
	num.substring(num.length-(4*i+3));
	return (num + ',' + cents);
}

function UpdateCosts(old, id, ppp, amount) { 
	//entrycheck
	// if <amount> contains no proper amount, reset it to <old>
	// emtpy is permitted too (=zero)
	if (amount >= 0) {
		amount = Number(amount);
		amount = parseInt(amount);
	}
	else {
		alert('Ongeldige waarde.');
		return old;
	}
	
	//price per piece (euro), count
	document.body.style.cursor='wait';
	var ote = getPage('/cart/update.asp?id='+id+'&n='+amount);
	document.getElementById('totaleuro').value=formatCurrency(ote);
	if(amount==0){
		document.getElementsByName(id)[0].value='';
	}else{
		document.getElementsByName(id)[0].value=amount;
	}
	document.body.style.cursor='auto';
	
	return 'OK';
}

function showimg(url) {
	b = window.open(url,'productinfo','height=700,width=740,menubar=no,scrollbars=yes,resizable=yes');
	b.focus();
}

function bekijkinhoud() {
	top.location.href='/cart/bekijkinhoud.asp';
}

function bestel() {
	top.location.href='/cart/bestel.asp';
}

function doOnFocus(o) {
	o.style.backgroundColor='#ffffff';
	o.style.fontWeight='bold';
	oldamount=o.value;
}

function doOnBlur(o) {
	o.style.backgroundColor='transparent';
	o.style.fontWeight='normal';
}

function doOnChange(o) {
	o.style.backgroundColor='transparent';
	o.style.fontWeight='normal';
	r=UpdateCosts(oldamount, o.name, o.id, o.value);
	if (r!='OK') {
		o.value=r;
	}
}

