Niederlassungen = new Array('064');
NL=new Array('Kantoor Venlo');
NLanschrift=new Array('Zonneveld 1-7');
NLort=new Array('NL-5993 SG Maasbree/Venlo');
NLphone=new Array('31 (0) 77 39 61 955');
NLfax=new Array('31 (0) 77 39 61 965');
NLmail=new Array('nl-venlo');
LAND='NL';
WAEHRUNG='EUR';


function ini_niederlassung(index)
{
NL_AUSGABE_NL='GRENKEFINANCE N.V.';
NL_AUSGABE_NL2=NL[index];
NL_AUSGABE_ANSCHRIFT=NLanschrift[index];
NL_AUSGABE_ORT=NLort[index];
NL_AUSGABE_TEL=NLphone[index];
NL_AUSGABE_FAX=NLfax[index];
NL_AUSGABE_MAIL=NLmail[index];
}

function set_waehrung()
{
AUSGABESATZ ="<select name='Waehrung' style=width:45 onChange='intro_kalk()' onBlur='intro_kalk()'><option selected value='"+WAEHRUNG+"'>"+WAEHRUNG+"</option></select>";
document.write (AUSGABESATZ);
}

function set_varten(x)
{

var accesscode=parent.frames[2].document.forms[0].hvid.value;

if (accesscode.indexOf("M9") > "-1")
{
   AUSGABESATZ ="<option value='MIETE'>Mietvertrag</option>";
   document.write (AUSGABESATZ);
}
if (accesscode.indexOf("DA") > "-1")
{
   AUSGABESATZ ="<option value='DA'>DAS-Vertrag</option>";
   document.write (AUSGABESATZ);
}
if (accesscode.indexOf("MK") > "-1")
{
   AUSGABESATZ ="<option value='MK'>Mietkauf</option>";
   document.write (AUSGABESATZ);
}
}

function set_waehrung_antrag()
{
AUSGABESATZ ="<select name='Waehrung' style=width:45 onChange='antrag_kalk()' onBlur='antrag_kalk()'><option selected value='"+WAEHRUNG+"'>"+WAEHRUNG+"</option></select>";
document.write (AUSGABESATZ);
}

function set_waehrung_vpantrag()
{
AUSGABESATZ ="<select name='Waehrung' style=width:45><option selected value='"+WAEHRUNG+"'>"+WAEHRUNG+"</option></select>";
document.write (AUSGABESATZ);
}

function Ergebnis(Faktor,EINGABEWERT,PK)
{
var x = 0;
var x =EINGABEWERT;
var Faktor=Faktor+(Faktor*(PK/100));
ergebnis=Runden(Faktor,2);
var Faktor=ergebnis;
var x =(x*Faktor) / 100;
ergebnis=Runden(x,2);
window.document.KALK.Ausgabewert.value = ergebnis;
ergebnis=NachKomma2();
window.document.KALK.Ausgabewert.value = ergebnis;
}


function kalkulation(){

LZ = new Array(15,24,30,36,42,48,54,60,72);
Grenzen= new Array(500,2500,5000,25000,50000,1000)
Raten = new Array();
FlexRaten = new Array();
RentalRaten = new Array();
DARaten = new Array();

PRUEFZIFFER=1;
EINGABEWERT = (window.document.KALK.Eingabewert.value);
var erlaubt = "0123456789,.";var temp='';
for (var y=0; y<document.KALK.Eingabewert.value.length; y++)
 {
	var temp = "" + document.KALK.Eingabewert.value.substring(y, y+1);
	if (erlaubt.indexOf(temp) == "-1"){PRUEFZIFFER=0;}

EINGABEWERT=(EINGABEWERT).replace(/,/,".");document.KALK.Eingabewert.value=EINGABEWERT;}


if (EINGABEWERT < Grenzen[0])
	{
	var min= Grenzen[0]+' '+WAEHRUNG;
    alert("Er is voor dit bedrag geen leasecalculatie mogelijk.\nHet bedrag ter hoogte van "+min+" ligt onder het minimum.");
    PRUEFZIFFER=0;
   }
if (EINGABEWERT > Grenzen[4])
	{
	var min= Grenzen[4]+' '+WAEHRUNG;
    alert("Een leasecalculatie over dit bedrag is niet mogelijk.\n\nVanaf een bedrag van "+min+" krijgt u een offerte berekent met de dagrente.\nNeemt u aub contakt op met GRENKEFINANCE.");
    PRUEFZIFFER=0;
   }

if (PRUEFZIFFER==0)
{
   document.KALK.Eingabewert.focus();
   return false; 
}

for(i=0;i<document.KALK.Pfaktor.length;++i){ if(document.KALK.Pfaktor.options[i].selected == true)
{
	PK=(document.KALK.Pfaktor.options[i].value)};
}	

FIndex = 3;
   if (EINGABEWERT >=Grenzen[0] && EINGABEWERT <=Grenzen[1])
      var FIndex = 0  
   if (EINGABEWERT > Grenzen[1] && EINGABEWERT <=Grenzen[2])
      var FIndex = 1  
   if (EINGABEWERT > Grenzen[2] && EINGABEWERT <=Grenzen[3])
      var FIndex = 2  
   if (EINGABEWERT > Grenzen[3] && EINGABEWERT <=Grenzen[4])
      var FIndex = 3


//-- FlexLeasing //-->

FFaktor15 = new Array(6.6667,6.6667,6.6667,6.6667,0);
FFaktor24 = new Array(4.1667,4.16667,4.16667,4.16667,0);
FFaktor30 = new Array(3.3333,3.3333,3.3333,3.3333,0);
FFaktor36 = new Array(2.7778,2.7778,2.7778,2.7778,0);
Ergebnis(FFaktor15[FIndex],EINGABEWERT,0);
FlexRaten[0]=ergebnis;
Ergebnis(FFaktor24[FIndex],EINGABEWERT,0);
FlexRaten[1]=ergebnis;
Ergebnis(FFaktor30[FIndex],EINGABEWERT,0);
FlexRaten[2]=ergebnis;
Ergebnis(FFaktor36[FIndex],EINGABEWERT,0);
FlexRaten[3]=ergebnis;

if (EINGABEWERT > Grenzen[5] && PK ==0)
   {	
	for (var f=0; f < 4; f++)
		{
	   	 document.KALK.fergebnis[f].value=FlexRaten[f]+' '+WAEHRUNG;;
		}
	}
else
	{
	for (var f=0; f < 4; f++)
		{
	   	document.KALK.fergebnis[f].value='';
		FlexRaten[0]='';FlexRaten[1]='';FlexRaten[2]='';FlexRaten[3]='';
		}
	}

//--RentalLeasing--//

RFaktor15 = new Array(6.70,6.64,6.60,6.53,0);
RFaktor24 = new Array(4.42,4.39,4.35,4.32,0);
RFaktor30 = new Array(3.65,3.59,3.56,3.53,0);
RFaktor36 = new Array(3.09,3.04,3.02,2.99,0);
Ergebnis(RFaktor15[FIndex],EINGABEWERT,PK);
RentalRaten[0]=ergebnis;
Ergebnis(RFaktor24[FIndex],EINGABEWERT,PK);
RentalRaten[1]=ergebnis;
Ergebnis(RFaktor30[FIndex],EINGABEWERT,PK);
RentalRaten[2]=ergebnis;
Ergebnis(RFaktor36[FIndex],EINGABEWERT,PK);
RentalRaten[3]=ergebnis;
RentalRaten[4]='';
RentalRaten[5]='';
RentalRaten[6]='';
RentalRaten[7]='';
RentalRaten[8]='';
for (var f=0; f < 4; f++)
	{
    document.KALK.rergebnis[f].value=RentalRaten[f]+' '+WAEHRUNG;;
	}

//--DA System--//

DFaktor15 = new Array(7.21,7.17,7.10,7.06,0);
DFaktor24 = new Array(4.88,4.81,4.73,4.71,0);
DFaktor30 = new Array(0,0,0,0,0);
DFaktor36 = new Array(3.50,3.37,3.29,3.28,0);
DFaktor42 = new Array(3.09,2.98,2.91,2.84,0);
DFaktor48 = new Array(2.76,2.55,2.53,2.52,0);
DFaktor54 = new Array(2.60,2.42,2.30,2.28,0);
DFaktor60 = new Array(2.43,2.23,2.11,2.07,0);
DFaktor72 = new Array(0,1.93,1.83,1.82,0);
Ergebnis(DFaktor15[FIndex],EINGABEWERT,PK);
DARaten[0]=ergebnis;
Ergebnis(DFaktor24[FIndex],EINGABEWERT,PK);
DARaten[1]=ergebnis;
Ergebnis(DFaktor30[FIndex],EINGABEWERT,PK);
DARaten[2]=ergebnis;
Ergebnis(DFaktor36[FIndex],EINGABEWERT,PK);
DARaten[3]=ergebnis;
Ergebnis(DFaktor42[FIndex],EINGABEWERT,PK);
DARaten[4]=ergebnis;
Ergebnis(DFaktor48[FIndex],EINGABEWERT,PK);
DARaten[5]=ergebnis;
Ergebnis(DFaktor54[FIndex],EINGABEWERT,PK);
DARaten[6]=ergebnis;
Ergebnis(DFaktor60[FIndex],EINGABEWERT,PK);
DARaten[7]=ergebnis;
Ergebnis(DFaktor72[FIndex],EINGABEWERT,PK);
DARaten[8]=ergebnis;


//-- VA Normal --//
Faktor15 = new Array(6.99,6.96,6.88,6.83,0);
Faktor24 = new Array(4.71,4.63,4.49,4.49,0);
Faktor30 = new Array(3.99,3.79,3.74,3.69,0);
Faktor36 = new Array(3.37,3.22,3.04,3.01,0);
Faktor42 = new Array(2.99,2.89,2.79,2.71,0);
Faktor48 = new Array(2.69,2.49,2.42,2.34,0);
Faktor54 = new Array(2.51,2.34,2.23,2.19,0);
Faktor60 = new Array(2.36,2.14,1.99,1.94,0);
Faktor72 = new Array(0,1.89,1.68,1.64,0);
Ergebnis(Faktor15[FIndex],EINGABEWERT,PK);
Raten[0]=ergebnis;
Ergebnis(Faktor24[FIndex],EINGABEWERT,PK);
Raten[1]=ergebnis;
Ergebnis(Faktor30[FIndex],EINGABEWERT,PK);
Raten[2]=ergebnis;
Ergebnis(Faktor36[FIndex],EINGABEWERT,PK);
Raten[3]=ergebnis;
Ergebnis(Faktor42[FIndex],EINGABEWERT,PK);
Raten[4]=ergebnis;
Ergebnis(Faktor48[FIndex],EINGABEWERT,PK);
Raten[5]=ergebnis;
Ergebnis(Faktor54[FIndex],EINGABEWERT,PK);
Raten[6]=ergebnis;
Ergebnis(Faktor60[FIndex],EINGABEWERT,PK);
Raten[7]=ergebnis;
Ergebnis(Faktor72[FIndex],EINGABEWERT,PK);
Raten[8]=ergebnis;
for (var f=0; f < 9; f++)
	{
    document.KALK.ergebnis[f].value=Raten[f]+' '+WAEHRUNG;
	}
}


function eingabe_fordern(i)
{
document.KALK.elements[i].focus();
return false;
}

function erlaubt_sind(i,erlaubt)
{
var temp='';
for (var y=0; y<document.KALK.elements[i].value.length; y++)
	{
	var temp = "" + document.KALK.elements[i].value.substring(y, y+1);
	if (erlaubt.indexOf(temp) == "-1")
			{
			eingabe_fordern(i); return false;
			}
	}
}


function intro_kalk()
{
for (var f=0; f < 9; f++)
	{
    document.KALK.ergebnis[f].value='';
	}
kalkulation();
}


function antrag_kalk()
{

for(i=0;i<document.KALK.Laufzeit.length;++i)
	{
	 if (document.KALK.Laufzeit.options[i].selected == true)
		var a=i;
	};
for(i=0;i<document.KALK.Vertrag.length;++i)
	{
	 if (document.KALK.Vertrag.options[i].selected == true)
		var Vertrag=(document.KALK.Vertrag.options[i].value)
	};


if (Vertrag == 'DA')
{
	document.getElementById('DAS').style.visibility="visible";
}
else
{
	document.getElementById('DAS').style.visibility="hidden";
}

kalkulation();


document.KALK.Ausgabewert.value=Raten[a];
document.KALK.Ausgabewaehrung.value=WAEHRUNG;
document.KALK.Ausgabewert.style.borderColor = "#ffffff";
	

if (Vertrag == 'RENTAL')
	{
	if (RentalRaten[a] =='')
	{
	document.KALK.Ausgabewert.value='ontoelaatbaar';
	document.KALK.Ausgabewaehrung.value=' ! ';
	document.KALK.Ausgabewert.style.borderColor = "red";
	}
	else
	{
	document.KALK.Ausgabewert.value=RentalRaten[a];
	document.KALK.Ausgabewaehrung.value=WAEHRUNG;
	document.KALK.Ausgabewert.style.borderColor = "#ffffff";
	}	
	}

if (Vertrag == 'DISPO' && document.KALK.Eingabewert.value < 25000)
{
	document.KALK.Ausgabewert.value='ontoelaatbaar';
	document.KALK.Ausgabewaehrung.value=' ! ';
	document.KALK.Ausgabewert.style.borderColor = "red";
	alert ("Ein Dispo-Leasingvertrag ist nicht möglich.\nDer erforderliche Mindestbetrag für Dispo-Leasingverträge liegt\n bei 25.000 EUR ist nicht erreicht.");
}

if (Vertrag == 'FLEX')
	{
	if (FlexRaten[a] =='')
	{
	document.KALK.Ausgabewert.value='ontoelaatbaar';
	document.KALK.Ausgabewaehrung.value=' ! ';
	document.KALK.Ausgabewert.style.borderColor = "red";
	}
	else
	{
	document.KALK.Pfaktor.selectedIndex=0;
	document.KALK.Ausgabewert.value=FlexRaten[a];
    document.KALK.Ausgabewaehrung.value=WAEHRUNG;
	document.KALK.Ausgabewert.style.borderColor = "#ffffff";
	}
	}


if (Vertrag == 'DA')
	{
	if (DARaten[a] < 1)
	{
	document.KALK.Ausgabewert.value='ontoelaatbaar';
	document.KALK.Ausgabewaehrung.value=' ! ';
	document.KALK.Ausgabewert.style.borderColor = "red";
	}
	else
	{
	document.KALK.Ausgabewert.value=DARaten[a];
	document.KALK.dahardwarebetrag.value=DARaten[a];
	document.KALK.Ausgabewaehrung.value=WAEHRUNG;
	document.KALK.Ausgabewert.style.borderColor = "#ffffff";
	dasberechnung();
	}	
	}

if (Vertrag == 'MK')
	{
	document.KALK.Ausgabewert.value=document.KALK.Ausgabewert.value*1.075;
	document.KALK.Ausgabewert.value=NachKomma2();	
	}		


var zwischenspeicher=document.KALK.Ausgabewert.value;
document.KALK.Ausgabewert.value=zwischenspeicher*100/EINGABEWERT;
ergebnis=document.KALK.Ausgabewert.value;
ergebnis=Runden(ergebnis,2);
document.KALK.Ausgabefaktor.value=ergebnis;
document.KALK.Ausgabewert.value=zwischenspeicher;
}

function uebernahme_angebot()
{
var a=9;
AR=new Array();
AR[1]=document.KALK.awert1.value;
AR[2]=document.KALK.awert2.value;
AR[3]=document.KALK.awert3.value;
AR[4]=document.KALK.awert4.value;
AR[5]=document.KALK.awert5.value;
AR[6]=document.KALK.awert6.value;
AR[7]=document.KALK.awert7.value;
AR[8]=document.KALK.awert8.value;
for(i=8;i >= 1;i--)
	{
	if (AR[i] ==''){var a=i;}
	};

if (a > 7)
	{
	alert("Deze offerte kan niet worden opgeslagen.");
	return false;
	}

if (document.KALK.Ausgabewert.value < 1 || document.KALK.Ausgabewert.value =='ontoelaatbaar')
   {
   alert ("Deze waarde kan niet worden overgenomen.");
   return false;
   }

if (document.KALK.Vertrag.value =='FLEX' && document.KALK.Pfaktor.value !='0')
   {
   alert ("Flex-leasing kan niet met ingecalculeerde provisie worden aangeboden.");
   return false;
   }

var uebergabe=document.KALK.Ausgabewert.value+' '+WAEHRUNG;   

for(i=8;i >= 1;i--)
	{
	if (uebergabe ==AR[i])
	{
	alert ("Deze offerte is al opgeslagen.");
	return false;
	}
	};


if (a==1){document.KALK.aart1.value=document.KALK.Vertrag.value;document.KALK.alz1.value=document.KALK.Laufzeit.value+' Maanden';document.KALK.awert1.value=uebergabe;document.KALK.aprov1.value=document.KALK.Pfaktor.value+' %';}
if (a==2){document.KALK.aart2.value=document.KALK.Vertrag.value;document.KALK.alz2.value=document.KALK.Laufzeit.value+' Maanden';document.KALK.awert2.value=uebergabe;document.KALK.aprov2.value=document.KALK.Pfaktor.value+' %';}
if (a==3){document.KALK.aart3.value=document.KALK.Vertrag.value;document.KALK.alz3.value=document.KALK.Laufzeit.value+' Maanden';document.KALK.awert3.value=uebergabe;document.KALK.aprov3.value=document.KALK.Pfaktor.value+' %';}
if (a==4){document.KALK.aart4.value=document.KALK.Vertrag.value;document.KALK.alz4.value=document.KALK.Laufzeit.value+' Maanden';document.KALK.awert4.value=uebergabe;document.KALK.aprov4.value=document.KALK.Pfaktor.value+' %';}
if (a==5){document.KALK.aart5.value=document.KALK.Vertrag.value;document.KALK.alz5.value=document.KALK.Laufzeit.value+' Maanden';document.KALK.awert5.value=uebergabe;document.KALK.aprov5.value=document.KALK.Pfaktor.value+' %';}
if (a==6){document.KALK.aart6.value=document.KALK.Vertrag.value;document.KALK.alz6.value=document.KALK.Laufzeit.value+' Maanden';document.KALK.awert6.value=uebergabe;document.KALK.aprov6.value=document.KALK.Pfaktor.value+' %';}
if (a==7){document.KALK.aart7.value=document.KALK.Vertrag.value;document.KALK.alz7.value=document.KALK.Laufzeit.value+' Maanden';document.KALK.awert7.value=uebergabe;document.KALK.aprov7.value=document.KALK.Pfaktor.value+' %';}
if (a==8){document.KALK.aart8.value=document.KALK.Vertrag.value;document.KALK.alz8.value=document.KALK.Laufzeit.value+' Maanden';document.KALK.awert8.value=uebergabe;document.KALK.aprov8.value=document.KALK.Pfaktor.value+' %';}
}

function delthis(a){
if (a==1){document.KALK.aart1.value='';document.KALK.alz1.value='';document.KALK.awert1.value='';document.KALK.aprov1.value='';}
if (a==2){document.KALK.aart2.value='';document.KALK.alz2.value='';document.KALK.awert2.value='';document.KALK.aprov2.value='';}
if (a==3){document.KALK.aart3.value='';document.KALK.alz3.value='';document.KALK.awert3.value='';document.KALK.aprov3.value='';}
if (a==4){document.KALK.aart4.value='';document.KALK.alz4.value='';document.KALK.awert4.value='';document.KALK.aprov4.value='';}
if (a==5){document.KALK.aart5.value='';document.KALK.alz5.value='';document.KALK.awert5.value='';document.KALK.aprov5.value='';}
if (a==6){document.KALK.aart6.value='';document.KALK.alz6.value='';document.KALK.awert6.value='';document.KALK.aprov6.value='';}
if (a==7){document.KALK.aart7.value='';document.KALK.alz7.value='';document.KALK.awert7.value='';document.KALK.aprov7.value='';}
if (a==8){document.KALK.aart8.value='';document.KALK.alz8.value='';document.KALK.awert8.value='';document.KALK.aprov8.value='';}

}


function NachKomma2()
{
  var punkt = false
  var s =window.document.KALK.Ausgabewert.value;

  var pospkt = s.indexOf(",")
  if(pospkt == -1)
  {
    pospkt = s.indexOf(".")
    if(pospkt == -1)
      return s + ".00"
    punkt = true
  }
  ergebnis=s.substring(0, pospkt) +
         (punkt ? "." : ",") +
         (s + "00").substring(pospkt + 1, pospkt + 3)
  return ergebnis;
}

function PunktNachKomma(x)
{
  var s = x.toString()

  var pospkt = s.indexOf(".")
  if(pospkt == -1)
    return s
  return s.substring(0, pospkt) +
         "," +
         s.substring(pospkt + 1, s.length)
}



function Runden(x, n)
{
  var stellen = Math.pow(10, n)
  return Math.round(x * stellen) / stellen
}

function Korrektur(x, n)
{
  var stellen = Math.pow(10, n)
  return Math.floor(x * stellen + .1) / stellen
}

function dasberechnung(){

document.KALK.dabetrag1.value=(document.KALK.dabetrag1.value).replace(/,/,".");
document.KALK.dabetrag2.value=(document.KALK.dabetrag2.value).replace(/,/,".");
document.KALK.dabetrag3.value=(document.KALK.dabetrag3.value).replace(/,/,".");

document.KALK.daservicebetrag1.value=(document.KALK.daservicebetrag1.value).replace(/,/,".");
document.KALK.daservicebetrag2.value=(document.KALK.daservicebetrag2.value).replace(/,/,".");
document.KALK.daservicebetrag3.value=(document.KALK.daservicebetrag3.value).replace(/,/,".");

document.KALK.mindestmenge1.value=(document.KALK.mindestmenge1.value).replace(/,/,".");
document.KALK.mindestmenge2.value=(document.KALK.mindestmenge2.value).replace(/,/,".");
document.KALK.mindestmenge2.value=(document.KALK.mindestmenge2.value).replace(/,/,".");


var aa=parseFloat(document.KALK.dabetrag1.value);
var bb=parseFloat(document.KALK.daservicebetrag1.value);
var cc=parseFloat(document.KALK.mindestmenge1.value);
document.KALK.dagesamt1.value=(aa+bb)*cc;

var dd=parseFloat(document.KALK.dabetrag2.value);
var ee=parseFloat(document.KALK.daservicebetrag2.value);
var ff=parseFloat(document.KALK.mindestmenge2.value);
document.KALK.dagesamt2.value=(dd+ee)*ff;

var gg=parseFloat(document.KALK.dabetrag3.value);
var hh=parseFloat(document.KALK.daservicebetrag3.value);
var ii=parseFloat(document.KALK.mindestmenge3.value);
document.KALK.dagesamt3.value=(gg+hh)*ii;

var jj=parseFloat(document.KALK.dagesamt3.value);
var kk=parseFloat(document.KALK.dagesamt2.value);
var ll=parseFloat(document.KALK.dagesamt1.value);

document.KALK.dagesamtbetrag.value=(jj+kk+ll);


if (document.KALK.dahardwarebetrag.value > 0)
{
	var zz=parseFloat(document.KALK.dahardwarebetrag.value);
	var yy=parseFloat(document.KALK.dagesamtbetrag.value);
	document.KALK.Ausgabewert.value=(zz+yy);
	document.KALK.Ausgabewert.value=NachKomma2();	
}

}


function Heute(){
 var Jetzt = new Date();
 var Tag = Jetzt.getDate();
 var Monat = Jetzt.getMonth() + 1;
 var Jahr = Jetzt.getYear();
 var Vortag  = ((Tag < 10) ? "0" : "");
 var Vormon  = ((Monat < 10) ? ".0" : ".");
 var Datum = Vortag + Tag + Vormon + Monat  + "." + Jahr;
 }
