

function showAlert(msg) {
	jQuery('html, body').animate({scrollTop:0}, 'fast'); 
	if(msg) {
		jQuery('#alertmsg').html(msg);
		var alerttimer = window.setTimeout(function () {
			 jQuery('#alertmsg').trigger('click');
		}, 6000);
		jQuery('#alertmsg').animate({height:  jQuery('#alertmsg').css('line-height') || '50px'}, 200).click(function () {
			window.clearTimeout(alerttimer);
			jQuery('#alertmsg').animate({height: '0'}, 200);
		});
	}
}


function emptyCart() {
	jQuery.post("/api.php"
				, {
					  "ctrl": 		"main"
					, "request": 	"cartreset"
				}
				, function(res) {
					 if(res.count == "0") {
					 	jQuery("#cartmenuinfo").html("");
					 	jQuery("#menuboxwinkelwagen").hide();
					 }
					 else {
					 	jQuery("#cartmenuinfo").html("("+res.count+")");
					 	jQuery("#menuboxwinkelwagen").show();
					 }
				}
				, "json"
	);
}

function addProduct(id, size) {
	jQuery.post("/api.php"
				, {
					  "ctrl": 		"main"
					, "request": 	"cartaddproduct"
					, "product": 	id
					, "size": 		size
				}
				, function(res) {
					 showAlert("Product is aan het winkelmandje toegevoegd. U wordt doorgestuurd...");
					 if(res.count == "0") {
					 	jQuery("#cartmenuinfo").html("");
					 	jQuery("#menuboxwinkelwagen").hide();
					 	setTimeout("document.location = '/winkelwagen';", 1000);
					 }
					 else {
					 	jQuery("#cartmenuinfo").html("("+res.count+")");
					 	jQuery("#menuboxwinkelwagen").show();
					 }
				}
				, "json"
	);
}

function delProduct(id) {
	jQuery.post("/api.php"
				, {
					  "ctrl": 		"main"
					, "request": 	"cartdelproduct"
					, "product": 	id
				}
				, function(res) {
					 showAlert("Product is uit het winkelmandje verwijderd.");
					 if(res.count == "0") {
					 	jQuery("#cartmenuinfo").html("");
					 	jQuery("#menuboxwinkelwagen").hide();
					 }
					 else {
					 	jQuery("#cartmenuinfo").html("("+res.count+")");
					 	jQuery("#menuboxwinkelwagen").show();
					 }
				}
				, "json"
	);
}

function delProductAll(id) {
	jQuery.post("/api.php"
				, {
					  "ctrl": 		"main"
					, "request": 	"cartdelproductall"
					, "product": 	id
				}
				, function(res) {
					 if(res.count == "0") {
					 	jQuery("#cartmenuinfo").html("");
					 	jQuery("#menuboxwinkelwagen").hide();
					 }
					 else {
					 	jQuery("#cartmenuinfo").html("("+res.count+")");
					 	jQuery("#menuboxwinkelwagen").show();
					 }
				}
				, "json"
	);
}

