function clear_add_to_cart(productID)
{
	document.getElementById('cart_add_' + productID).innerHTML = '';
	document.getElementById('cart_add_' + productID).style.display = 'none';
}

function add_to_cart(colourID, productID, update)
{
	var qtyEle = document.getElementById('qty_' + productID);
		
	if(!qtyEle) {
		alert('Sorry but an error occoured whilst attempt to retrieve that colour.');
		return false;
	}
	else if(qtyEle.value == 0) {
		alert('Please enter a quantity before adding to your cart');
		return false;
	}
	
	var result = addToCart(colourID, productID, qtyEle.value, {type: 'r'});
	switch(result) {
		case 1 :
			alert('Please enter a valid quantity');
		break;
		
		case 2: 
			alert('An error occoured whilst attempting to add the item to your cart');
		break;
		
		default:
			show_cart(productID);
			clear_add_to_cart(productID);
	}
}

function update_product(colourID, productID)
{
	var qtyEle = document.getElementById('qty_' + productID);

	var result = addToCart(colourID, productID, qtyEle.value, {type: 'r'});
	switch(result) {
		case 1 :
			alert('Please enter a valid quantity');
		break;
		
		case 2: 
			alert('An error occoured whilst attempting to add the item to your cart');
		break;
		
		default:
			show_cart(productID);
			clear_add_to_cart(productID);
	}
}

function show_add_to_cart(colourID, productID)
{
//	showLoader(productID);
	
	if(!document.getElementById('cart_add_' + productID)) {
		alert('Sorry but an error occoured whilst attempt to retrieve that colour.');
		return false;
	}
	
	// fetchCartAdd(colourID, productID, 'type=r,target=verso_cart_'+productID);
	document.getElementById('cart_add_' + productID).style.display='block';
	showAddToCart(colourID, productID, {target: 'cart_add_'+productID});
	
//	hideLoader(productID);
	return false;
}

function show_cart(productID)
{
	if(!document.getElementById('cart_'+productID)) {
		alert('An error occoured whilst trying to display your cart');
		return false;
	}
	
	document.getElementById('cart_'+productID).style.display = 'block';
	showCart(productID, {target: 'cart_' + productID});
}

function showLoader(productID) {	
	// calculate loader's position
	var container = document.getElementById('prod_container'+productID);	
	var loader = document.getElementById('loader'+productID);
	
	// Show loader
	loader.style.display = 'block';
	
	// calculate loader position
	var pos = (container.clientHeight - loader.clientHeight) / 2;
	loader.style.marginTop = pos+'px';	
}

function hideLoader(productID) {	
	var loader = document.getElementById('loader'+productID);
	loader.style.display = 'none';
}