function removeAllOptions(pcnt) {
    
    if (document.getElementById('property_select_' + pcnt) && document.getElementById('property_select_' + pcnt).options) {
        var i
        optionCount = document.getElementById('property_select_' + pcnt).options.length-1
        for(i = optionCount; i >= 0; i--) {
            document.getElementById('property_select_' + pcnt).remove(i)
        }
        var optn = document.createElement('option')
        optn.text = '- Maak uw keuze -'
        optn.value = 0
        document.getElementById('property_select_' + pcnt).options.add(optn)
        
        removeAllOptions(pcnt + 1);
    }
}


function changeOptions(prod_id, prpr_id, pcnt, pppr_id, queryString) {
    
    if (document.getElementById('property_' + (pcnt + 1))) {
        if (pppr_id != 0) {
            removeAllOptions(pcnt + 1)
            var URL = SITEBASE + '/include/ajax/loadOptions.php?prod_id=' + prod_id + '&prpr_id=' + prpr_id + '&pcnt=' + pcnt + queryString
            // alert(URL);
            ASyncGet(URL, 'property_' + (pcnt + 1))
        } else {
            removeAllOptions(pcnt + 1)
        }
        calCulatePrice();
    }
}

function calCulatePrice() {
    document.getElementById('price').value = ProdPrice;
    
    // Als het GEEN actieproduct is dan gaan we de prijs opnieuw berekenen
    if (ActionProduct == 0) {
        
        for (var p = 0; p < propsArray.length; p++) {
            pppr_id = document.getElementsByName('prop_' + propsArray[p])[0].value
            if (pppr_id != 0) {
                
                calculator = prodOptionsInProd[pppr_id]['cal']
                value = prodOptionsInProd[pppr_id]['val']
                if (calculator != 0 && value != 0) {
                    
                    price = document.getElementById('price').value
                    var newPrice = 0;
                    
                    switch(calculator) {
                        case '-':
                            newPrice = parseInt(price) - parseInt(value)
                        break;
                        case '+':
                            newPrice = parseInt(price) + parseInt(value)
                        break;
                        case '*':
                            newPrice = parseInt(price) * parseInt(value)
                        break;
                        case '/':
                            newPrice = parseInt(price) / parseInt(value)
                        break;
                    }
                    
                    newPrice = newPrice.toFixed(2);
                    document.getElementById('price').value = newPrice
                }
            }
        }
    }
    
    pieceprice = document.getElementById('price').value / document.getElementById('pieces').value;
    pieceprice = pieceprice.toFixed(2);
    
    document.getElementById('prodPricePiece').innerHTML = 'Prijs per stuk: &euro; ' + pieceprice.replace('.', ',');
    document.getElementById('prodPrice').innerHTML = '&euro; ' + document.getElementById('price').value.replace('.', ',');
}


function doOrderProduct() {
    var err = 0
    
    for (var p = 0; p < propsArray.length; p++) {
        if (document.getElementsByName('prop_' + propsArray[p])[0].value == 0) {
            err = 1;
        }
    }
    
    if (p == 0) {
        err = 2;
    }
    
    if (err == 1) {
        alert('Maak aub bij alle opties een keuze.');
    } else {
        if (err == 2) {
            alert('Dit product is niet op voorraad.');
        } else {
            calCulatePrice();
            document.getElementById('orderProduct').submit();
        }
    }
}





