// JavaScript Document

function calc() {
        if(sumWeight!=0) {
                //var pay=0;
                var sticker=12, karton=184, pp=0;
                //if(document.form.choicePM[1].checked) {
                //        pay=0.50*anzItems;
                //}
                if(sumWeight==56 || sumWeight==63 || sumWeight==112 || sumWeight==126 || sumWeight==119
                        || sumWeight==75 || sumWeight==150 || sumWeight==131 || sumWeight==138 ) {
                        var calcWeight=sumWeight;
                        calcWeight+=sticker;
                        var isKarton=false;
                } else {
                        calcWeight=sumWeight;
                        calcWeight+=(sticker+karton);
                        isKarton=true;
                }
                if(prod<24.97) {
                    if(document.form.choicePP[0].checked) { // D
                            if(!isKarton) {//Luftpolster
                                    pp=2;
                            } else {//Karton
                                    if(calcWeight<=500) {
                                            pp=2.50;
                                    } else {
                                            if(calcWeight<=2000) {
                                                    pp=4.50;
                                            } else {
                                                    if(calcWeight<=5000) {
                                                            pp=7.00;
                                                    } else {
                                                            alert("too many items");
                                                    }
                                            }
                                    }
                            }
                    } // End D
                    if(document.form.choicePP[1].checked) { // EU
                            if(!isKarton) {//Luftpolster
                                    pp=3.5;
                            } else {//Karton
                                    if(calcWeight<=500) {
                                            pp=3.5;
                                    } else {
                                            if(calcWeight<=1000) {
                                                    pp=6.00;
                                            } else {
                                                    if(calcWeight<=2000) {
                                                            pp=9.00;
                                                    } else {
                                                            alert("too many items");
                                                    }
                                            }
                                    }
                            }
                    } // End EU
                    if(document.form.choicePP[2].checked) { //INT
                            if(!isKarton) {//Luftpolster
                                    pp=6;
                            } else {//Karton
                                    if(calcWeight<=500) {
                                            pp=6.00;
                                    } else {
                                            if(calcWeight<=1000) {
                                                    pp=10.00;
                                            } else {
                                                    if(calcWeight<=2000) {
                                                            pp=12.00;
                                                    } else {
                                                            alert("too many items");
                                                    }
                                            }
                                    }
                            }
                    } // End INT
                } else { // Kein Porto wenn Bestellwert ab 25euro
                    pp=0.00;
                }
                //document.getElementById('payment').innerHTML = kaufm(pay);
                document.getElementById('popa').innerHTML = kaufm(pp);
                //document.getElementById('GS').innerHTML = kaufm(prod + pay + pp);
                //document.form.sendprice.value= kaufm(prod + pay + pp);
                document.getElementById('GS').innerHTML = kaufm(prod + pp);
                document.form.sendprice.value= kaufm(prod + pp);
                document.form.sendpostage.value= kaufm(pp);
                //document.form.sendpay.value= kaufm(pay);
        }
}

function resetPrice() {
        //document.getElementById('payment').innerHTML = kaufm(0);
        document.getElementById('popa').innerHTML = kaufm(0);
        document.getElementById('GS').innerHTML = kaufm(0);
        window.setTimeout("calc()", 10);
}

function kaufm(x) {
  var k = x.toString();
  k += (k.indexOf('.') == -1)? '.00' : '00';
  var p = k.indexOf('.'), m = k.indexOf('-.');
  var f = (p == 0 || m == 0)? '0.' : '.';
  return k.substring(0, p) + f + k.substring(p+1, p+3);
}

function isAvail() {
        var sizeSelectedIndex=document.add.siz.selectedIndex;
        var colorSelectedIndex=document.add.col.selectedIndex;
        var cut=document.add.cut.value;

        if(sizeSelectedIndex==null || colorSelectedIndex==null
            || sizeSelectedIndex==0 || colorSelectedIndex==0) {
               alert("You didn't choose all options correctly!\nChoose size and color!");
               return false;
        } else if (sizeSelectedIndex==1 && colorSelectedIndex==2 && cut=="Regular") {
            alert("This combination is sold out!\nPlease choose a different size or color!");
            document.add.col.selectedIndex=0;
            return false;
        } else {
            return true;
        }
}
