function testNum(Eingabe, Min,Max,Meld) {
   var Zeichen, String = "";
   var i, l, Wert = 0;
   Meld = Meld + " passt nicht zum gewählten Produkt: " + Eingabe.value;
   String = Eingabe.value;
   if (String. length < 1) {
      alert (Meld+" leeres Feld");
      return false;
   }
   for (i = 0; i < String.length; i++) {
      Zeichen = String. substring (i, i + 1);
      if ((Zeichen < "0" || Zeichen > "9") && (Zeichen != "," && Zeichen !=".")) {
         alert (Meld);
         return false;
      }
   }
   Wert = parseInt(String);
   if (Wert < Min || Wert > Max) {
      alert(Meld + ". Wert zu klein/groß: ["+ Min + ".." + Max + "]");
      return false;
   }
   Eingabe.value = Wert;
   return true;
}

function IntToMoney (Geld) {
	var	Money = "";
	var	Pfennig;
	Money = parseInt (Geld/100);
   Pfennig = Geld - Money * 100;
   Money = Money + ",";
   if (Pfennig < 10) {
   	Money = Money + "0";
  		if (Pfennig < 1) {
			Money = Money + "0";
		}
		else {
			Money = Money + Pfennig;
		}
   }
	else {
		Money = Money + Pfennig;
 	}
	return Money;
}

function calcForm(form) {
   var p=0;
   var Gewicht;
	var Stueckzahl="Fehler!";
	var Porto_gesamt;
	if(testNum(form.Stueckzahl,50,9999999,"Stückzahl"))	{
		Stueckzahl = form.Stueckzahl.value;
	}
   //Infopost/Kataloge-Standard	
   if (form.Format[0].checked==1) {
      if (testNum(form.Gewicht,1,20,"Gewicht"))
         p=25;
   }
   //Infopost/Kataloge-Kompakt bis 50g	
   if (form.Format[1].checked==1) {
      if (testNum(form.Gewicht,1,50,"Gewicht")) {
         Gewicht = form.Gewicht.value;
         if (Gewicht < 20)
            p = 28;
         else
            p = Math.round((Gewicht - 20) * 0.352 + 28);
      }
   }
   //Infopost/Kataloge-Groß	
   if (form.Format[2].checked==1) {
      if (testNum(form.Gewicht,1,1000,"Gewicht")) {
         Gewicht = form.Gewicht.value;
         if (Gewicht < 20)
            p = 36;
         else
            if (Gewicht < 100)
               p = Math.round((Gewicht - 20) * 0.352 + 36);
            else
               p = Math.round((Gewicht - 100) * 0.046 + 64);
      }
   }
   //Infopost/Kataloge-Maxi	
   if (form.Format[3].checked==1) {
     if (testNum(form.Gewicht,1,1000,"Gewicht")) {
         Gewicht = form.Gewicht.value;
         if (Gewicht < 20)
            p = 73;
         else
            if (Gewicht < 100)
               p = Math.round((Gewicht - 20) * 0.352 + 73);
            else
               p = Math.round((Gewicht - 100) * 0.046 + 101);
      }
   }
	if ((p > 1) & (p < 99999999)) {
   	form.Porto.value=p;
		if (Stueckzahl == "Fehler!") {
			form.Porto_gesamt.value = "Fehler!"
		}
		else {
			Porto_gesamt = IntToMoney (Stueckzahl * p);
			form.Porto_gesamt.value = Porto_gesamt;
		}
	}
	else {
		form.Porto.value = "Fehler!"
	}
   return;
}