function HandleReturnKey(e) {
if (!e) e = window.event;
if (e.keyCode == 13) {
$('#btnCalculerMensu').click();
}
}
function HandleReturnKey2(e) {
if (!e) e = window.event;
if (e.keyCode == 13) {
$('#btnCalculerDuree').click();
}
}
function FormatPrix(value) {
return $().number_format(value, {
numberOfDecimals: 2,
decimalSeparator: '.',
thousandSeparator: ' ',
symbol: '€'
});
}
function calcMensu(){
var zprix, zapport, zduree, ztaux, zmensualite, temp;
var errApport=erreur_financement_apport_superieur;
$('.formInput.Mensu').each(function(){
$(this).val($(this).val().replace(",", "."));
if($(this).attr("name") == "duree")
zduree = parseFloat(this.value * 12);
if($(this).attr("name") == "taux")
ztaux = parseFloat((this.value / 100) / 12);
if($(this).attr("name") == "prix")
zprix = parseFloat(this.value);
if($(this).attr("name") == "apport")
zapport = parseFloat(this.value);
});
if(zduree == 0 && ztaux == 0 && zprix == 0 && zapport == 0) {
$('#resultMensuParAn').html(FormatPrix(0));
$('#resultMensuParMois').html(FormatPrix(0));
$('#resultMensuInteret').html(FormatPrix(0));
} else if(zapport > zprix){
$('.popup_warning.croix .contenu_texte').html(errApport);
lancementPopup("popup_warning.croix");
} else {
zvo = eval(zprix - zapport);
temp = Math.pow(1 + ztaux, -zduree);
temp = eval((1 - temp) / ztaux);
temp = eval(zvo / temp);
if(isNaN(Math.round((temp * 12) * 100) / 100)||temp<0)
$('#resultMensuParAn').html(erreur_financement_erreur_calcul)
else
$('#resultMensuParAn').html(FormatPrix(Math.round((temp * 12) * 100) / 100));
if(isNaN(Math.round(temp * 100) / 100)||temp<0)
$('#resultMensuParMois').html(erreur_financement_erreur_calcul)
else
$('#resultMensuParMois').html(FormatPrix(Math.round(temp * 100) / 100));
if(isNaN(Math.round(((temp * zduree) - zvo) * 100) / 100)||temp<0)
$('#resultMensuInteret').html(erreur_financement_erreur_calcul)
else
$('#resultMensuInteret').html(FormatPrix(Math.round(((temp * zduree) - zvo) * 100) / 100));
}
}
function calcDuree(){
var zvo, ztaux, zmensualite, zprix, zapport, temp;
var errApport=erreur_financement_apport_superieur;
$('.formInput.Duree').each(function(){
$(this).val($(this).val().replace(",", "."));
if($(this).attr("name") == "versement")
zmensualite = parseFloat(this.value);
if($(this).attr("name") == "taux")
ztaux = parseFloat((this.value / 100) / 12);
if($(this).attr("name") == "prix")
zprix = parseFloat(this.value);
if($(this).attr("name") == "apport")
zapport = parseFloat(this.value);
});
if(zmensualite == 0 && ztaux == 0 && zprix == 0 && zapport == 0) {
$('#resultNbMensu').html("0");
$('#resultNbAnnees').html("0 "+An);
} else if(zapport > zprix){
$('.popup_warning.croix .contenu_texte').html(errApport);
lancementPopup("popup_warning.croix");
} else {
zvo = eval(zprix - zapport);
temp = Math.log(1 - ( (zvo * ztaux) / zmensualite));
temp = Math.round(-(temp / Math.log(1 + ztaux)));
if (!parseInt(temp)) {
$('.popup_warning.croix .contenu_texte').html(erreur_financement_mensuInsuffisant);
lancementPopup("popup_warning.croix");
$('#resultNbMensu').html(erreur_financement_erreur_calcul)
$('#resultNbAnnees').html(erreur_financement_erreur_calcul);
$('#resultNbMois').html("");
} else {
$('#resultNbMensu').html(temp);
if(isNaN(parseInt(temp / 12)) || isNaN(temp % 12) || temp<0) {
$('#resultNbAnnees').html(erreur_financement_erreur_calcul);
$('#resultNbMois').html("");
} else {
if(parseInt(temp / 12) > 1) {
$('#resultNbAnnees').html(''+ parseInt(temp / 12)+" "+Ans+" "+simuEt);
} else {
$('#resultNbAnnees').html(''+ parseInt(temp / 12)+" "+An+" "+simuEt);
}
$('#resultNbMois').html(''+ eval(temp % 12)+" "+simuMois);
}
}
}
}
$(document).ready(function(){
$(".btnCalculer.Mensu").click(function(){
var erreur = "";
$('.formInput.Mensu').each(function(){ if( this.value == "" ){
erreur+=simuAlert+" "+$(this).attr("name")+".
";
$(this).css("border","1px solid red");
$(this).css("color","red");
var idDestination = $(this).attr('titre');
obj_titre = $('#'+idDestination);
$(obj_titre).css("color","red");
}
});
if(erreur!=""){ $('.popup_warning.croix .contenu_texte').html(erreur);
lancementPopup("popup_warning.croix");
}else
calcMensu();
});
$('.formInput.Mensu').keyup( function(e) {
if (e.keyCode == 13) {
e.preventDefault();
e.stopPropagation();
$('.formInput.Mensu').blur();
setTimeout( "$('.btnCalculer.Mensu').click();", 10 );
}
});
$(".btnCalculer.Duree").click(function(){
var erreur = "";
$('.formInput.Duree').each(function(){ if( this.value == "" ){
erreur+="\n"+simuAlert+" "+$(this).attr("name")+".
";
$(this).css("border","1px solid red");
$(this).css("color","red");
var idDestination = $(this).attr('titre');
obj_titre = $('#'+idDestination);
$(obj_titre).css("color","red");
}
});
if(erreur!=""){ $('.popup_warning.croix .contenu_texte').html(erreur);
lancementPopup("popup_warning.croix");
}else
calcDuree();
});
$('.formInput.Duree').keyup( function(e) {
if (e.keyCode == 13) {
e.preventDefault();
e.stopPropagation();
$('.formInput.Duree').blur();
setTimeout( "$('.btnCalculer.Duree').click();", 10 );
}
});
$('div.img_infoB').mouseout(function(){
$(this).children().css("display","none");
});
$('div.img_infoB').mouseover(function(){
affichage_InfoBulle($(this).attr("id"))
// $(this).children().css("display","block");
});
function affichage_InfoBulle(element){
var blocHeight = $('#'+element+' .i-infoB').height();
var positionIcone = $('#'+element+'').offset().top
var pageHeight = $(window).height();
var hautPage = $(document).scrollTop();
var basPage = hautPage+pageHeight;
if(hautPage < (positionIcone - blocHeight)) {
$('#'+element+' .i-infoB').css("top","-80px");
$('#'+element+' .fleche').css("display","block");
$('#'+element+' .fleche_inverse').css("display","none");
} else {
$('#'+element+' .i-infoB').css("top","25px");
$('#'+element+' .fleche_inverse').css("display","block");
$('#'+element+' .fleche').css("display","none");
}
$('#'+element+' .i-infoB').css("display","block");
}
});