$(document).ready(function() {
    $('a.colorbox').colorbox({'photo':'true','opacity':'0.5','close':'Sluiten','next':'Volgende','previous':'Vorige','current':'Afbeelding {current} van {total}'});

    $("div.account form table input[name='number']").blur(function () {
        removeNumberFromStreet();
    });

    $("div.account form table input[name='numberadd']").blur(function () {
        removeNumberFromStreet();
    });

    $("select[name='country']").change(function(e) {
        $("input[name='useown']").removeAttr("checked");
        $country = $(this).val();
        $.getJSON('actions/ajax/getCartPrices.php', {'country':$country}, function(data) {
            $(".shipping_cost").html(data.shippingCost);
            $(".grandTotal").html(data.grandTotal);
        });
    });

});

function removeNumberFromStreet() {
    $street = $("div.account form table input[name='street']").val();
    $number = $("div.account form table input[name='number']").val();
    $numberAdd = $("div.account form table input[name='numberadd']").val();
    $numberInclAdd  = $number+$numberAdd;
    $ending = $street.substr(($numberInclAdd.length*-1));
    if($ending==$numberInclAdd) {
        $newVal = $("div.account form table input[name='street']").val();
        $("div.account form table input[name='street']").val($newVal.slice(0,$newVal.length-($ending.length+1)));
    }
}
