pricetable = new Array();
pricetable[2] = "2.20";
pricetable[3] = "4.02";
pricetable[4] = "8.00";

//niet versturen
pricetable[0]=0;


function updatePrice () {

	var dispatchField = document.getElementById('dispatchmethod');
	var priceField = document.getElementById('pricetag');
	var priceformField = document.getElementById('pricefield');

	updateDivs(dispatchField.value);

	var price = "12.50";

	if (dispatchField.value == "" || dispatchField.value == "1") {
		priceField.innerHTML = "<b>&euro;" + price + "</b>";
		priceformField.value = price;
		return;
	} else {
		total = round_decimals((parseFloat(price)+parseFloat(pricetable[dispatchField.value])),2);
		priceField.innerHTML = "&euro;" + price + " + &euro;" + pricetable[dispatchField.value] + " = <b>&euro;" + total +"</b>";
		priceformField.value = total;
	}
}


function updateDivs (dispatchvalue) {
	var adres = document.getElementById('steps5');
	var country = document.getElementById('steps6');

	if (dispatchvalue == "" || dispatchvalue == "1") {
		adres.style.display = "none";
		country.style.display = "none";
	} else if (dispatchvalue == "2") {
		adres.style.display = "block";
		country.style.display = "none";
	} else if (dispatchvalue > 2) {
		adres.style.display = "block";
		country.style.display = "block";
	}
}


function updatePrice_paypal () {

	var dispatchField = document.getElementById('dispatchmethod');
	var dispatchSpan = document.getElementById('dispatchspan');
	var priceField = document.getElementById('pricespan');

	updateDivs_paypal(dispatchField.value);

	var price = "13.30";

	if (dispatchField.value == "") {
		dispatchSpan.innerHTML = "?";
		priceField.innerHTML = "?";
		return;
	} else {
		total = round_decimals((parseFloat(price)+parseFloat(pricetable[dispatchField.value])),2);
		dispatchSpan.innerHTML = "<b>" + pricetable[dispatchField.value] + "</b>";
		priceField.innerHTML = "<b>&euro;" + total + "</b>";
		
	}
}


function updateDivs_paypal (dispatchvalue) {
	var paypal1 = document.getElementById('paypal1');
	var paypal2 = document.getElementById('paypal2');
	var paypal3 = document.getElementById('paypal3');

	if (dispatchvalue == "") {
		paypal1.style.display = "none";
		paypal2.style.display = "none";
		paypal3.style.display = "none";
	} else if (dispatchvalue == "2") {
		paypal1.style.display = "block";
		paypal2.style.display = "none";
		paypal3.style.display = "none";
	} else if (dispatchvalue == "3") {
		paypal1.style.display = "none";
		paypal2.style.display = "block";
		paypal3.style.display = "none";
	} else if (dispatchvalue == "4") {
		paypal1.style.display = "none";
		paypal2.style.display = "none";
		paypal3.style.display = "block";
	}
}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}


function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}


function numeralsOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 49 || charCode > 52)) {
        return false;
    }
    return true;
}



