
var run="";var loaded=false;var g2_erros="";var valPrix_d_achat=0;var valApport=0;var valMontant_du_ballon=0;var valTaux_annuel=0;var valDuree_en_mois=0;var valFrais_de_dossier=0;var valAutres_loyers=0;function monav(idname,pic)
{if(document.images&&loaded)
{document.images[idname].src=pic;}}
var curhelp="";function showhelp(formno,qty,helpid)
{if(document.getElementById("auto1")&&document.getElementById("auto2")&&document.getElementById("auto3")&&document.getElementById("auto4")&&document.getElementById("auto5")&&loaded)
{helpid="help"+formno+"-"+helpid;if(curhelp=="")
{for(n=1;n<=qty;n++)
{getID("help"+formno+"-"+n).style.display="none";}}
else
{getID(curhelp).style.display="none";}
if(getID(helpid))
{getID(helpid).style.display="";curhelp=helpid;getID("showall"+formno).style.display="";}}}
function showall(formno,qty)
{for(n=1;n<=qty;n++)
{getID("help"+formno+"-"+n).style.display="";}
window.focus();curhelp="";getID("showall"+formno).style.display="none";}
function selectID(pageFrom,pageTo,helpqty)
{g2_erros="";if(ValidatePage(pageFrom))
{if(pageFrom!=pageTo)
{eval("document.auto"+pageFrom+".style.visibility='hidden';");eval("document.auto"+pageTo+".style.visibility='visible';");eval("document.auto"+pageFrom+".style.position='absolute';");eval("document.auto"+pageTo+".style.position='static';");}
if(helpqty>0)
{eval("showall("+pageTo+","+helpqty+")");}
if(pageTo==2)
{if((valPrix_d_achat>=0)&&(valApport>=0))
{document.getElementById("CalculApport").innerHTML=numToFloatbis((Math.round(valPrix_d_achat*valApport)/100).toString())+"&nbsp;&euro;";}}
if(pageTo==3)
{if((pageFrom==2)||(pageFrom==1))
{if((valPrix_d_achat>=0)&&(valApport>=0))
{document.getElementById("emprunt").innerHTML="<b>"+numToFloatbis((Math.round((valPrix_d_achat-(valPrix_d_achat*(valApport/100)))*100)/100).toString())+"&nbsp;&euro;";}
else
{document.getElementById("emprunt").innerHTML="<b>"+numToFloatbis("0")+"&nbsp;&euro;";}
if(valPrix_d_achat>=0)
{soit=numToFloatbis((Math.round((valPrix_d_achat/2)*100)/100).toString());}
else
{soit="";}}
if(document.auto3.Simple_ballon[0].checked)
{document.getElementById("Montant").style.display="none";}
else
{document.getElementById("Montant").style.display="";}}
if(pageTo==4)
{if(valPrix_d_achat>=0)
{document.getElementById("auto4Prix_d_achat").innerHTML="<b>"+numToFloatbis(valPrix_d_achat.toString())+"&nbsp;&euro;";}
else
{document.getElementById("auto4Prix_d_achat").innerHTML="<b>"+numToFloatbis("0")+"&nbsp;&euro;";}
valDepot=document.auto4.Depot_de_garantie[document.auto4.Depot_de_garantie.selectedIndex].value;valOption=document.auto4.Option_d_achat[document.auto4.Option_d_achat.selectedIndex].value;valPremier=document.auto4.Premier_loyer_majore[document.auto4.Premier_loyer_majore.selectedIndex].value;document.getElementById("auto4DepotSoit").innerHTML="<b>"+numToFloatbis((Math.round(valPrix_d_achat*valDepot)/100).toString())+"&nbsp;&euro;";document.getElementById("auto4OptionSoit").innerHTML="<b>"+numToFloatbis((Math.round(valPrix_d_achat*valOption)/100).toString())+"&nbsp;&euro;";document.getElementById("auto4PremierSoit").innerHTML="<b>"+numToFloatbis((Math.round(valPrix_d_achat*valPremier)/100).toString())+"&nbsp;&euro;";}
if(pageTo=5)
{if(pageFrom!=2)
ValidatePage(2);if(pageFrom!=3)
ValidatePage(3);if(pageFrom!=4)
ValidatePage(4);CalculateResults();}}
else
{alert("Certaines donn\u00E9es sont erron\u00E9es.\nV\u00E9rifiez ces champs: "+g2_erros)}}
function CalculateResults()
{apport=Math.round(valPrix_d_achat*valApport)/100;if(document.auto3.Simple_ballon[0].checked)
{type_ballon=10;ballon=0;}
else
{type_ballon=20;ballon=valMontant_du_ballon;}
valDepot=document.auto4.Depot_de_garantie[document.auto4.Depot_de_garantie.selectedIndex].value;valOption=document.auto4.Option_d_achat[document.auto4.Option_d_achat.selectedIndex].value;valPremier=document.auto4.Premier_loyer_majore[document.auto4.Premier_loyer_majore.selectedIndex].value;valDuree_de_la_location=document.auto4.Duree_de_la_location[document.auto4.Duree_de_la_location.selectedIndex].value;if(valPremier=="")
{premier_loyer=numToFloatbis("0");}
else
{premier_loyer=(Math.round(valPrix_d_achat*valPremier)/100).toString();}
prix_pret=0;if(valTaux_annuel>0)
{taux_mensuel=valTaux_annuel/(12*100);denominateur=Math.pow((1+taux_mensuel),valDuree_en_mois);prix_pret=valPrix_d_achat-apport;if(type_ballon==10)
{mensualite1=Math.round((prix_pret*taux_mensuel)/(1-1/denominateur)*100)/100;}
else
{mensualite1=Math.round((prix_pret-valMontant_du_ballon/denominateur)*(taux_mensuel)/(1-1/denominateur)*100)/100;}}
else
{mensualite1=0;}
if(valOption=="")
{option_achat=0;}
else
{option_achat=Math.round(valPrix_d_achat*valOption)/100;}
if(type_ballon==10)
{cout_credit=(mensualite1*valDuree_en_mois)+valFrais_de_dossier}
else
{cout_credit=(mensualite1*valDuree_en_mois)+valFrais_de_dossier+valMontant_du_ballon;}
interests=cout_credit-prix_pret;cout_total=valPrix_d_achat+interests;cout_total_location=option_achat+(valAutres_loyers*valDuree_de_la_location)+(valPremier*valPrix_d_achat/100);document.getElementById("auto5Apport").innerHTML=numToFloatbis(apport.toString())+"&nbsp;&euro;";document.getElementById("auto5Ballon").innerHTML=numToFloatbis(ballon.toString())+"&nbsp;&euro;";document.getElementById("auto5Premier").innerHTML=numToFloatbis(premier_loyer.toString())+"&nbsp;&euro;";document.getElementById("auto5mensualite1").innerHTML=numToFloatbis(mensualite1.toString())+"&nbsp;&euro;";document.getElementById("auto5Autres_loyers").innerHTML=numToFloatbis(valAutres_loyers.toString())+"&nbsp;&euro;";document.getElementById("auto5Duree_en_mois").innerHTML=valDuree_en_mois.toString()+"&nbsp;mois";document.getElementById("auto5Duree_de_la_location").innerHTML=valDuree_de_la_location.toString()+"&nbsp;mois";document.getElementById("auto5option_achat").innerHTML=numToFloatbis(option_achat.toString())+"&nbsp;&euro;";document.getElementById("auto5Frais_de_dossier").innerHTML=numToFloatbis(valFrais_de_dossier.toString())+"&nbsp;&euro;";document.getElementById("auto5cout_credit").innerHTML=numToFloatbis((Math.round(cout_credit*100)/100).toString())+"&nbsp;&euro;";document.getElementById("auto5interests").innerHTML=numToFloatbis((Math.round(interests*100)/100).toString())+"&nbsp;&euro;";document.getElementById("auto5cout_total").innerHTML="<b>"+numToFloatbis((Math.round(cout_total*100)/100).toString())+"&nbsp;&euro;</b>";document.getElementById("auto5cout_total_location").innerHTML="<b>"+numToFloatbis((Math.round(cout_total_location*100)/100).toString())+"&nbsp;&euro;</b>";}
function addError(name)
{g2_erros=g2_erros+"\n"+name;}
function ValidatePage(tmp_current)
{if(tmp_current==2)
{if(!checkInput(2,"Prix_d_achat","N0"))
{addError("Prix d'achat");}
if(!checkInput(2,"Apport","P0"))
{addError("Apport");}}
if(tmp_current==3)
{if(!checkInput(3,"Montant_du_ballon","N0"))
{addError("Montant du ballon");}
if(!checkInput(3,"Taux_annuel","P"))
{addError("Taux annuel");}
if(!checkInput(3,"Duree_en_mois","N"))
{addError("Dur\u00E9e en mois");}
if(!checkInput(3,"Frais_de_dossier","N0"))
{addError("Frais de dossier");}}
if(tmp_current==4)
{if(!checkInput(4,"Autres_loyers","N0M"))
{addError("Autres loyers");}}
if(g2_erros!="")
return false;return true;}
function checkInput(formno,myInput,myType)
{var str,arg;var myInputName=myInput;var str=eval("document.auto"+formno+"."+myInput+".value");if(str!="")
{arg=str;arg=arg.replace(/ /g,"");myInput=arg;myInput=myInput.replace(/,/g,".");if(IsNumeric(arg))
{switch(myType)
{case"P":if((parseFloat(myInput)>0)&&(parseFloat(myInput)<=100))
{eval("val"+myInputName+"="+parseFloat(myInput));return true;}
else
{return false;}
break;case"P0":if((parseFloat(myInput)>=0)&&(parseFloat(myInput)<=100))
{eval("val"+myInputName+"="+parseFloat(myInput));return true;}
else
{return false;}
break;case"N":if(parseFloat(myInput)>0)
{eval("val"+myInputName+"="+parseFloat(myInput));return true;}
else
{return false;}
break;case"N0":if(parseFloat(myInput)>=0)
{eval("val"+myInputName+"="+parseFloat(myInput));return true;}
else
{return false;}
break;case"N0M":if((parseFloat(myInput)>=0)&&(parseFloat(myInput)<=10000000000))
{eval("val"+myInputName+"="+parseFloat(myInput));return true;}
else
{return false;}
break;}}
else
{return false;}}
else
{return false;}}
function _numToUnits(n,units_prefix,decimal_places,units_suffix)
{if(isOverflow(n))
return'<i>numeric overflow</i>'
var s=''
var d=strToInt(decimal_places)
var x=Math.abs(Math.round(n*Math.pow(10,decimal_places)))
if(x==0)
{var defaultStr='0'
if(d>0)
{defaultStr+=','
for(var i=0;i<d;i++)defaultStr+='0'}
defaultStr=units_prefix+defaultStr+units_suffix
return defaultStr}
if(d==0)
{var tmp=''+x
s=addCommas(tmp)}
else
{var leftTmp=''+x
var rightTmp=''+x
var len=leftTmp.length
for(var i=0;i<d+1-len;i++)
{leftTmp='0'+leftTmp
rightTmp='0'+rightTmp}
len=leftTmp.length
var decimalSplit=len-d
var leftStr=addCommas(leftTmp.substring(0,decimalSplit))
var rightStr=rightTmp.substring(decimalSplit,len)
s=leftStr+','+rightStr}
s=units_prefix+s+units_suffix
return s}
function numToFloatbis(n)
{n=n.replace(/ /g,"");if(n.length>0)
{return _numToUnits(n,"",2,"")}
return"";}
function IsNumeric(sText)
{var ValidChars="0123456789.,";var IsNumber=true;var Char;for(i=0;i<sText.length&&IsNumber==true;i++)
{Char=sText.charAt(i);if(ValidChars.indexOf(Char)==-1)
{IsNumber=false;}}
return IsNumber;}
function getID(thisID)
{var thisDiv=false;if(thisID!="")
{thisDiv=document.getElementById(thisID);}
else
{thisDiv=true;}
return(thisDiv);}
function start()
{loaded=true;if(run!=''){setTimeout(run,0);}}
start();