var CONTRACT_FEES = 0.0015 ;//pourcentagevar RETIREMENT_FEES = 0.00024991;var RATE_EUROSSIMA = 0.327374;var RATE_BALANCED = 0.5565415;var RATE_DYNAMIC = 0.797414;var RETIREMENT_YEAR = 65;/*************** calcul du total  ***************/function calculate_total(idInputTotal){    var tabHorizon = new Array();    switch(idInputTotal){        case 1:    // gestion horizon retraite            tabHorizon = Array("horizon_total","horizon_support1_montant","horizon_support2_montant","horizon_support3_montant","horizon_support4_montant","horizon_support5_montant");            break;        case 21:   // gestion libre 1 --> fond eurossima            tabHorizon = Array("libre_total","libre_fonderossima","libre_support1_montant","libre_support2_montant","libre_support3_montant","libre_support4_montant","libre_support5_montant","libre_support6_montant");            break;        case 22:   // gestion libre 2            tabHorizon = Array("libre_versementlibre_total","libre_versementlibre_support1Montant","libre_versementlibre_support2Montant","libre_versementlibre_support3Montant","libre_versementlibre_support4Montant","libre_versementlibre_support5Montant");            break;        case 3:     // gestion profilée            tabHorizon = Array("profilee_versementlibre_total","profilee_versementlibre_support1Montant","profilee_versementlibre_support2Montant","profilee_versementlibre_support3Montant","profilee_versementlibre_support4Montant","profilee_versementlibre_support5Montant");            break;    }    //jQuery.noConflict();    var calTotal = 0;    var obj=0;    for (var i=1;i<tabHorizon.length;i++){        //alert("#"+tabHorizon[i]);        obj = document.getElementById(tabHorizon[i]).value;        if(parseInt(obj)){            calTotal += parseInt(obj);        }    }    document.getElementById(tabHorizon[0]).value = calTotal;    }/*************** Commun functions ***************/function handleFormBlocsVisiblity(){    paramsArray = getRequestParamsAsArray();    numPage = paramsArray["page"];    if(numPage==19){// Etape 2        toggleVisibilityChequeBloc();    }else if(numPage==20){// Etape 3        toggleVisibilityNumYearBloc();    }else if(numPage==21){// Etape 4    //toggleVisibilityTypeGestion();    //toggleVisibilityGestionLibreVersement();    //toggleVisibilityLibreSecuristationFonds();    }else if(numPage==23){// Etape 6        toggleVisibilityTypeBeneficiaire();    }}function getRequestParamsAsArray(){    paramsString = window.location.search;    var paramsArray = new Array();    if (paramsString) {        paramsString = paramsString.substr(1);        var sNVPairs = paramsString.split("&");        for (var i = 0; i < sNVPairs.length; i++)        {                var sNV = sNVPairs[i].split("=");                var sName = sNV[0];                var sValue = sNV[1];                paramsArray[sName] = sValue;            }    }    return paramsArray;}function simulateRetirement(initialPayment,monthlyPayment,age){      $("#montant_actu").css('display','');    $("#simulateur_input").css('display','');    $("#capital_bloc").css('display','');    $("#capital").css('display','');       yearsNumber = RETIREMENT_YEAR - age;//.replace( ' ', '' )    monthsNumber = yearsNumber * 12;    reachedCapital = initialPayment;    for(month=1;month<=monthsNumber;month++){        tempNumMonth = monthsNumber-month;        tempNumYear = tempNumMonth/12;         rate = getRate(tempNumYear);        if(month==1){            reachedCapital = reachedCapital * rate;        }else{            reachedCapital = (reachedCapital+ monthlyPayment)* rate;        }        if(tempNumMonth % 3 == 0){            reachedCapital = reachedCapital - CONTRACT_FEES * reachedCapital - RETIREMENT_FEES * reachedCapital;        }    //reachedCapital =  Math.round(reachedCapital);    /* if(month==25){            reachedCapital = 38373;        //break;        }*/    /*if(month==48){            alert(reachedCapital);            break;                   //reachedCapital = 70561;        // alert(rate);        }*/    /*  if(month==52){            //reachedCapital = 70561;            /* alert(reachedCapital);            alert(Math.round(reachedCapital));            //reachedCapital = 38373;*/    //break;    //}           }    reachedCapital =  Math.round(reachedCapital);    additionalIncome =  Math.round(reachedCapital/monthsNumber);    $("#montant_actu").html(lisibilite_nombre(reachedCapital));    $("#capital").html(lisibilite_nombre(additionalIncome));}function lisibilite_nombre(nbr){    var nombre = ""+nbr;    var retour = "";    var count=0;    for(var i=nombre.length-1 ; i>=0 ; i--)    {        if(count!=0 && count % 3 == 0){            retour = nombre.charAt(i)+" "+retour ;        }else{            retour = nombre.charAt(i)+retour ;        }        count++;    }    return retour;}function getRate(numYear){    if (numYear <= 2){        eurossima_percentage = 1;        balanced_percentage = 0;        dynamic_percentage = 0;    }else if(numYear <= 4){        eurossima_percentage = 0.7;        balanced_percentage = 0.2;        dynamic_percentage = 0.1;    }else if (numYear <= 8 ) {        eurossima_percentage = 0.4;        balanced_percentage = 0.3;        dynamic_percentage = 0.3;    }else if (numYear <= 12 ){        eurossima_percentage = 0;        balanced_percentage = 0.5;        dynamic_percentage = 0.5;    }else if (numYear <= 16 ){        eurossima_percentage = 0;        balanced_percentage = 0.3;        dynamic_percentage = 0.7;    }else if (numYear <= 20 ){        eurossima_percentage = 0;        balanced_percentage = 0.1;        dynamic_percentage = 0.9;    }else{        eurossima_percentage = 0;        balanced_percentage = 0;        dynamic_percentage = 1;    }    rate = 1+ (eurossima_percentage * RATE_EUROSSIMA + balanced_percentage * RATE_BALANCED + dynamic_percentage * RATE_DYNAMIC)/100;//RATE_EUROSSIMA    return rate;}function validateForm(){    document.form.submit();}function returntoStep(numPage){    document.form.action="index.php?page="+numPage;    document.form.submit();}/****************** Step 1  *****************/function validateStep1Form() {    var message="";    if (document.form.name.value=="") message+=" - Nom obligatoire.\n";    if (document.form.firstname.value=="") message+=" - PrÃ©nom obligatoire.\n";    if (document.form.adresse.value=="") message+=" - Adresse obligatoire.\n";    if (document.form.cp.value=="") message+=" - Code postal obligatoire.\n";    if (document.form.ville.value=="") message+=" - Ville obligatoire.\n";    if (document.form.datenaissance.value=="") message+=" - Date de naissance obligatoire.\n";    if (document.form.lieunaissance.value=="") message+=" - Lieu de naissance obligatoire.\n";    if (document.form.departement.value=="") message+=" - DÃ©partement obligatoire.\n";    if (document.form.profession.value=="") message+=" - Profession obligatoire.\n";    if (message!="") {        alert("Les erreurs suivantes se sont produites :\n"+message);        return false;    } else {        if (!document.form.hasCoAssure.checked){            document.form.hasCoAssureHidden.value=0;            document.form.action="index.php?page=19";        }else{            document.form.hasCoAssureHidden.value=1;        }        document.form.submit();    }}/****************** Step 1 Bis *****************/function validateStep1BisForm() {    var message="";    if (document.form.co_name.value=="") message+=" - Nom obligatoire.\n";    if (document.form.co_firstname.value=="") message+=" - PrÃ©nom obligatoire.\n";    if (document.form.co_adresse.value=="") message+=" - Adresse obligatoire.\n";    if (document.form.co_cp.value=="") message+=" - Code postal obligatoire.\n";    document.form.co_checkVersementHidden.value = document.form.co_checkVersement.checked ? 1 : 0;    if (message!="") {        alert("Les erreurs suivantes se sont produites :\n"+message);        return false;    } else {        document.form.submit();    }}/****************** Step 2 *****************/// TODO test if the step 1 bis or the step 1 is the previous stepfunction validateStep2Form() {    document.form.modeReglementHidden.value =  document.form.checkModeReglement.checked ? 1:0;    document.form.checkvirementHidden.value =  document.form.checkVirement.checked ? 1:0;     document.form.submit();}function validateStep4Form() {    document.form.checkVersLibreHidden.value =  document.form.checkVersLibre.checked ? 1:0;    document.form.checkProfilee_profilprudent.value =  document.form.checkProfilee_profilprudent.checked ? 1:0;    document.form.checkProfilee_profilequilibre.value =  document.form.checkProfilee_profilequilibre.checked ? 1:0;    document.form.checkProfilee_profildynamique.value =  document.form.checkProfilee_profildynamique.checked ? 1:0;    document.form.checkProfilee_versementlibre.value =  document.form.checkProfilee_versementlibre.checked ? 1:0;    document.form.submit();}/******************* step 5 *******************/function validateStep5Form() {    var message="";    if (!document.form.checkCodeAcces.checked) message+=" - Confirmation de r\351ception code d'acc\350s obligatoire.\n";    if (message!="") {         alert("Les erreurs suivantes se sont produites :\n"+message);        return false;    } else {        document.form.checkCodeAccesHidden.value =  document.form.checkCodeAcces.checked ? 1:0;        document.form.submit();    }    }function validateStep7Form() {    var message="";    if (document.form.valeurtypeGestion.value==1){        if (parseInt(document.form.brutnet.value)<parseInt(document.form.brutnetsupport.value)) message+=" - (a) doit etre sup\351rieure que (b).\n";    }    if (message!="") {         alert("Les erreurs suivantes se sont produites :\n"+message);        return false;    } else {         document.form.submit();    }}function validateStep8Form() {    document.form.checkConditionsHidden.value =  document.form.checkConditions.checked ? 1:0;    document.form.submit();}function toggleVisibilityChequeBloc(){    if ($("checkModeReglement").checked){        $("ChequeBloc").show();    }else{        $("ChequeBloc").hide();    }}function toggleVisibilityMontantVerser(){    if ($("checkProfilee_profilprudent").checked || $("checkProfilee_profilequilibre").checked || $("checkProfilee_profildynamique").checked){        $("montant_transferer_div").show();    }else{        $("montant_transferer_div").hide();    }}/****************** Step 3 *****************/function toggleVisibilityNumYearBloc(){    //alert($("indetermine").checked);    if ($("indetermine").checked){        $("NumYearBloc").hide();    }else{        $("NumYearBloc").show();    }}/****************** Step 4 *****************/function toggleVisibilityTypeGestion(){    if ($("horizonOption").checked){        $("horizonBloc").show();        // libre bloc         $("libreBloc").hide();        $("libre_versementlibre_Bloc").hide();        $("libre_securisation_Bloc").hide();        $("libre_securisation_fondsEurossima_Bloc").hide();        $("libre_securisation_fondsSuivants_Bloc").hide();        // profilee bloc        $("profileeBloc").hide();        $("profileeBloc_verslibre").hide();    }else if ($("libreOption").checked) {        $("horizonBloc").hide();        /*if($("checkVersLibre").checked==false){            $("horizonBloc_versLibre").hide();        }else{            $("horizonBloc_versLibre").show();        }*/                $("horizonBloc_versLibre").hide();        $("libreBloc").show();        $("profileeBloc").hide();        $("profileeBloc_verslibre").hide();    }else{        $("horizonBloc").hide();        $("horizonBloc_versLibre").hide();                // libre bloc        $("libreBloc").hide();        $("libre_versementlibre_Bloc").hide();        $("libre_securisation_Bloc").hide();        $("libre_securisation_fondsEurossima_Bloc").hide();        $("libre_securisation_fondsSuivants_Bloc").hide();        // profilee bloc        $("profileeBloc").show();        if($("checkProfilee_versementlibre").checked==false){            $("profileeBloc_verslibre").hide();        }else{            $("profileeBloc_verslibre").show();        }    //$("profileeBloc_verslibre").hide();    }}function toggleVisibilityCheckProfilee_versementlibre(){    $("horizonBloc").hide();    $("horizonBloc_versLibre").hide();            // libre bloc    $("libreBloc").hide();    $("libre_versementlibre_Bloc").hide();    $("libre_securisation_Bloc").hide();    $("libre_securisation_fondsEurossima_Bloc").hide();    $("libre_securisation_fondsSuivants_Bloc").hide();    // profilee bloc    $("profileeBloc").show();    if($("checkProfilee_versementlibre").checked==false){        $("profileeBloc_verslibre").hide();    }else{        $("profileeBloc_verslibre").show();    }}function toggleVisibilityCheckVersLibre(){    if($("checkVersLibre").checked==false){        $("horizonBloc_versLibre").hide();    }else{        $("horizonBloc_versLibre").show();    }    $("horizonBloc").show();            // libre bloc    $("libreBloc").hide();    $("libre_versementlibre_Bloc").hide();    $("libre_securisation_Bloc").hide();    $("libre_securisation_fondsEurossima_Bloc").hide();    $("libre_securisation_fondsSuivants_Bloc").hide();    // profilee bloc    $("profileeBloc").hide();    $("profileeBloc_verslibre").hide();}function toggleVisibilityGestionLibreVersement(){    if ($("libre_withoutCostOption").checked){        $("libre_versementlibre_Bloc").show();        $("libre_securisation_Bloc").hide();        $("libre_securisation_fondsEurossima_Bloc").hide();        $("libre_securisation_fondsSuivants_Bloc").hide();    //$("libre_securisation_fondsEurossimaOption").removeAttribute("checked");    //$("libre_securisation_fondsSuivantOption").removeAttribute("checked");    }else{        $("libre_versementlibre_Bloc").hide();        $("libre_securisation_Bloc").show();    }}function toggleVisibilityLibreSecuristationFonds(){    if ($("libre_securisation_fondsEurossimaOption").checked){        $("libre_securisation_fondsEurossima_Bloc").show();        $("libre_securisation_fondsSuivants_Bloc").hide();    }else{        $("libre_securisation_fondsEurossima_Bloc").hide();        $("libre_securisation_fondsSuivants_Bloc").show();    }}function hideWithCostFields(checkbox){    if(checkbox.checked){        $("horizon_mensuelle").disable();        $("horizon_trimestrielle").disable();        $("horizon_semestrielle").disable();        $("horizon_annuelle").disable();        $("horizon_support1_label").disable();        $("horizon_support1_ISIN").disable();        $("horizon_support1_montant").disable();        $("horizon_support2_label").disable();        $("horizon_support2_ISIN").disable();        $("horizon_support2_montant").disable();        $("horizon_support3_label").disable();        $("horizon_support3_ISIN").disable();        $("horizon_support3_montant").disable();        $("horizon_support4_label").disable();        $("horizon_support4_ISIN").disable();        $("horizon_support4_montant").disable();        $("horizon_support5_label").disable();        $("horizon_support5_ISIN").disable();        $("horizon_support5_montant").disable();        $("horizon_total").disable();    }else{        $("horizon_mensuelle").enable();        $("horizon_trimestrielle").enable();        $("horizon_semestrielle").enable();        $("horizon_annuelle").enable();        $("horizon_support1_label").enable();        $("horizon_support1_ISIN").enable();        $("horizon_support1_montant").enable();        $("horizon_support2_label").enable();        $("horizon_support2_ISIN").enable();        $("horizon_support2_montant").enable();        $("horizon_support3_label").enable();        $("horizon_support3_ISIN").enable();        $("horizon_support3_montant").enable();        $("horizon_support4_label").enable();        $("horizon_support4_ISIN").enable();        $("horizon_support4_montant").enable();        $("horizon_support5_label").enable();        $("horizon_support5_ISIN").enable();        $("horizon_support5_montant").enable();        $("horizon_total").enable();    }}function returnToStep3(){    document.form.action="index.php?page=20";    document.form.submit();}/****************** Step 5 *****************/function returnToStep4(){    document.form.action="index.php?page=21";    document.form.submit();}/****************** Step 6 *****************/function returnToStep5(){    document.form.action="index.php?page=22";    document.form.submit();}function toggleVisibilityTypeBeneficiaire(){    if ($("autresOption").checked){        $("beneficiaires").show();    }else{        $("beneficiaires").hide();    }}function calculateEtape7(){    var age = document.form.ageSouscripteur.value;    var nbrAnneeRetr = 65-parseInt(age);    var finalValue;    //alert(nbrAnneeRetr);    if(nbrAnneeRetr>=9){        finalValue = 0;    }else if(nbrAnneeRetr>=5){        finalValue = 40;    }else if(nbrAnneeRetr>=3){        finalValue = 70;    }else{        finalValue = 100;    }    //alert(finalValue);    document.form.brutnetsupport.value = finalValue;}
