function creditCalculatorClass()
{
	this.aCreditMatrix = new Array();

	this.fCreditAmount = 0.00;					// Kreditbetrag
	this.iCreditDuration = 0;					// Laufzeit
	this.fOverviewCreditAmount = 0.00;			// Kreditbetrag -> Angebot
	this.iOverviewCreditDuration = 0;			// Laufzeit -> Angebot
	this.fAccountFee = 0.00;					// Grundgebühr

	this.fCreditAmountWithFee = 0.00;			// Kreditbetrag+Grundgebühr
	this.fAffectiveInterest = 0.00;				// Effektivzins
	this.fNominalInterest = 0.00;				// Nominalzins
	this.fMonthlyCreditRate = 0.00;				// monatliche Rate
	this.fOverallRedemptionAmount = 0.00;		// Gesamt-Kreditbetrag
	this.fOverallInterest = 0.00;				// Zinsen

	this.aDurationRange = new Array();			// Array Laufzeiten
	this.aCreditOverview = new Array();			// Array Angebot
	this.aCreditCollateral = new Array();		// Array Versicherungen
	this.aCreditCollateralValue = new Array();	// Array Versicherungen-Werte
	this.sCreditCollateral = '';				// Versicherung
	this.sCreditCollateralValue = '';			// Versicherung-Wert
	this.iPositionCurrentDuration = 0;
	this.iPositionFirstDuration = 0;
	this.iPositionLastDuration = 0;
	this.iCurrentCreditDuration = 0;
	this.iPositionCurrentRow = 0;
	this.bTest = false;
	this.oDolly = new Object();
	this.bReverseCreditOverview = false;

	/* #################################################################  */
	/* FUNKTION setCreditAmount */
	this.setCreditAmount = function(sCreditAmount)
	{
		this.fCreditAmount = parseFloat(sCreditAmount);
	}

	/* #################################################################  */
	/* FUNKTION setCreditDuration */
	this.setCreditDuration = function(sCreditDuration)
	{
		this.iCreditDuration = parseInt(sCreditDuration);
	}

	/* #################################################################  */
	/* FUNKTION setAccountFee */
	this.setAccountFee = function(sAccountFee)
	{
		this.fAccountFee = parseFloat(sAccountFee);
	}

	/* #################################################################  */
	/* FUNKTION getCreditMatrix */
	this.getCreditMatrix = function()
	{
		return this.aCreditMatrix;
	}

	/* #################################################################  */
	/* FUNKTION setCreditMatrix */
	this.setCreditMatrix = function(sCreditAmount, sCreditDuration, sAffectiveInterest)
	{
		var aCreditDuration = sCreditDuration.split(',');
		var aAffectiveInterest = sAffectiveInterest.split(',');
		var sArrayKeyCreditDuration = '';

		this.aCreditMatrix[sCreditAmount] = new Array();

		for(sArrayKeyCreditDuration in aCreditDuration)
		{
			this.aCreditMatrix[sCreditAmount][aCreditDuration[sArrayKeyCreditDuration]] = aAffectiveInterest[sArrayKeyCreditDuration];
		}
	}

	/* #################################################################  */
	/* FUNKTION string replace  */
	this.str_replace = function(search, replace, subject) {
		return subject.split(search).join(replace);
	}

	/* #################################################################  */
	/* FUNKTION setCreditCalculation */
	/* Setzt die Werte der Übersicht bei Initialisierung der Seite */
	this.setCreditCalculation = function()
	{
		this.fCreditAmountWithFee = this.fCreditAmount + this.fAccountFee;
		this.fAffectiveInterest = this.getAffectiveInterest();

		var sfAffectiveInterestOut = this.str_replace(".",",",this.fAffectiveInterest);

		this.fNominalInterest = (Math.pow(1 + (this.fAffectiveInterest/100), 1/12) - 1) * 100 * 12;
		var fNominalInterest = String((Math.pow(1 + (this.fAffectiveInterest/100), 1/12) - 1) * 100 * 12);

		var fNominalInterest = String((Math.round(fNominalInterest * 100) / 100));

		var aNominalInterest = fNominalInterest.split('.');
		if(typeof(aNominalInterest[1]) != 'undefined' && aNominalInterest[1].length == 1)
		{
			aNominalInterest[1] = aNominalInterest[1] + '0';
		}
		else if(typeof(aNominalInterest[1]) == 'undefined')
		{
			aNominalInterest[1] = '00';
		}
		var sNominalInterest = aNominalInterest.join(','); // Nominalzins - Sring

		// Berechnung der Rate (gerundet) ohne Sikkerhet, nur bei Initialisierung der Seite

		this.fMonthlyCreditRate = Math.round(((this.fCreditAmountWithFee * this.fNominalInterest / 1200) / (-1 * Math.pow(1 + this.fNominalInterest / 1200, -1 * this.iCreditDuration) + 1) + this.sCreditCollateralValue * this.fCreditAmount / 100) * 100 ) / 100;
		this.fOverallRedemptionAmount = this.fMonthlyCreditRate * this.iCreditDuration;
		this.fOverallInterest = this.fOverallRedemptionAmount - this.fCreditAmountWithFee;

		// Berechnung der Rate (gerundet) mit Sikkerhet, nur bei Initialisierung der Seite
		var iSikkerhet = "0.26";
		this.fMonthlyCreditRateSikkerhet = Math.round(((this.fCreditAmountWithFee * this.fNominalInterest / 1200) / (-1 * Math.pow(1 + this.fNominalInterest / 1200, -1 * this.iCreditDuration) + 1) + iSikkerhet * this.fCreditAmount / 100) * 100 ) / 100;
		this.fOverallRedemptionAmountSikkerhet = this.fMonthlyCreditRateSikkerhet * this.iCreditDuration;
		this.fOverallInterestSikkerhet = this.fOverallRedemptionAmountSikkerhet - this.fCreditAmountWithFee;

		var fOverallRedemptionAmountGesamt = String(Math.round(this.fOverallRedemptionAmount * 100) / 100).split('.');
		var fOverallMax = fOverallRedemptionAmountGesamt[0].length;

		if(fOverallMax==3){
			var fOverallRedemptionAmountGesamtF = fOverallRedemptionAmountGesamt[0];
		}

		if(fOverallMax==4){
			var fOverallRedemptionAmountGesamtF1 = fOverallRedemptionAmountGesamt[0].substr(0,1);
			var fOverallRedemptionAmountGesamtF2 = fOverallRedemptionAmountGesamt[0].substr(1,3);
			fOverallRedemptionAmountGesamtF = fOverallRedemptionAmountGesamtF1 + '.' + fOverallRedemptionAmountGesamtF2;
		}

		if(fOverallMax==5){
			var fOverallRedemptionAmountGesamtF1 = fOverallRedemptionAmountGesamt[0].substr(0,2);
			var fOverallRedemptionAmountGesamtF2 = fOverallRedemptionAmountGesamt[0].substr(2,4);
			fOverallRedemptionAmountGesamtF = fOverallRedemptionAmountGesamtF1 + '.' + fOverallRedemptionAmountGesamtF2;
		}

		fOverallRedemptionAmountGesamt[1] = fOverallRedemptionAmountGesamt[1] + '0';
		fOverallRedemptionAmountGesamt[1] = fOverallRedemptionAmountGesamt[1].substr(0, 2);

		/* PRINT VALUES OF CALCULATION */
		if(document.getElementById('layerVal_24')){
			document.getElementById('layerVal_24').innerHTML = sNominalInterest + "% / " + sfAffectiveInterestOut + "%"; // EM 19.05.2009
		}

		if(document.getElementById('formValZinsAffective')){
			document.getElementById('formValZinsAffective').value = sfAffectiveInterestOut; // EM 19.05.2009
		}

		if(document.getElementById('formValZinsNominal')){
			document.getElementById('formValZinsNominal').value = sNominalInterest; // EM 19.05.2009
		}

		if(document.getElementById('layerVal_14')){
			document.getElementById('layerVal_14').value = this.fMonthlyCreditRate + "(" + this.fMonthlyCreditRateSikkerhet + ")"; // EM 19.05.2009
			var layerVal_14 = this.fMonthlyCreditRateSikkerhet;
		}

		if(document.getElementById('layerVal_25')){

			if(fOverallRedemptionAmountGesamt[1]=="un"){ // part of "undefinied"
				fOverallRedemptionAmountGesamt[1] = "00";
			}
			document.getElementById('layerVal_25').innerHTML = fOverallRedemptionAmountGesamtF + ',' +fOverallRedemptionAmountGesamt[1] + ' &euro;' ; // EM 19.05.2009
			document.getElementById('formValGesamtSikkerhet').value = this.fOverallRedemptionAmountSikkerhet; // EM 19.05.2009
		}

		if(document.getElementById('formValGesamt')){
			document.getElementById('formValGesamt').value = String(Math.round(this.fOverallRedemptionAmount * 100) / 100).split('.'); // EM 19.05.2009
		}
	}

	/* #################################################################  */
	/* FUNKTION getAffectiveInterest */
	this.getAffectiveInterest = function()
	{
		var sArrayKeyCreditAmount = '';
		var fArrayKeyCreditAmount = 0.00;
		var fCreditAmountMatrix = 0.00;

		var sArrayKeyCreditDuration = '';
		var iArrayKeyCreditDuration = 0;
		var iCreditDurationMatrix = 0;

		for(sArrayKeyCreditAmount in this.aCreditMatrix)
		{
			fArrayKeyCreditAmount = parseFloat(sArrayKeyCreditAmount);
			if(this.fCreditAmount <= fArrayKeyCreditAmount)
			{
				fCreditAmountMatrix = fArrayKeyCreditAmount;
				for(sArrayKeyCreditDuration in this.aCreditMatrix[fArrayKeyCreditAmount])
				{
					iArrayKeyCreditDuration = parseInt(sArrayKeyCreditDuration);
					if(this.iCreditDuration <= iArrayKeyCreditDuration)
					{
						iCreditDurationMatrix = iArrayKeyCreditDuration;
						break;
					}
				}
				break;
			}
		}
		return this.aCreditMatrix[fCreditAmountMatrix][iCreditDurationMatrix];
	}

	/* #################################################################  */
	/* FUNKTION setDurationRange */
	this.setDurationRange = function(aDurationRange)
	{
		this.aDurationRange = aDurationRange;
	}

	/* FUNKTION setCreditCollateral */
	this.setCreditCollateral = function(aCreditCollateral, aCreditCollateralValue)
	{
		this.aCreditCollateral = aCreditCollateral;
		this.sCreditCollateral = aCreditCollateral[0];
		this.aCreditCollateralValue = aCreditCollateralValue;
		this.sCreditCollateralValue = aCreditCollateralValue[0];
	}

	/* #################################################################  */
	/* FUNKTION setInsertCurrentDuration */
	this.setInsertCurrentDuration = function(iCurrentCreditDuration)
	{
		this.iCurrentCreditDuration = iCurrentCreditDuration;
		for(var sArrayKeyDurationRange in this.aDurationRange)
		{
			if(this.iCurrentCreditDuration < parseInt(this.aDurationRange[sArrayKeyDurationRange]))
			{
				this.aDurationRange.splice(sArrayKeyDurationRange, '', String(this.iCurrentCreditDuration));
				break;
			}
			else if(this.iCurrentCreditDuration > parseInt(this.aDurationRange[this.aDurationRange.length - 1]))
			{
				this.aDurationRange.push(String(this.iCurrentCreditDuration));
			}
			else if(this.iCurrentCreditDuration == this.aDurationRange[sArrayKeyDurationRange]) {
				break;
			}
		}
		if(document.getElementById('formValiCreditDuration')){
			document.getElementById('formValiCreditDuration').value = this.iCurrentCreditDuration; // EM 13.02.2009
		}

		if(document.getElementById('layerVal_10')){
			document.getElementById('layerVal_10').innerHTML = this.iCurrentCreditDuration + " Monate"; // EM 19.05.2009
		}

		if(document.getElementById('formValGesamtlaufzeit')){
			document.getElementById('formValGesamtlaufzeit').value = this.iCurrentCreditDuration; // EM 19.05.2009
		}

		this.setCreditCalculation();
	}
}