function credit(){
var totalpay = 0;
var investot = 0;
var perapp = 0;
var credtaux = 0;
var credass = 0;
var credlen = 0;
var total = 0;

totalpay = eval(document.devis.vala.value);
statusmar = eval(document.devis.statype.value);
perchargnb = eval(document.devis.pernb.value);
timp = TotalImpotCalc((totalpay * 0.9),statusmar,perchargnb);

if(totalpay > 0){
	document.getElementById("realcost").innerHTML = "Déduction 10% : " + FormatNumber(totalpay * 0.1) + " \u20AC";
	document.getElementById("baseimpots").innerHTML = "Impots avant défiscalisation : " + timp + " \u20AC";
}

credplaf = MaxCrdInter(statusmar,perchargnb);

investot = eval(document.devis.invest.value);
perapp = eval(document.devis.perapp.value);
totcred = investot - perapp;

	credtype = eval(document.devis.credtype.value);
	switch (credtype) {
		case 1:
			revtaux = 1;
		break;
		case 2:
			revtaux = 0.97;
		break;
		case 3:
			revtaux = 1.03;
		break;
	}

if((totcred > 0) && (totalpay > 0)){
	
	basetaux = eval(document.devis.crtaux.value);
	credtaux = basetaux / 100;
	pertaux = credtaux / 12;
	credass = (eval(document.devis.crass.value) / 100);
	asscost = totcred * (credass / 12);
	credlen = eval(document.devis.crtime.value);
	credmo = credlen * 12;
	
	ech = ((totcred * pertaux) / (1 - Math.pow((1 + pertaux), -credmo))) + asscost;
	
	if(credtype == 1)
		credcost = (ech * credmo) - totcred;
	else{
		revtauxcost = ((revtaux * credlen) * revtaux) / credlen;
		echrevc = ((totcred * (pertaux * revtauxcost)) / (1 - Math.pow((1 + (pertaux * revtauxcost)), -credmo))) + asscost;
		credcost = (echrevc * credmo) - totcred;
	}
	
	document.getElementById("creditotal").innerHTML = "Montant emprunté : " + FormatNumber(totcred) + " \u20AC"; 

	if(credcost >= 0){
		document.getElementById("coutcredit").innerHTML = "Coût du crédit : " + FormatNumber(credcost) + " \u20AC";
		document.getElementById("coutassur").innerHTML = "Coût de l\'assurance : " + FormatNumber(asscost * credmo) + " \u20AC";
	}
	
	if(ech >= 0){
		if(credtype == 1)
			echlist = "Echéance : " + FormatNumber(ech) + " \u20AC / mois"; 
		else{
			echlist = 'Moyennes des échéances :<br />';
			echrevtaux = 1;
			for(echynb=0 ; echynb<5 ; echynb++){
				echrev = ((totcred * (pertaux * echrevtaux)) / (1 - Math.pow((1 + (pertaux * echrevtaux)), -credmo))) + asscost;
				echlist = echlist + "- Année " + (echynb + 1) + " : " + FormatNumber(echrev) + " \u20AC / mois<br />";
				if(credtype == 2)
					echrevtaux = echrevtaux - 0.03;
				else
					echrevtaux = echrevtaux + 0.03;
			}
		}
		if(ech > (totalpay / 36))
			echlist = echlist + " <font color=#ff0000>Risque de dépassement du plafond !</font>";
		document.getElementById("echeance").innerHTML = echlist;
		
		for(ynb=0 ; ynb<5 ; ynb++){
			intcred = 0;
			if(totcred > 0){
				for(mnb=0 ; mnb<13 ; mnb++){
					if((pertaux > 0) && (totcred > 0))
						intcred = intcred + ((totcred * pertaux) + asscost);
			
					if(totcred > ech)
						totcred = totcred - ech + ((totcred * pertaux) + asscost);
					else
						totcred = 0;
				}
			}
		
			if(ynb == 0)
				interannu = intcred * 0.4;
			else
				interannu = intcred * 0.2;

			if(interannu > credplaf)
				interannu = credplaf;

				document.getElementById("ecoannu" + (ynb + 1)).innerHTML =  "- Année " + (ynb + 1) + " : " + FormatNumber(interannu)  + " \u20AC";
				total = total + interannu;
			
			pertaux = pertaux * revtaux;
		}
		document.getElementById("ecototal").innerHTML =  "Soit une économie totale de " + FormatNumber(total)  + " \u20AC sur 5 ans.";
	}
}

}