/**
* Enkelbutik Shopping Cart functions.
* @copyright 2009 Daniel Eneström
*/

function addToCart(product_id, variant_id, amount)
{
	if (variant_id == undefined) variant_id == 0;
	if (!onevariant && variant_id < 1)
	{
		var theString = new String(variants_label);
		alert("Du måste välja "+theString.toLowerCase()+" innan du kan lägga till produkten.");
		return;
	}
	
	addProductToCart(product_id, variant_id, amount);
}

function addProductToCart(product_id, variant_id, amount)
{	
	// Ajax tool init
	AjaxTool.clear();
	AjaxTool.url = '/ajax/addToCart.php';
	AjaxTool.addField('product',product_id);
	AjaxTool.addField('variant',variant_id);
	AjaxTool.addField('amount',amount);
	
	// Check if a response function is defined and if it is, set the AjaxTool response function
	if(typeof window.addToCartResponse == 'function')
	{
		// function exists, so we can use it
		AjaxTool.responseFunction = addToCartResponse;
	}
	AjaxTool.send();
}
function addPhotoToCart(product_id)
{	
	// Ajax tool init
	AjaxTool.clear();
	AjaxTool.url = '/ajax/addToCart.php';
	AjaxTool.addField('photo',product_id);
	
	// Check if a response function is defined and if it is, set the AjaxTool response function
	if(typeof window.addToCartResponse == 'function')
	{
		// function exists, so we can use it
		AjaxTool.responseFunction = addToCartResponse;
	}
	AjaxTool.send();
}
function removeProductFromCart(product_id, variant_id, amount)
{	
	// Ajax tool init
	AjaxTool.clear();
	AjaxTool.url = '/ajax/removeFromCart.php';
	AjaxTool.addField('product',product_id);
	AjaxTool.addField('variant',variant_id);
	AjaxTool.addField('amount',amount);
	
	// Check if a response function is defined and if it is, set the AjaxTool response function
	if(typeof window.removeFromCartResponse == 'function')
	{
		// function exists, so we can use it
		AjaxTool.responseFunction = removeFromCartResponse;
	}
	AjaxTool.send();
}
function addVoucher(voucher)
{	
	// Ajax tool init
	AjaxTool.clear();
	AjaxTool.url = '/ajax/addVoucher.php';
	AjaxTool.addField('voucher',voucher);
	
	// Check if a response function is defined and if it is, set the AjaxTool response function
	if(typeof window.addVoucherResponse == 'function')
	{
		// function exists, so we can use it
		AjaxTool.responseFunction = addVoucherResponse;
	}
	AjaxTool.send();
}
function goTestPay()
{
	$('checkoutForm_test').submit();
}
function goPay(method)
{
	if (method == undefined) method = "payson";
	
	//console.log("Payment method: "+method);
	//console.log("Test mode: "+Site.test_mode);
	
	if (method == "payson" && Site.test_mode)
	{
		$('checkoutForm_test').submit();
	}
	else if (method == "payson" && !Site.test_mode)
	{
		$('checkoutForm').submit();
	}
	else if (method == "dibs")
	{
		$('checkoutForm').submit();
	}
	else if (method == "invoice" || method == "part")
	{
		Klarna.createTransaction(method);
	}
}
function testFinishOrder()
{
	$('checkoutForm').action = "/testfinishorder.php";
	$('checkoutForm').submit();
}