function convertClick() {
	if (verifValeurs()) {
		monnaie=1-monnaie;
		coeff=(monnaie==1)?1/pariteEuro:pariteEuro;
		document.frm.montant.value=inttostr(Math.round(strtoint(document.frm.montant.value)*coeff));
		ongletClick(onglet);
	}
	return false;
}
function ongletClick(ong,winName) {
	if (verifValeurs()) {
		l="index.php?client="+client+"&tpl="+template+"&ong="+ong+"&mnn="+monnaie;
		
		l+="&mnt="+strtoint(document.frm.montant.value);
		l+="&txi="+strtofloat(document.frm.tauxInteret.value);
		l+="&txir="+strtofloat(document.frm.tauxInteretRev.value);
		l+="&txa="+strtofloat(document.frm.tauxAssurance.value);
		l+="&prv="+strtofloat(document.frm.pourcentRev.value);
		l+="&sce="+document.frm.scenario.value;
		l+="&grf="+document.frm.graphic.value;
		l+="&ava="+document.frm.avance.value;
		l+="&cml="+document.frm.cumul.value;
		l+="&vt1="+strtofloat(document.frm.varTaux1.value);
		l+="&vt2="+strtofloat(document.frm.varTaux2.value);
		l+="&vt3="+strtofloat(document.frm.varTaux3.value);
	
		if ((onglet==1)||(onglet==9)) {
			l+="&dur="+document.frm.duree.options[document.frm.duree.selectedIndex].text;
			l+="&duri="+document.frm.dureeInterm.options[document.frm.dureeInterm.selectedIndex].text;
			l+="&durv="+document.frm.dureeRev.options[document.frm.dureeRev.selectedIndex].text;
			l+="&hau="+document.frm.hausse.options[document.frm.hausse.selectedIndex].value;
			l+="&bai="+document.frm.baisse.options[document.frm.baisse.selectedIndex].value;
		} else {
			l+="&dur="+document.frm.duree.value;
			l+="&duri="+document.frm.dureeInterm.value;
			l+="&durv="+document.frm.dureeRev.value;
			l+="&hau="+document.frm.hausse.value;
			l+="&bai="+document.frm.baisse.value;
		}
	
		if (((onglet==2)||(onglet==9))&&(scenario==1)) {
			l+="&dv1="+document.frm.varDuree1.options[document.frm.varDuree1.selectedIndex].text;
			l+="&dv2="+document.frm.varDuree2.options[document.frm.varDuree2.selectedIndex].text;
			l+="&dv3="+document.frm.varDuree3.options[document.frm.varDuree3.selectedIndex].text;
		} else {
			l+="&dv1="+document.frm.varDuree1.value;
			l+="&dv2="+document.frm.varDuree2.value;
			l+="&dv3="+document.frm.varDuree3.value;
		}

		location=l;
	}
	return false;
}
function verifValeurs() {
	var verifValeurs=0;
	if (strtoint(document.frm.montant.value)<=0)
		jalert("Veuillez indiquer le montant du prêt")
	else
		verifValeurs=1;
	return verifValeurs;
}
function calcClick() {
	if ((onglet==1)||(onglet==6))
		return ongletClick(2)
	else
		return ongletClick(onglet);
}
function dureeChange() {
	d=document.frm.duree.options[document.frm.duree.selectedIndex].text;
	s=eval("document.frm.tauxInteret"+d+".value");
	document.frm.tauxInteret.value = floattostr(s);
	s=eval("document.frm.tauxInteretRev"+d+".value");
	document.frm.tauxInteretRev.value = floattostr(s);

	di=document.frm.dureeInterm.options[document.frm.dureeInterm.selectedIndex].text;
	dureeInterm=document.frm.dureeInterm;
	for (i=dureeInterm.length-1; i>=0; i--) dureeInterm.options[i]=null;
	opt=new Array;
	for (i=0; i<d-1; i++) {
		opt[i]=new Option(i+1,"");
		dureeInterm.options[i]=opt[i];
	}
	document.frm.dureeInterm.selectedIndex=Math.min(di-1,d-2);
}
function scenarioClick() {
	document.frm.scenario.value=1-document.frm.scenario.value;
	ongletClick(onglet);
}
function graphicClick() {
	document.frm.graphic.value=1-document.frm.graphic.value;
	ongletClick(onglet);
}
function avanceClick() {
	document.frm.avance.value=1-document.frm.avance.value;
	ongletClick(onglet);
}
function cumulClick() {
	document.frm.cumul.value=1-document.frm.cumul.value;
	ongletClick(onglet);
}
function persoClick(p,o) {
	document.frm.perso.value=p;
	if (persoClick.arguments.length<2) o=onglet;
	ongletClick(o);
}

function calcCoefPret(i,d)	{
	p=1;
	for (j=0; j<d; j++) p*=(1+i);
	return p;
}
function calcMens(mnt,dur,txi,txa) {
	mis=dur*12;
	if(modeAssurance==1) {
		txm=(txi+txa)/1200;
		prw=calcCoefPret(txm,mis);
		result=mnt*prw*txm/(prw-1);
	} else {
		txm=txi/1200;
		prw=calcCoefPret(txm,mis);
		result=mnt*(prw*txm/(prw-1)+txa/1200);
	}
	return result;
}
function calculer() {
	//monnaie=document.frm.monnaie.value;
	monnaie=1;
	if (monnaie==1) {
		monnaieSymbole=" €";
	} else {
		monnaieSymbole=" F";
	}
	montant=document.frm.montant.value;
	txa=strtofloat(document.frm.tauxAssurance.value);
	mensualitefix=calcMens(montant,duree,document.frm.tauxInteret.value,txa);
	annuifix=mensualitefix*12;

	totannuivar=0;
	for (i=1; i<=duree; i++) {
		obj = eval("document.frm.txv"+i);
		stxv = obj.value;
		tauxvar = strtofloat(stxv);
		mensualitevar=(calcMens(montant,duree,tauxvar,txa)*pourcentRev+mensualitefix*(100-pourcentRev))/100;
		annuivar=mensualitevar*12;
		totannuivar+=annuivar;

		obj = eval("document.frm.mnv"+i);
		obj.value = inttostr(mensualitevar)+monnaieSymbole;
		obj = eval("document.frm.ttv"+i);
		obj.value = inttostr(annuivar)+monnaieSymbole;

		obj = eval("document.frm.mnf"+i);
		obj.value = inttostr(mensualitefix)+monnaieSymbole;
		obj = eval("document.frm.ttf"+i);
		obj.value = inttostr(annuifix)+monnaieSymbole;

		obj = eval("document.frm.mne"+i);
		obj.value = inttostr(-mensualitevar+mensualitefix)+monnaieSymbole;
		obj = eval("document.frm.tte"+i);
		obj.value = inttostr(-annuivar+annuifix)+monnaieSymbole;
	}
	document.frm.tgv.value=inttostr(totannuivar)+monnaieSymbole;
	document.frm.tgf.value=inttostr(annuifix*duree)+monnaieSymbole;
	document.frm.tge.value=inttostr(-totannuivar+annuifix*duree)+monnaieSymbole;
}
function txchange(ednum) {
	if (ednum>1) {
		obj = eval("document.frm.txv"+ednum);
		txv = strtofloat(obj.value);
		if (txv > tauxvarmaxi) txv = tauxvarmaxi;
		if (txv < tauxvarmini) txv = tauxvarmini;
		obj.value = floattostr(txv);
		obj = eval("document.frm.txv"+(ednum-1));
		txvp = strtofloat(obj.value);
		obj = eval("document.frm.vartxv"+(ednum-1));
		obj.value = floattostr(txv-txvp);
	}else{
		document.frm.txv1.value=floattostr(tauxInteretRev+tauxAssurance);
	}
	if (ednum!=duree) {
		obj = eval("document.frm.txv"+(ednum+1));
		txvs = strtofloat(obj.value);
		obj = eval("document.frm.vartxv"+ednum);
		obj.value = floattostr(txvs-txv);
	}
	calculer()
}
function vartxchange(ednum) {
	for (i=ednum;i<duree;i++) {
		obj = eval("document.frm.txv"+i);
		txv = strtofloat(obj.value);
		obj = eval("document.frm.vartxv"+i);
		vartxv = strtofloat(obj.value,1);
		txvs = txv+vartxv;
		if (txvs > tauxvarmaxi) txvs = tauxvarmaxi;
		if (txvs < tauxvarmini) txvs = tauxvarmini;
		obj.value = floattostr(Math.round((txvs-txv)*100)/100);
		obj = eval("document.frm.txv"+(i+1));
		obj.value = floattostr(Math.round(txvs*100)/100);
	}
	calculer();
}
function up(ednum) {
	obj = eval("document.frm.vartxv"+ednum);
	v = Math.round((strtofloat(obj.value,1)+.5)*100)/100;
	obj.value = floattostr(v);
	vartxchange(ednum);
	return false;
}
function down(ednum) {
	obj = eval("document.frm.vartxv"+ednum);
	v = Math.round((strtofloat(obj.value,1)-.5)*100)/100;
	obj.value = floattostr(v);
	vartxchange(ednum);
	return false;
}
function curseurClick(pourcentFixe) {
	document.frm.pourcentRev.value=100-pourcentFixe;
	ongletClick(onglet);
}

