
function checkradio(feld) {
	for (i=0; i<feld.length; i++) {
		if(feld[i].checked == true) {
			return feld[i].value;
		}
	}
}

function DropdownValue(feld){
	return feld.options[feld.selectedIndex].value;
}

function DropdownText(feld){
	return feld.options[feld.selectedIndex].text;
}

function InZahl(Wert) {
	if (Wert.indexOf(",",0) > -1) Wert = Wert.replace(/,/, ".");
	if (isNaN(Wert)) return 0;
	return parseFloat(Wert);
}

function eng2ger(Wert) {

	if (Wert.indexOf(".",0) > -1) Wert = Wert.replace(/\./, ",");

	var vorkomma
	var nachkomma
	var pospkt = Wert.indexOf(",")

	if(pospkt == -1) {
		vorkomma  = Wert
		nachkomma = ""
	} else {
		vorkomma  = Wert.substring(0, pospkt)
		nachkomma = Wert.substring(pospkt + 1)
	}

	var laenge_ganz   = Math.floor(vorkomma.length / 3 + .1)
	var laenge_anfang = vorkomma.length % 3
	var vorkomma_neu  = ""
	if(laenge_anfang != 0) vorkomma_neu = vorkomma.substring(0, laenge_anfang)
	var i
	for(i = 0; i < laenge_ganz; i++) {
		vorkomma_neu += ((vorkomma_neu == "") ? "" : ".") + vorkomma.substring(laenge_anfang + (3 * i), laenge_anfang + (3 * i) + 3)
	}

	return vorkomma_neu + ((nachkomma == "") ? "" : ("," + nachkomma))
}

function calc() {

	// &Uuml;bernahme der Variablen
	// =======================

	var rentenart = checkradio(document.formular.rentenart);
	if (rentenart == "alter") rentenartText = "Altersrente";
	else if (rentenart == "vermind") rentenartText = "Rente wegen verminderter Erwerbsf&auml;higkeit";
	else if (rentenart == "erwerb") rentenartText = "Berufs-/Erwerbsunf&auml;higkeitsrente";

	var ort = checkradio(document.formular.ort);
	var monat = DropdownValue(document.formular.monat);
	var monatText = DropdownText(document.formular.monat);
	var punkte = InZahl(document.formular.punkte.value);

	monat = parseInt(monat);
	// Plausibilit&auml;tscheck
	// ===================

	if (punkte < 0 || punkte > 6.5) {
		document.write("<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\"><html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\" xml:lang=\"de-DE.UTF8\" lang=\"de-DE.UTF8\" dir=\"ltr\"><head><title>IKK GESUND PLUS · VERSICHERTENSERVICE UNSER SERVICE ONLINE-RECHNER HINZUVERDIENSTRECHNER<\/title><meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/><link rel=\"STYLESHEET\" type=\"text\/css\" href=\"..\/..\/..\/developer\/templates_production\/styles\/body_normal.css\" \/><link rel=\"STYLESHEET\" type=\"text\/css\" href=\"..\/..\/..\/developer\/templates_production\/styles\/screen.css\" \/><link rel=\"STYLESHEET\" type=\"text\/css\" href=\"style.css\" \/><\/head><body>");
		document.write("<div id=\"container\" style=\"padding-bottom:.5em;\"><h3>Fehler<\/h3>");
		document.write("<p>Die von Ihnen get&auml;tigte Eingabe der Entgeltpunkte l&auml;sst keine Berechnung zu. Bitte geben Sie eine Zahl ein, die zwischen 0 und 6,5 liegt sowie maximal 4 Nachkommastellen hat.");
		document.write("<br \/><br \/><a href=\"index.html\" class=\"Button\">Zur&uuml;ck</a></p><\/div><\/body><\/html>");
		return;
	}

	// Berechnung
	// ==========

	var AllgHiZuGrenze, BesHiZuGrenze23, BesHiZuGrenze12, BesHiZuGrenze13,BesHiZuGrenzeV34, BesHiZuGrenzeV12, BesHiZuGrenzeV14, BesHiZuGrenzeT11, BesHiZuGrenzeT12, BesHiZuGrenzeBU11, BesHiZuGrenzeBU23, BesHiZuGrenzeBU13;

	AllgHiZuGrenze = 400;

	if (rentenart == "alter" || rentenart == "vermind") {

		if (punkte <= 1.5) {
			if (monat >= 1001 && monat <= 1106) {
				if (ort == "west") {
					BesHiZuGrenze23 = 498.23;
					BesHiZuGrenze12 = 728.18;
					BesHiZuGrenze13 = 958.13;
					BesHiZuGrenzeV34 = 651.53;
					BesHiZuGrenzeV12 = 881.48;
					BesHiZuGrenzeV14 = 1073.10;
					BesHiZuGrenzeT11 = 881.48;
					BesHiZuGrenzeT12 = 1073.10;
				} else {
					BesHiZuGrenze23 = 441.99;
					BesHiZuGrenze12 = 645.99;
					BesHiZuGrenze13 = 849.98;
					BesHiZuGrenzeV34 = 577.99;
					BesHiZuGrenzeV12 = 781.98;
					BesHiZuGrenzeV14 = 951.98;
					BesHiZuGrenzeT11 = 781.98;
					BesHiZuGrenzeT12 = 951.98;
				}
			} else if (monat >= 1107 && monat <= 1112) {
				if (ort == "west") {
					BesHiZuGrenze23 = 498.23;
					BesHiZuGrenze12 = 728.18;
					BesHiZuGrenze13 = 958.13;
					BesHiZuGrenzeV34 = 651.53;
					BesHiZuGrenzeV12 = 881.48;
					BesHiZuGrenzeV14 = 1073.10;
					BesHiZuGrenzeT11 = 881.48;
					BesHiZuGrenzeT12 = 1073.10;
				} else {
					BesHiZuGrenze23 = 442.00;
					BesHiZuGrenze12 = 646.00;
					BesHiZuGrenze13 = 850.00;
					BesHiZuGrenzeV34 = 578.00;
					BesHiZuGrenzeV12 = 782.00;
					BesHiZuGrenzeV14 = 952.00;
					BesHiZuGrenzeT11 = 782.00;
					BesHiZuGrenzeT12 = 952.00;
				}
			} else if (monat >= 1201 && monat <= 1206) {
				if (ort == "west") {
					BesHiZuGrenze23 = 511.88;
					BesHiZuGrenze12 = 748.13;
					BesHiZuGrenze13 = 984.38;
					BesHiZuGrenzeV34 = 669.38;
					BesHiZuGrenzeV12 = 905.63;
					BesHiZuGrenzeV14 = 1102.50;
					BesHiZuGrenzeT11 = 905.63;
					BesHiZuGrenzeT12 = 1102.50;
				} else {
					BesHiZuGrenze23 = 454.11;
					BesHiZuGrenze12 = 663.70;
					BesHiZuGrenze13 = 873.29;
					BesHiZuGrenzeV34 = 593.84;
					BesHiZuGrenzeV12 = 803.43;
					BesHiZuGrenzeV14 = 978.08;
					BesHiZuGrenzeT11 = 803.43;
					BesHiZuGrenzeT12 = 978.08;
				}
			}
		} else {
			if (monat >= 1001 && monat <= 1106) {
				if (ort == "west") {
					BesHiZuGrenze23 = (punkte * 13 * 2555) / 100;
					BesHiZuGrenze12 = (punkte * 19 * 2555) / 100;
					BesHiZuGrenze13 = (punkte * 25 * 2555) / 100;
					BesHiZuGrenzeV34 = (punkte * 17 * 2555) / 100;
					BesHiZuGrenzeV12 = (punkte * 23 * 2555) / 100;
					BesHiZuGrenzeV14 = (punkte * 28 * 2555) / 100;
					BesHiZuGrenzeT11 = (punkte * 23 * 2555) / 100;
					BesHiZuGrenzeT12 = (punkte * 28 * 2555) / 100;
				} else {
					BesHiZuGrenze23 = (punkte * 13 * (2555 * 2413 / 2720)) / 100;
					BesHiZuGrenze12 = (punkte * 19 * (2555 * 2413 / 2720)) / 100;
					BesHiZuGrenze13 = (punkte * 25 * (2555 * 2413 / 2720)) / 100;
					BesHiZuGrenzeV34 = (punkte * 17 * (2555 * 2413 / 2720)) / 100;
					BesHiZuGrenzeV12 = (punkte * 23 * (2555 * 2413 / 2720)) / 100;
					BesHiZuGrenzeV14 = (punkte * 28 * (2555 * 2413 / 2720)) / 100;
					BesHiZuGrenzeT11 = (punkte * 23 * (2555 * 2413 / 2720)) / 100;
					BesHiZuGrenzeT12 = (punkte * 28 * (2555 * 2413 / 2720)) / 100;
				}
			} else if (monat >= 1107 && monat <= 1112) {
				if (ort == "west") {
					BesHiZuGrenze23 = (punkte * 13 * 2555) / 100;
					BesHiZuGrenze12 = (punkte * 19 * 2555) / 100;
					BesHiZuGrenze13 = (punkte * 25 * 2555) / 100;
					BesHiZuGrenzeV34 = (punkte * 17 * 2555) / 100;
					BesHiZuGrenzeV12 = (punkte * 23 * 2555) / 100;
					BesHiZuGrenzeV14 = (punkte * 28 * 2555) / 100;
					BesHiZuGrenzeT11 = (punkte * 23 * 2555) / 100;
					BesHiZuGrenzeT12 = (punkte * 28 * 2555) / 100;
				} else {
					BesHiZuGrenze23 = (punkte * 13 * (2555 * 2437 / 2747)) / 100;
					BesHiZuGrenze12 = (punkte * 19 * (2555 * 2437 / 2747)) / 100;
					BesHiZuGrenze13 = (punkte * 25 * (2555 * 2437 / 2747)) / 100;
					BesHiZuGrenzeV34 = (punkte * 17 * (2555 * 2437 / 2747)) / 100;
					BesHiZuGrenzeV12 = (punkte * 23 * (2555 * 2437 / 2747)) / 100;
					BesHiZuGrenzeV14 = (punkte * 28 * (2555 * 2437 / 2747)) / 100;
					BesHiZuGrenzeT11 = (punkte * 23 * (2555 * 2437 / 2747)) / 100;
					BesHiZuGrenzeT12 = (punkte * 28 * (2555 * 2437 / 2747)) / 100;
				}
			} else if (monat >= 1201 && monat <= 1206) {
				if (ort == "west") {
					BesHiZuGrenze23 = (punkte * 13 * 2625) / 100;
					BesHiZuGrenze12 = (punkte * 19 * 2625) / 100;
					BesHiZuGrenze13 = (punkte * 25 * 2625) / 100;
					BesHiZuGrenzeV34 = (punkte * 17 * 2625) / 100;
					BesHiZuGrenzeV12 = (punkte * 23 * 2625) / 100;
					BesHiZuGrenzeV14 = (punkte * 28 * 2625) / 100;
					BesHiZuGrenzeT11 = (punkte * 23 * 2625) / 100;
					BesHiZuGrenzeT12 = (punkte * 28 * 2625) / 100;
				} else {
					BesHiZuGrenze23 = (punkte * 13 * (2625 * 2437 / 2747)) / 100;
					BesHiZuGrenze12 = (punkte * 19 * (2625 * 2437 / 2747)) / 100;
					BesHiZuGrenze13 = (punkte * 25 * (2625 * 2437 / 2747)) / 100;
					BesHiZuGrenzeV34 = (punkte * 17 * (2625 * 2437 / 2747)) / 100;
					BesHiZuGrenzeV12 = (punkte * 23 * (2625 * 2437 / 2747)) / 100;
					BesHiZuGrenzeV14 = (punkte * 28 * (2625 * 2437 / 2747)) / 100;
					BesHiZuGrenzeT11 = (punkte * 23 * (2625 * 2437 / 2747)) / 100;
					BesHiZuGrenzeT12 = (punkte * 28 * (2625 * 2437 / 2747)) / 100;
				}
			}
		}
	} else if (rentenart == "erwerb") {
	
		if (punkte <= 0.5) {
			if (monat >= 1001 && monat <= 1106) {
				if (ort == "west") {
					BesHiZuGrenzeBU11 = 728.18;
					BesHiZuGrenzeBU23 = 970.90;
					BesHiZuGrenzeBU13 = 1200.85;
				} else {
					BesHiZuGrenzeBU11 = 645.99;
					BesHiZuGrenzeBU23 = 861.32;
					BesHiZuGrenzeBU13 = 1065.31;
				}
			} else if (monat >= 1107 && monat <= 1112) {
				if (ort == "west") {
					BesHiZuGrenzeBU11 = 728.18;
					BesHiZuGrenzeBU23 = 970.90;
					BesHiZuGrenzeBU13 = 1200.85;
				} else {
					BesHiZuGrenzeBU11 = 646.00;
					BesHiZuGrenzeBU23 = 861.33;
					BesHiZuGrenzeBU13 = 1065.33;
				}
			} else if (monat >= 1201 && monat <= 1206) {
				if (ort == "west") {
					BesHiZuGrenzeBU11 = 748.13;
					BesHiZuGrenzeBU23 = 997.50;
					BesHiZuGrenzeBU13 = 1233.75;
				} else {
					BesHiZuGrenzeBU11 = 663.70;
					BesHiZuGrenzeBU23 = 884.93;
					BesHiZuGrenzeBU13 = 1094.52;
				}
			}
		} else {
			if (monat >= 1001 && monat <= 1106) {
				if (ort == "west") {
					BesHiZuGrenzeBU11 = (punkte * 57 * 2555) / 100;
					BesHiZuGrenzeBU23 = (punkte * 76 * 2555) / 100;
					BesHiZuGrenzeBU13 = (punkte * 94 * 2555) / 100;
				} else {
					BesHiZuGrenzeBU11 = (punkte * 57 * (2555 * 2413 / 2720)) / 100;
					BesHiZuGrenzeBU23 = (punkte * 76 * (2555 * 2413 / 2720)) / 100;
					BesHiZuGrenzeBU13 = (punkte * 94 * (2555 * 2413 / 2720)) / 100;
				}
			} else if (monat >= 1107 && monat <= 1112) {
				if (ort == "west") {
					BesHiZuGrenzeBU11 = (punkte * 57 * 2555) / 100;
					BesHiZuGrenzeBU23 = (punkte * 76 * 2555) / 100;
					BesHiZuGrenzeBU13 = (punkte * 94 * 2555) / 100;
				} else {
					BesHiZuGrenzeBU11 = (punkte * 57 * (2555 * 2437 / 2747)) / 100;
					BesHiZuGrenzeBU23 = (punkte * 76 * (2555 * 2437 / 2747)) / 100;
					BesHiZuGrenzeBU13 = (punkte * 94 * (2555 * 2437 / 2747)) / 100;
				}
			} else if (monat >= 1201 && monat <= 1206) {
				if (ort == "west") {
					BesHiZuGrenzeBU11 = (punkte * 57 * 2625) / 100;
					BesHiZuGrenzeBU23 = (punkte * 76 * 2625) / 100;
					BesHiZuGrenzeBU13 = (punkte * 94 * 2625) / 100;
				} else {
					BesHiZuGrenzeBU11 = (punkte * 57 * (2625 * 2437 / 2747)) / 100;
					BesHiZuGrenzeBU23 = (punkte * 76 * (2625 * 2437 / 2747)) / 100;
					BesHiZuGrenzeBU13 = (punkte * 94 * (2625 * 2437 / 2747)) / 100;
				}
			}
		}

	
	}


	// Ausgabe
	// ======= 0.145 * 100

	document.write("<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\"><html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\" xml:lang=\"de-DE.UTF8\" lang=\"de-DE.UTF8\" dir=\"ltr\"><head><title>IKK GESUND PLUS · VERSICHERTENSERVICE UNSER SERVICE ONLINE-RECHNER HINZUVERDIENSTRECHNER<\/title><meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/><link rel=\"STYLESHEET\" type=\"text\/css\" href=\"..\/..\/..\/developer\/templates_production\/styles\/body_normal.css\" \/><link rel=\"STYLESHEET\" type=\"text\/css\" href=\"..\/..\/..\/developer\/templates_production\/styles\/screen.css\" \/><link rel=\"STYLESHEET\" type=\"text\/css\" href=\"style.css\" \/><\/head><body><div id=\"container\">");

	document.write("<h3>Ergebnis<\/h3>");
	document.write("<p>Auf der Grundlage Ihrer Angaben ergeben sich die folgenden Hinzuverdienstgrenzen:<\/p>");

	document.write("<br \/><h3>" + rentenartText + "<\/h3><br \/>");
	document.write("<p><strong>Entgeltpunkte: " + punkte + "<br \/>Hinzuverdienstgrenze f&uuml;r " + monatText + "<\/strong>");

	if (ort == "west") document.write(" (Alte Bundesl&auml;nder)<br \/><br \/>");
	else document.write(" (Neue Bundesl&auml;nder)<br \/><br \/>");

	// Altersrente
	if (rentenart == "alter") {
		document.write("Haben Sie bereits das 65. Lebensjahr vollendet, d.h. Sie haben bereits Ihren 65. Geburtstag gefeiert, k&ouml;nnen Sie <strong>unbegrenzt hinzuverdienen<\/strong>.<br \/><br \/>");
	
		document.write("Vor Vollendung des 65. Lebensjahres gilt:<br \/><br \/>");
	
		document.write("Beziehen Sie die Altersrente als Vollrente, betr&auml;gt die Hinzuverdienstgrenze <strong>" + eng2ger(AllgHiZuGrenze.toFixed(2)) + " EUR<\/strong> im Monat.<br \/><br \/>");
	
		document.write("Ist Ihr Hinzuverdienst im Monat h&ouml;her, leistet die Deutsche Rentenversicherung anstelle der Vollrente nur noch eine Teilrente. Die Alters-Teilrenten werden gezahlt, sofern individuelle Hinzuverdienstgrenzen, basierend auf den Entgeltpunkten der letzten drei Kalenderjahre vor Rentenbeginn, nicht &uuml;berschritten sind:<br \/><br \/>");
	
		document.write("<strong>2\/3 Teilrente: " + eng2ger(BesHiZuGrenze23.toFixed(2)) + " EUR<\/strong><br \/><br \/>");
		document.write("<strong>1\/2 Teilrente: " + eng2ger(BesHiZuGrenze12.toFixed(2)) + " EUR<\/strong><br \/><br \/>");
		document.write("<strong>1\/3 Teilrente: " + eng2ger(BesHiZuGrenze13.toFixed(2)) + " EUR<\/strong><br \/><br \/>");
	
		document.write("Der Rentenanspruch entf&auml;llt, sofern die Hinzuverdienstgrenze f&uuml;r die 1\/3 Teilrente &uuml;berschritten ist.<br \/><br \/>");

	// Rente wegen verminderter Erwerbsf&auml;higkeit
	} else if (rentenart == "vermind") {
	
		document.write("Eine Rente wegen verminderter Erwerbsf&auml;higkeit wird nur geleistet, wenn die folgenden Hinzuverdienstgrenzen nicht &uuml;berschritten sind:<br \/><br \/>");

		document.write("Beziehen Sie eine <strong>Rente wegen voller Erwerbsminderung<\/strong> als Vollrente, betr&auml;gt die Hinzuverdienstgrenze <strong>" + eng2ger(AllgHiZuGrenze.toFixed(2)) + " EUR<\/strong> im Monat.<br \/><br \/>");

		document.write("Ist Ihr Hinzuverdienst im Monat h&ouml;her, leistet die Deutsche Rentenversicherung anstelle der Vollrente nur noch eine Teilrente. Die Teilrenten werden gezahlt, sofern individuelle Hinzuverdienstgrenzen, basierend auf den Entgeltpunkten der letzten drei Kalenderjahre vor Rentenbeginn, nicht &uuml;berschritten sind:<br \/><br \/>");

		document.write("<strong>3\/4 Teilrente: " + eng2ger(BesHiZuGrenzeV34.toFixed(2)) + " EUR<\/strong><br \/><br \/>");
		document.write("<strong>1\/2 Teilrente: " + eng2ger(BesHiZuGrenzeV12.toFixed(2)) + " EUR<\/strong><br \/><br \/>");
		document.write("<strong>1\/4 Teilrente: " + eng2ger(BesHiZuGrenzeV14.toFixed(2)) + " EUR<\/strong><br \/><br \/>");

		document.write("Beziehen Sie eine <strong>Rente wegen teilweiser Erwerbsminderung<\/strong>, gelten die folgenden individuellen  Hinzuverdienstgrenzen (je Monat):<br \/><br \/>");

		document.write("<strong>Vollrente: " + eng2ger(BesHiZuGrenzeT11.toFixed(2))+ " EUR<\/strong><br \/><br \/>");

		document.write("<strong>1\/2 Teilrente: " + eng2ger(BesHiZuGrenzeT12.toFixed(2))+ " EUR<\/strong><br \/><br \/>");
	
	
	// Erwerbs-/Berufsunf&auml;higkeitsrente
	} else if (rentenart == "erwerb") {

		document.write("Beziehen Sie eine Erwerbsunf&auml;higkeitsgrenze (EU-Rente), betr&auml;gt die Hinzuverdienstgrenze <strong>" + eng2ger(AllgHiZuGrenze.toFixed(2)) + " EUR<\/strong> im Monat.<br \/><br \/>");

		document.write("Ist Ihr Hinzuverdienst im Monat h&ouml;her, leistet die Deutsche Rentenversicherung anstelle der EU-Rente nur noch eine Berufsunf&auml;higkeitsrente (BU-Rente). Diese wird gezahlt, sofern individuelle Hinzuverdienstgrenzen, basierend auf den Entgeltpunkten des letzten Kalenderjahres vor Rentenbeginn, nicht &uuml;berschritten sind:<br \/><br \/>");

		document.write("<strong>1\/1 Rente: " + eng2ger(BesHiZuGrenzeBU11.toFixed(2)) + " EUR<\/strong><br \/><br \/>");
		document.write("<strong>2\/3 Teilrente: " + eng2ger(BesHiZuGrenzeBU23.toFixed(2)) + " EUR<\/strong><br \/><br \/>");
		document.write("<strong>1\/3 Teilrente: " + eng2ger(BesHiZuGrenzeBU13.toFixed(2)) + " EUR<\/strong><br \/><br \/>");

		document.write("Wird auch die Hinzuverdienstgrenze f&uuml;r die 1/3 Teilrente &uuml;berschritten, entf&auml;llt die BU-Rente.<br \/><br \/>");
	
	}

	var j = new Date();

	document.write("<strong>Wichtig:<\/strong> Die ma&szlig;gebende Hinzuverdienstgrenze darf zweimal im Laufe eines jeden Kalenderjahres um einen Betrag bis zur H&ouml;he der jeweils geltenden Hinzuverdienstgrenze &uuml;berschritten werden.<br \/><br \/><a href=\"Javascript:history.back(-1);\" class=\"Button\">Zur&uuml;ck<\/a><\/p><\/div><\/body><\/html>");
	document.close()
}
