/*
webshop milafire

*/

function AddToCart(id)
{
	var id = arguments[0];
	var aantal = arguments[1];
	var update = arguments[2];
	if(update === undefined)
	{
		update = "nieuw";
	}
	if(aantal === undefined)
	{
		aantal = "1";
	}
	if(isInt(aantal))
	{
		if(id != '')
		{
			var product_id = id;
			$.post("webshop/cart.php", { productid: product_id, aantal: aantal, update: update}, function(data) {
				$(".cartBox").replaceWith(data);
				Cufon.now(); 
			});
		}
	}else
	{
		jAlert(aantal+' is geen getal, voer alleen een getal in','Winkelwagen');
	}
}

function clearCart()
{
	$.post("webshop/cart.php", { clearcart: 1 }, function(data) {
		$(".cartBox").replaceWith(data);
		Cufon.now();
	});
}

function deleteFromCart(id)
{
	var id = arguments[0];
	var remove = arguments[1];
	if(remove === undefined)
	{
		remove = "1";
	}
	$.post("webshop/cart.php", { productid: id, remove: remove }, function(data) {
		$(".cartBox").replaceWith(data);
		Cufon.now(); 
	});
}

function updateCart(id)
{
	
	aantal = $("#update-"+id).val();
	if(aantal == '0')
	{
		result = deleteFromCart(id,"2");
	}else
	{
		result = AddToCart(id,aantal,'update');
	}
}

function removeItem(id)
{
	$("#prod-"+id+" .aantal").val('0');
	$("#submit").click();
}

/* shop sorteer functies */

function changeGroep()
{
	$("#producten").submit();
}

function betaalMethode(methode)
{
	var betaalmethode = methode;
	if(betaalmethode == 'ideal')
	{
		$('.idealBox').show();
		$('#bestelForm').attr('action','afrondenideal.php');
		$('#submitknop').val('Afrekenen');
	}else if(betaalmethode == 'factuur')
	{
		$('.idealBox').hide();
		$('#bestelForm').attr('action','afrondenfactuur.php');
		$('#submitknop').val('Plaats uw bestelling');
	}
}

function emptySearch()
{
	$('#search').attr('value', '');
}

function checkLength()
{
	var searchval = $('#search').val();
	if(searchval.length < '3')
	{
		jAlert('Uw zoek criteria moet langer zijn dan 3 karakters','Search');
		return false;
	}else
	{
		return true;
	}
	
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=900');");
}

/* utils */
function isInt(x)
{
	var y = parseInt( x );
	if ( isNaN( y ) ) return false;
	return x==y && x.toString()==y.toString();
}


