function setSubItemActive(id) {
	$('#subMenuid_'+id).css('list-style-type', 'disc');
	$('#subMenuid_'+id+' a').css('text-decoration', 'none');
} 

function getOptions() {
		var colorValue = $('select[name="option_color"]').val();
		var typeValue = $('select[name="option_type"]').val();
		var sizeValue = $('select[name="option_size"]').val();
		
		var options = '';
		if(colorValue) { options+= colorValue+';'; }
		if(typeValue) { options+= typeValue+';'; }
		if(sizeValue) { options+= sizeValue+';'; }
		
		return options;
}

// add item to cart
function addToCart(id,b_subItem) {
	qty = $('input:text[name=articleQty_' + id + ']').val();
	if(!qty) {qty =1;}
	
	if(b_subItem) {
		var options = getOptions();
	} else {
		var options = '';
	}

	$.ajax({ url: "" + URL + "/pages/Webshop/shopcart_functions.php?action=addToCart&id=" + id + "&options=" + options + "&qty=" + qty + "", success: function(data){		
		var cartUpdate = eval('(' + data + ')');
		
		$('#introBlock').css('display','none');
		$('#cartBlock').css('display','block');
		$('#itemCounter').html(cartUpdate['cartDetails'][0].totalitems).hide().fadeIn(1500);
		$('#cartTotal').html(cartUpdate['cartDetails'][0].total).hide().fadeIn(1500);			
		
		$.fancybox(
		'<img src="'+URL+'/includes/gui/img/cartApplyed.png" align="left"><h3>Artikel toegevoegd</h3><p>Het artikel is succesvol toegevoegd aan uw winkelwagentje.</p><input onclick="window.location=\''+URL+'/Webshop/winkelwagen\';" type="button" value="Naar winkelwagentje"></input>',
		{
        	'autoDimensions'	: false,
			'width'         		: 350,
			'height'        		: 150,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
		}
		);
		
		setTimeout ( "$.fancybox.close()", 3000 );
	}});
}

function changeQty(itemId,s_subItem,newQty) {

	if(newQty == 'fieldvalue') {
		var newQty = $('input:text[name=qty_'+itemId+'_'+s_subItem+']').val();
	}
	
	if(s_subItem == '' || s_subItem == 0) {
		var subItemgetvalue = 'false';
	} else {
		var subItemgetvalue = s_subItem;
	}
	$.ajax({ url: "" + URL + "/pages/Webshop/shopcart_functions.php?action=changeQty&itemId=" + itemId + "&subid=" + subItemgetvalue + "&qty=" + newQty + "", success: function(data){

		var cartUpdate = eval('(' + data + ')');
		
		if(cartUpdate['updateDetails'][0].errors == 0) {
			//alert('geenfout');
			
			$('input:text[name="qty_'+itemId+'_'+s_subItem+'"]').val(cartUpdate['updateDetails'][0].newQty);
			$('div[id="cartItemPrice_'+itemId+'_'+s_subItem+'"]').html('&euro; ' + cartUpdate['updateDetails'][0].newSubTotal);
			$('#cartTotalAmount').html('Totaal: &euro; ' + cartUpdate['updateDetails'][0].newTotal);
		} else {
			//alert('fouten');
			$('input:text[name=qty_'+itemId+'_'+s_subItem+']').val(cartUpdate['updateDetails'][0].newQty);
		}
	}});

}

// remove an item from the cart
function removeFromCart(id,subItemId) {

	if(subItemId == '' || subItemId == 0) {
		var subItemgetvalue = 'false';
	} else {
		var subItemgetvalue = subItemId;
	}
	
	$("div[id='cartItem_"+id+"_"+subItemId+"']").fadeOut("slow");

	//alert(id+'-'+subItemId);

	$.ajax({ url: "" + URL + "/pages/Webshop/shopcart_functions.php?action=removeFromCart&id="+id+"&subid="+subItemgetvalue+"", success: function(data){
		var total = data;
		
		if(total == 0) {
		
			$('#cartItems').find('#cartIsEmpty').css('display', 'block');
			$('#cart').find('#cartTotalAmount').html("Totaal: &euro; 0.00");	
			$('#cart').find('#checkoutButton').css('display','none');
			
		} else {
		
			$('#cart').find('#cartTotalAmount').html("Totaal: &euro; " + total + "");
		
		}

	}
	});
	
	return false;
}

// empty the cart
function emptyCart()
{
	$.ajax({ url: "" + URL + "/pages/Webshop/shopcart_functions.php?action=emptyCart", success: function(data){
			if (data == 1)
			{
				// update the cart's total amount and contents
				$("#cartItems div[id^='cartItem']").fadeOut(1500);
				$('#cartItems').find('#cartIsEmpty').css('display', 'block');
				
				$('#cart').find('#cartTotalAmount').html("Totaal: &euro; 0.00");
				$('#cart').find('#checkoutButton').css('display','none');
			}
		}
	});
	return false;
}
