function cartAdd() {
    $.ajax({
        url: $("#shoppingcart_url").val() + 'add/' + $("#product_id").val(),
        type: 'GET',
        data: { 
                'amount'    : $("#amount").val(), 
                'product'   : $("#product_name").val(),
                'url'       : $("#shoppingcart_url").val()
              },
        dataType: 'html',
        timeout: 1000,
        error: function(){
            alert('Error loading HTML document');
        },
        success: function(html){
            $("#adddialog").html(html); 
        }
    });
}

function cartEdit() {
    window.location.href = $("#shoppingcart_url").val() + 'edit/' + $("#product_id").val() + "/" + $("#amount").val();
}

function toggleDelivery(_obj) {
    if (_obj.checked) {
        $("#deliverycontainer").slideUp();
    } else {
        $("#deliverycontainer").slideDown();
    }
}

function toggleOther(_obj) {
    if (_obj.options[_obj.selectedIndex].value == 'Anders, namelijk...') {
        $("#othercontainer").show();
        _obj.blur();
        $("#othercontainer").focus();
    } else {
        $("#othercontainer").hide();
        $("#othercontainer").blur();
    }
}

function checkOrderForm(_form) {
    
    if (!$("#shippingmethod").val()) {
        alert("U heeft het volgende veld niet ingevuld: verzendkosten");
        $("#shippingmethod").focus();
        return false;
    }
    
    if (!$("#email").val()) {
        alert("U heeft het volgende veld niet ingevuld: email");
        $("#email").focus();
        return false;
    }
    
    if (!document.getElementById("conditions").checked) {
        alert("U moet akkoord gaan met onze algemene voorwaarden");
        $("#conditions").focus();
        return false;
    }
    
    return true;
}

$(function() {
    if (/addtocart$/.test(window.location.hash)) {
        $('a#orderbutton').click();
    }
});
