function add(){
	$("#cartpicker").attr("action","");
	$("#cartpicker").submit();
	return false;
}

function add_goto_cart(lang){
	
	switch(lang){
		case 'nl':
			link = "nl/webshop/winkelmandje.html";
		break;
		case 'en':
			link = "en/webshop/winkelmandje.html";
		break;
		case 'es':
			link = "es/webshop/winkelmandje.html";
		break;
	}
	$('#cartpicker').attr("action",link);
	$('#cartpicker').submit();
	return false;
}

function addShop_nl(productid,productnaam,image){
	Shadowbox.open({
        content:    '<form action="" method="post" id="cartpicker"><div class="cartpic" style="background: url(\''+image+'\');"></div><div id="rightcolcart"><h1>'+productnaam+'</h1><div class="aantal"><div class="aantal_text">Aantal:</div><input type="text" name="quantity" value="1" /><input type="hidden" name="add_product" value="1" /><input type="hidden" name="productid" value="'+productid+'" /></div><div class="buttons"><div class="cartbutton"><a onclick="return add();" href="#">Voeg toe en winkel verder</a></div><div class="cartbutton" style="margin-left: 10px;"><a onclick="return add_goto_cart(\'nl\');" href="#">Voeg toe en bekijk mandje</a></div></div></div></form>',
		player:     "html",
        title:      "Voeg toe aan mandje",
        height:     150,
        width:      420
    });
	return false;
}

function addShop_en(productid,productnaam,image){
	Shadowbox.open({
        content:    '<form action="" method="post" id="cartpicker"><div class="cartpic" style="background: url(\''+image+'\');"></div><div id="rightcolcart"><h1>'+productnaam+'</h1><div class="aantal"><div class="aantal_text">Amount:</div><input type="text" name="quantity" value="1" /><input type="hidden" name="add_product" value="1" /><input type="hidden" name="productid" value="'+productid+'" /></div><div class="buttons"><div class="cartbutton"><a onclick="return add();" href="#">Add and continue</a></div><div class="cartbutton" style="margin-left: 10px;"><a onclick="return add_goto_cart(\'en\');" href="#">Add and check your order</a></div></div></div></form>',
		player:     "html",
        title:      "Add to order",
        height:     150,
        width:      420
    });
	return false;
}

function addShop_es(productid,productnaam,image){
	Shadowbox.open({
        content:    '<form action="" method="post" id="cartpicker"><div class="cartpic" style="background: url(\''+image+'\');"></div><div id="rightcolcart"><h1>'+productnaam+'</h1><div class="aantal"><div class="aantal_text">Cantidad:</div><input type="text" name="quantity" value="1" /><input type="hidden" name="add_product" value="1" /><input type="hidden" name="productid" value="'+productid+'" /></div><div class="buttons"><div class="cartbutton"><a onclick="return add();" href="#">Aņada y continue</a></div><div class="cartbutton" style="margin-left: 10px;"><a onclick="return add_goto_cart(\'es\');" href="#">Aņada y revise su compra</a></div></div></div></form>',
		player:     "html",
        title:      "Aņada a su compra",
        height:     150,
        width:      420
    });
	return false;
}
function deleteProduct(uid){
	$.get("../../shophandler.html", { action: "delete", deleteid: uid },
		function(data){
			$("#totalprice").html(data.totaal);
			$("#cartrow"+uid).slideUp();
		}, "json");
	return false;
}

function changeProduct(uid){
	aantal = $('#aantalp'+uid).val();
	$.get("../../shophandler.html", { action: "update", updateid: uid, aantal: aantal },
		function(data){
		$("#rowprice"+uid).html(data.rowprice);
		$("#totalprice").html(data.totaal);
		$("#stukprice"+uid).html(data.eachprice);
		//$("#cartrow"+uid).slideUp();
	}, "json");
}
function setShippingCosts(cost){
	
	$('#verzendkosten').html(cost);
        subtotaala = $('#subtotaal').html();

       subtotaala = subtotaala.replace(".", "");
       subtotaala = subtotaala.replace(",", ".");
       subtotaala = parseFloat(subtotaala);
	 
	transactioncostsa = $('#transactiekosten').html();
        transactioncostsa = transactioncostsa.replace(".", "");
        transactioncostsa = transactioncostsa.replace(",", ".");
        transactioncostsa = parseFloat(transactioncostsa);

        cost = cost.replace(".", "");
        cost = cost.replace(",", ".");
	shippingCost = parseFloat(cost);
	 
	totaala = shippingCost + subtotaala + transactioncostsa;
	$('#totaal').html(totaala.format(2,' ',','));
}

function setTransactionCosts(cost){
	
	 $('#transactiekosten').html(cost);
	 
	 subtotaal = $('#subtotaal').html();
	 subtotaal = subtotaal.replace(".", "");
     subtotaal = subtotaal.replace(",", ".");
	 subtotaal = parseFloat(subtotaal);

     transactionCost = cost;
     transactionCost = transactionCost.replace(".", "");
     transactionCost = transactionCost.replace(",", ".");
	 transactionCost = parseFloat(transactionCost);
	 
	 totaal = transactionCost + subtotaal;
	 $('#totaal').html(totaal.format(2,'.',','));
}

function verstuur(){
	$("#myform").submit();
	return false;
}

Number.prototype.format=function(decimalPoints,thousandsSep,decimalSep){
	 var val=this+'',re=/^(-?)(\d+)/,x,y;
	 if (decimalPoints!=null) val = this.toFixed(decimalPoints);
	 if (thousandsSep && (x=re.exec(val))){
	  for (var a=x[2].split(''),i=a.length-3;i>0;i-=3) a.splice(i,0,thousandsSep);
	  val=val.replace(re,x[1]+a.join(''));
	 }
	 if (decimalSep) val=val.replace(/\./,decimalSep);
	 return val;
	}
	if (typeof Number.prototype.toFixed!='function' || (.9).toFixed()=='0' || (.007).toFixed(2)=='0.00') Number.prototype.toFixed=function(f){
	 if (isNaN(f*=1) || f<0 || f>20) f=0;
	 var s='',x=this.valueOf(),m='';
	 if (this<0){ s='-'; x*=-1; }
	 if (x>=Math.pow(10,21)) m=x.toString();
	 else{
	  m=Math.round(Math.pow(10,f)*x).toString();
	  if (f!=0){
	   var k=m.length;
	   if (k<=f){
	    var z='00000000000000000000'.substring(0,f+1-k);
	    m=z+m;
	    k=f+1;
	   }
	   var a = m.substring(0,k-f);
	   var b = m.substring(k-f);
	   m = a+'.'+b;
	  }
	 }
	 if (m=='0') s='';
	 return s+m;
	}
