<!--

/* The decimal rounding script is Copyright (c) Paul McFedries and 
Logophilia Limited (http://www.mcfedries.com/).
Permission is granted to use this script as long as 
this Copyright notice remains in place.*/

function round_decimals(original_number) {
	var decimals = 2;
    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 berechne(){

if (ordercd.waehrung.value == "EUR") {
var preis_best_of = 18;
var preis_christmas_live = 15;
var preis_spiritual_inspiration = 15;
var preis_summertime = 15;
var preis_amazinggospel = 12;
var preis_centurycelebration = 12;
var preis_itschurchtime = 12;
var preis_thesoulofgospel = 10;
var preis_oletimereligion = 10;
var preis_liveinconcert = 10;
}

if (ordercd.waehrung.value == "CHF") {
var preis_best_of = 35;
var preis_christmas_live = 30;
var preis_spiritual_inspiration = 30;
var preis_summertime = 30;
var preis_amazinggospel = 25;
var preis_centurycelebration = 25;
var preis_itschurchtime = 25;
var preis_thesoulofgospel = 20;
var preis_oletimereligion = 20;
var preis_liveinconcert = 20;
}

// Berechne Betrag für jede CD auf 2 Kommastellen
ordercd.total_best_of.value = round_decimals(ordercd.best_of.value * preis_best_of);
ordercd.total_christmas_live.value = round_decimals(ordercd.christmas_live.value * preis_christmas_live);
ordercd.total_spiritual_inspiration.value = round_decimals(ordercd.spiritual_inspiration.value * preis_spiritual_inspiration);
ordercd.total_summertime.value = round_decimals(ordercd.summertime.value * preis_summertime);
ordercd.total_amazinggospel.value = round_decimals(ordercd.amazinggospel.value * preis_amazinggospel);
ordercd.total_centurycelebration.value = round_decimals(ordercd.centurycelebration.value * preis_centurycelebration);
ordercd.total_itschurchtime.value = round_decimals(ordercd.itschurchtime.value * preis_itschurchtime);
ordercd.total_thesoulofgospel.value = round_decimals(ordercd.thesoulofgospel.value * preis_thesoulofgospel);
ordercd.total_oletimereligion.value = round_decimals(ordercd.oletimereligion.value * preis_oletimereligion);
ordercd.total_liveinconcert.value = round_decimals(ordercd.liveinconcert.value * preis_liveinconcert);

// Berechne Anzahl CDs
ordercd.cd_total.value = parseFloat(ordercd.best_of.value) + parseFloat(ordercd.christmas_live.value) + parseFloat(ordercd.spiritual_inspiration.value) + parseFloat(ordercd.summertime.value) + parseFloat(ordercd.amazinggospel.value) + parseFloat(ordercd.centurycelebration.value) + parseFloat(ordercd.itschurchtime.value) + parseFloat(ordercd.thesoulofgospel.value) + parseFloat(ordercd.oletimereligion.value) + parseFloat(ordercd.liveinconcert.value);

anzahl_cds = ordercd.cd_total.value;

// Berechne Versandkosten auf 2 Kommastellen
if (ordercd.waehrung.value == "EUR") {
if (anzahl_cds >=9) {ordercd.versandkosten.value = 12.00;}
else if (anzahl_cds >=3 && anzahl_cds <=9) {ordercd.versandkosten.value = 9.00;}
else if (anzahl_cds >=1 && anzahl_cds <=3) {ordercd.versandkosten.value = 4.50;} 
else {ordercd.versandkosten.value = 0.00;}
}

if (ordercd.waehrung.value == "CHF") {
ordercd.versandkosten.value = 0.00;
}
ordercd.versandkosten.value = round_decimals(ordercd.versandkosten.value);


ordercd.gesamtbetrag.value = parseFloat(ordercd.total_best_of.value) + parseFloat(ordercd.total_christmas_live.value) + parseFloat(ordercd.total_spiritual_inspiration.value) + parseFloat(ordercd.total_summertime.value) + parseFloat(ordercd.total_amazinggospel.value) + parseFloat(ordercd.total_centurycelebration.value) + parseFloat(ordercd.total_itschurchtime.value) + parseFloat(ordercd.total_thesoulofgospel.value) + parseFloat(ordercd.total_oletimereligion.value) + parseFloat(ordercd.total_liveinconcert.value) + parseFloat (ordercd.versandkosten.value);
ordercd.gesamtbetrag.value = round_decimals(ordercd.gesamtbetrag.value);

gesamtbetrag = ordercd.gesamtbetrag.value;
waehrung = ordercd.waehrung.value; 
versandkosten = ordercd.versandkosten.value;
}

function PreisAlert(){
alert ("Your total order consists of "+anzahl_cds+" CD(s).\n Total amount "+waehrung+" "+gesamtbetrag+" \n\(Shipping fee "+waehrung+" "+versandkosten+"\)");
}

//-->
