function addtocart(product) {
	$.post("modules/functions/addtocart.php", { id: product },
	   function(data){
	     return updatecart();
	   });
}

function updateproduct(product) {
	optionvalue = $('#antal'+product).val();
	$.post("modules/functions/updatecart.php", { id: product, value: optionvalue },
	   function(data){
	     return updatecart();
	   });
}

function removeproduct(product) {
	$.post("modules/functions/removecart.php", { id: product },
	   function(data){
	     return updatecart();
	   });
}

function updatecart() {
	$.ajaxSetup({cache: false});
	$.ajax({
	  url: 'modules/functions/showcart.php',
	  success: function(data) {
		$('#cart').html(data);
	  }
	});
}

function calculateprice() {
	var datestart = $('#hamtaar').val()+'-'+$('#hamtamanad').val()+'-'+$('#hamtadag').val();
	var dateend = $('#lamnaar').val()+'-'+$('#lamnamanad').val()+'-'+$('#lamnadag').val();
	var error = '';
	if ($('#lamnamanad').val() < $('#hamtamanad').val()) {
		document.getElementById('lamnamanad').selectedIndex = document.getElementById('hamtamanad').selectedIndex;
		error = 1;
	}
	if ($('#lamnamanad').val() == $('#hamtamanad').val()) {
		if ($('#lamnadag').val() < $('#hamtadag').val()) {
			document.getElementById('lamnadag').selectedIndex = document.getElementById('hamtadag').selectedIndex;
			error = 1;
		}
	}
	
	if (error == 1) {
		
	} else {
		$.ajax({
	  		url: 'modules/functions/calculate.php', data: 'datestart='+datestart+'&dateend='+dateend,
	  		success: function(data) {
	    		$('#totalprice').html(data);
	  		}
		});
	}
}

function updatecartdate() {
	$.ajax({
	  url: 'modules/functions/showcart.php', data: 'dateok=1',
	  success: function(data) {
	    $('#cart').html(data);
	  }
	});
}

