﻿$(document).ready(function() {
    handlePrices();
    //$('#ctl00_ctrlCurrencyList').css('display', 'none');
    //$('#ctl00_ctrlLocaleList').css('display', 'none');

    $("#cmdSubmit[type='button']").attr('value', 'Verzenden');

    //Hack for Disable cursor hand on products (should be in css)
    //$('.content_products img').css('cursor', 'default');

    $('#ctl00_PageContent_ctrlShoppingCart_imgShoppingCartTab').css('display', 'none');

    //Hide column paying methods for account.aspx
    $('#ctl00_PageContent_pnlOrderHistory table table table td:nth-child(3)').hide();

    //Use fancyzoom om product icon images
    $('div.largeimage a').fancyZoom({ scaleImg: true, closeOnClick: true });

    //Uw accountgegevens tab op account.aspx verwijderen (zoals adres etc)
    $('table.UwAccountgegevens tr:eq(2)').css('display', 'none');
    $('table.UwAccountgegevens tr:eq(3)').css('display', 'none');
    $('table.UwAccountgegevens tr:eq(4)').css('display', 'none');
    $('table.UwAccountgegevens tr:eq(7)').css('display', 'none');
    //$('table.UwAccountgegevens tr:eq(8)').css('display', 'none');
    //$('table.UwAccountgegevens tr:eq(8)').css('display', 'none');

});


function roundNumber(num) {
	var s = num;
	s="" + s;
	var l=s.length;

	var p1=(s.substring(0,l-2));
	var p2=(s.substring(l-2));
	if(p1=="") p1="0";
	return p1 + "," + p2;
}
function handlePrices() {
	var $p=$("table.content_products>tbody>tr>td>table, table.content_products_simple");	//tables for products

	$(".SizeText").val("-,-");
	

	$p.each(
		function() {
			var $t=$(".ProductNameText", this);
//			alert("x" + $t.html() + "x");

			var $s=$(".SizeText", this); //pulldown for selecting size
			var $vp=$(".variantprice", this); //span for displaying price...
			var bp=$vp.html();
//if(console) console.log("1-----" + bp);

			if(bp) {
				bp=bp.split("&nbsp;")[1];
				bp=bp.split(" ")[1];
//if(console) console.log("2-----" + bp);
				bp=bp.replace(",", "");
//if(console) console.log("3-----" + bp);
				bp=parseInt(bp, 10);
//if(console) console.log("4-----" + bp);
				$vp.data("basisprijs", bp);						

				if($s.length==1) {
					$vp.html(" Prijs per stuk: - selecteer eerst een formaat -");
				} else {
					$vp.html($vp.html().replace("Basisprijs", " Prijs per stuk"));
				}



				var $o=$(".SizeText option", this);

				$o.each(
					function(){
						var pd=$(this).attr("value");
//if(console) console.log(pd);
						if((pd!="-,-") && (pd.indexOf("[")>0) && (pd.indexOf("]")>0)) {
							pd=pd.split("[")[1];
		
							pd=pd.split("]")[0];
	
							pd=parseFloat(pd.replace(".", "")); //Pricedifference
							
							var p=bp+pd;
//if(console) console.log(p);
							var t=$(this).text();
							t=t.split("[")[0];
							
							t=t + "[&euro; " + roundNumber(p) + "]";
							$(this).html(t);
						}
					}
				);	


				$s.change(
					function() {
						var pd=$(this).attr("value");
						if(pd=="-,-") {
							$vp.html(" Prijs per stuk: - selecteer eerst een formaat -");
						} else {
							pd=pd.split("[")[1];
							pd=pd.split("]")[0];
							pd=parseFloat(pd.replace(".", "")); //Pricedifference
							var p=bp+pd;
							$vp.data("prijs", roundNumber(p));
							$vp.html(" Prijs per stuk: &euro; " + roundNumber(p));
						}
					}
				);
			}
		}
	);	
	
}
