


// +-----------------------------------------------------------------------------------------------------+
// | rechner.js                                                                                          |
// +-----------------------------------------------------------------------------------------------------+
// | Copyright (c) 2008 steuerberaten.de                                                                 |
// +-----------------------------------------------------------------------------------------------------+
// | Datum: 07.07.2008                                                                                   |
// +-----------------------------------------------------------------------------------------------------+
// | Urheberrechtshinweis:                                                                               |
// | Diese Script ist urheberrechtlich geschützt. Einer Freigabe zur Publikation in anderen Medien oder  |
// | zu sonstiger Verwendung wird ausdrücklich widersprochen. Jede Zuwiderhandlung wird - unabhängig von |
// | Zweck, Person, Umfang, Einsatzgebiet - sofort und ohne weitere Warnung juristisch verfolgt.         |
// +-----------------------------------------------------------------------------------------------------+
// | Autor: Michael Mühl <muehl@emric.de>                                                                |
// +-----------------------------------------------------------------------------------------------------+



// ********** INFO TEXTE *********
function set_info(type)
 {
 	var TAXCALC = "19272001169";
	var obj;
    var txt;

    if (document.all)
      obj = document.all.infotext;
    else
      obj = document.getElementById("infotext");


	switch (type)
    {
		case "ausgabe":
			txt = txtausgabe
			break;
		
		case "start_datum":
			txt = "start_datum";
			break;
		case "nutzungsdauer_jahre":
			txt = "Geben Sie die betriebsgewöhnliche Nutzungsdauer an Wirtschafts-Wiki:<a href=\"#\" onclick=\"showWikiBox('AfA-Tabelle', '../../../')\" class=\"link_std\">AfA-Tabelle</a>";
			break;
		case "nutzungsdauer_jahre_max":
			txt = "Die maximale Nutzungsdauer beträgt 20 Jahre.";
			break;
		case "anschaffungskosten":
			txt = "Bitte geben Sie den Kaufpreis im Zeitpunkt der Anschaffung an; Netto bei Vorsteuerabzugsberechtigung; Brutto bei fehlender Vorsteuerabzugsberechtigung";
			break;
	}

    obj.innerHTML = txt;

  }
  

// ********** CALC *********
function CalcLineareAbschreibung(widget, style)  
{
	style_action(style);
	
	if (widget == "") widget = false;
	else widget = true;
	
	var error = false;

	var start_monat			= parseInt(document.eingabe.start_monat.value);
	var start_jahr			= parseInt(document.eingabe.start_jahr.value);
	nutzungsdauer_jahre		= parseInt(document.eingabe.nutzungsdauer_jahre.value);
	var anschaffungskosten	= parseInt(document.eingabe.anschaffungskosten.value);
	
	// Berechnung
	if (nutzungsdauer_jahre > 20) {
		error = true;
		set_info('nutzungsdauer_jahre_max');
	}
	if (!nutzungsdauer_jahre) {
		error = true;
		set_info('nutzungsdauer_jahre');
	}
	if (!anschaffungskosten || anschaffungskosten == "" || anschaffungskosten == 0) {
		error = true;
		set_info('anschaffungskosten');
	}
	
	jaehrliche_abschreibung = Math.ceil(anschaffungskosten / nutzungsdauer_jahre);
	
	out_jahr 	= new Array();
	wert1 		= new Array();
	wert2 		= new Array();
	wert3 		= new Array();
	wert4 		= new Array();
	
	var y = 1;
	for (var x = nutzungsdauer_jahre; x >= 0; x--) {
		
		if (nutzungsdauer_jahre - x >= 0) {
			out_jahr[x] = start_jahr + nutzungsdauer_jahre - x;
		} else {
			out_jahr[x] = "";
		}
		
		if (nutzungsdauer_jahre - x >= 0) {
			wert1[x] = jaehrliche_abschreibung;
		} else {
			wert1[x] = 0;
		}
		
		if (start_monat <= 12 && start_jahr == out_jahr[x]) {
			wert2[x] = Math.ceil(jaehrliche_abschreibung / 12 * (12 - (start_monat - 1)));
		} else {
			wert2[x] = 0;
		}
				
		if (out_jahr[x] == (start_jahr + nutzungsdauer_jahre) && start_monat <= 12) {
			wert3[x] = jaehrliche_abschreibung / 12 * (start_monat - 1);
		} else {
			wert3[x] = parseInt(wert1[x]);
		}
				
		if (wert2[x] > 0) {
			wert4[x] = wert2[x];
		} else {
			wert4[x] = wert3[x];
		}
		
		y++;
	}
	
		
	if (!error)
	{
		textzusammen(widget);
		set_info('ausgabe');
	}

}


function textzusammen(widget) 
{

	text = "<TABLE cellspacing=0 cellpadding=0 border=0'>";
	text += "<TR><TD class='cell_line'>&nbsp;</TD><TD class='cell_line_border'>&nbsp;</TD></TR>";

	text += "<TR><TD class='cell'><b>Jahr</b></TD>";
	text += "<TD class='cell_border'><b>Abschreibung</b></TD></TR>";
	text += "<TR><TD class='cell_line'>&nbsp;</TD><TD class='cell_line_border'>&nbsp;</TD></TR>";

	for (var i = nutzungsdauer_jahre; i >= 0; i--) {
		
		text += "<TR><TD class='cell_green'><nobr>&nbsp;" + out_jahr[i] + " </nobr></TD>";
		text += "<TD class='cell_green_border'><nobr>&nbsp;" + komma(wert4[i]) + " &euro;</nobr></TD></TR>";
		text += "<TR><TD class='cell_line'>&nbsp;</TD><TD class='cell_line_border'>&nbsp;</TD></TR>";
		
	}	
		
	text += "</TABLE>";


	if (!widget) 
	{ 
		promo = promo_u;
	} 
	else 
	{ 
		promo = "";
	}

	txtausgabe = text+promo;
}


