// JavaScript Document
// calculate price based on quantity
function changeQty(change){
    var currentQty = parseInt(document.getElementById('quant').value); // Where quant is the id of your quantity input field. Gets value of currentQty field
    
    switch (change) {
        case 'add':
            currentQty += 1
            document.getElementById('quant').value = currentQty
            calculate()
            break
        case 'subtract':
            if (currentQty > 1) { // only subtract if qty is greater than one
                currentQty -= 1
                document.getElementById('quant').value = currentQty
                calculate()
            }
            break
        case 'field':
            if (currentQty >= 0) {
                window.setTimeout('calculate()', 500)
            }
            break
    }
}
function calculate(){
    
    
    var preco=document.getElementById('base_pvp').value.substring(1).replace(/,/, ".");
    var promocao=document.getElementById('base_promocao').value.substring(1).replace(/,/, ".");
    var poupa=document.getElementById('base_poupa').value.substring(1).replace(/,/, ".");
     
    var startPVP = parseFloat(preco);
    var startPROMO = parseFloat(promocao);
    var startPOUPA = parseFloat(poupa); 

    var currentQty = parseInt(document.getElementById('quant').value); 
    

        var qtyPVP = startPVP * currentQty // Calculate the price.
        var qtyPROMO = startPROMO * currentQty // Calculate the price.
        var qtyPOUPA = startPOUPA * currentQty // Calculate the price.

        var qtyPVP = qtyPVP.toFixed(2); // Only allow 2 decimals. I'll let you add rounding features up or down.
        var qtyPROMO = qtyPROMO.toFixed(2);
        var qtyPOUPA = qtyPOUPA.toFixed(2);


    
    document.getElementById('pvp').innerHTML= '€' +  String(qtyPVP).replace(".",",");
    document.getElementById('promocao').innerHTML= '€' +  String(qtyPROMO).replace(".",",");
    document.getElementById('poupa').innerHTML= '€' +  String(qtyPOUPA).replace(".",",");
    
}
