var overviewMode = 'overview';

function show_tooltip(tooltipID,msg,tooltipW,offsetX,offsetY) {
	var tooltipDIV = document.createElement('div');
	tooltipDIV.setAttribute('id', tooltipID);
	tooltipDIV.style.display = "block";
	document.body.appendChild(tooltipDIV);

	if (tooltipW != null) {document.getElementById(tooltipID).style.width = tooltipDIV_width + "px";}
	if (offsetX != null) {document.getElementById(tooltipID).style.left = ((offsetX - tooltipDIV_width) + "px");}
	if (offsetY != null) {document.getElementById(tooltipID).style.top = (offsetY + "px");}

	document.getElementById(tooltipID).innerHTML = msg;
}

function hide_tooltip(tooltipID)
{
	var tooltipDIV = document.getElementById(tooltipID);
	if (tooltipDIV != null)
	{
		document.body.removeChild(tooltipDIV);
	}
}

function updateCartCounter(cartCounter)
{
	hide_tooltip('loading');
	switch (cartCounter) {
		case 0:	window.location = overviewMode;
		break;
		case 1:	cartCounter = '1 product';
				document.getElementById('totalProducts').innerHTML = cartCounter;
		break;
		default: cartCounter = cartCounter + ' producten';
				 document.getElementById('totalProducts').innerHTML = cartCounter;
		break;
	}
}

function updateCart(cartContent)
{
	document.getElementById('cartContent').innerHTML = cartContent;
	x_recalculateCartCounter(updateCartCounter);
}

function recalculateCart(productid, productcount)
{
	show_tooltip('loading','<img src="/public/images/loadingAnimation.gif">',null,null,null);
	x_recalculateCart(productid,productcount,updateCart);
}
