// JavaScript Document

function recalculate(sender) { //v1.0

	//	DEFINE VARIABLES
	//	GET FORM VALUES
	
	var accountingType;
		
	for (i = 0; i < document.myCalculator.accountingType.length; i++)
	{
		if (document.myCalculator.accountingType[i].checked == true)
		{
			accountingType = document.myCalculator.accountingType[i].value;
			break;
		}
	}
	
	var numberOfLines = document.myCalculator.numberOfLines.value;
	var numberOfPayrolls = document.myCalculator.numberOfPayrolls.value;
	
	if ((numberOfLines >= 0) && (numberOfPayrolls >= 0))
	{
	
		//	CALCULATE COSTS
		//	accountingType 1 = Einnahmen-Ausgaben-Rechner
		//	accountingType 2 = Bilanzierer
	
		var costLines = 1.9;
		var costPayrollsFull = 19;
		var costPayrollsDiscounted = 15;
		var costType1Annual = 750;
		var costType2AnnualPerLine = 1.2;
		var costType2AnnualMinimum = 1500;

		var costPerYear;
		var costPerMonth;
	
		costPerYear = numberOfLines*12*costLines;
	
		//	IF 5 OR MORE PAYROLLS, USE DISCOUNTED RATE
	
		if (numberOfPayrolls >= 5)
		{
			costPerYear += numberOfPayrolls*12*costPayrollsDiscounted;
		}
		else
		{
			costPerYear += numberOfPayrolls*12*costPayrollsFull;		
		}
	
		if (accountingType == 1)
		{
			costPerYear += costType1Annual;
		}
		else
		{
			var annualLinesCost = numberOfLines*12*costType2AnnualPerLine;
		
			if (annualLinesCost >= costType2AnnualMinimum)
			{
				costPerYear += annualLinesCost;
			}
			else
			{
				costPerYear += costType2AnnualMinimum;
			}
		}
	
		//	OUTPUT RESULTS
	
		costPerMonth = costPerYear/12;
		
		document.getElementById('resultsText').innerHTML = '<p class="leadin">Monatlich pauschal netto Euro ' + costPerMonth.toFixed(2).toString().replace (/\./g, ',') + '.</p>';
		document.getElementById('myResults').style.display = 'block';
	
	}
	else
	{
		//	NO VALUES SELECTED

		document.getElementById('myResults').style.display = 'none';
		
		if (sender == 1)
		{
			alert('Bitte wählen Sie für Ihre Berechnung die voraussichtliche Anzahl der monatlichen Buchungszeilen und Lohnverrechnungsvorgänge aus.');
		}
		
	}
	
}
