/*******************************************fonction pour la calculette hypothécaire*****/

function VIDE (chV) {
vsRETV = 'O' ;
if (chV != null) {
  viLONGV = chV.length ;
  vsCHV = chV ;
  comptV = 0 ;
  while ((comptV < viLONGV) && (vsRETV == 'O')) {
    vsCARV = vsCHV.charAt(comptV) ;
    if (vsCARV > ' ') vsRETV = 'N' ;
    comptV +=1 ;
  }
}
return vsRETV ;
}

function fPRIX() {
with (document.hypo) {
        vNEWPRICE = prix.value ;
        var vStrLen = vNEWPRICE.length ;
        vCOMPT = 0;
        vChar = "";
        vOk = "";

        if (VIDE(vNEWPRICE) == "N") {
                while (vCOMPT < vStrLen) {
                        vChar = vNEWPRICE.charAt(vCOMPT);
                        if (vChar >= '0' && vChar <= '9') {
                                vOk = "true";
                        } else {
                                vOk = "false";
                                alert("Le prix ne doit contenir que des chiffres.\nPlease enter numbers only") ;
                                prix.value = vPRIX ;
                                prix.focus() ;
                                break;
                        }
                        vCOMPT++;
                }
                vPRIX = Math.abs(prix.value) ;
                vINITC = init.value ;
                if (VIDE(vINITC) == "N") {
                        vINIT = Math.ceil(init.value) ;
                } else {
                        init.value = Math.ceil(Math.abs(vPRIX) / 10) ;
                        vINIT = Math.ceil(init.value) ;
                }


					mhyp.value  = ((Math.abs(vPRIX) - Math.abs(vINIT))< 0) ? 0 : (Math.abs(vPRIX) - Math.abs(vINIT)) ;

        } else {
                alert("Le prix est obligatoire\nThe loan amount is required") ;
                prix.value = vPRIX ;
                prix.focus() ;
        }
}
}
function fINIT() {
with (document.hypo) {
        vNEWPRICE = init.value ;
        var vStrLen = vNEWPRICE.length ;
        vCOMPT = 0;
        vChar = "";
        vOk = "";

        if (VIDE(vNEWPRICE) == "N") {
                while (vCOMPT < vStrLen) {
                        vChar = vNEWPRICE.charAt(vCOMPT);
                        if (vChar >= '0' && vChar <= '9') {
                                vOk = "true";
                        } else {
                                vOk = "false";
                                alert("Le paiement initial ne doit contenir que des chiffres.Please enter numbers only") ;
                                init.value = Math.ceil(Math.abs(vPRIX) / 10) ;
                                vINIT = Math.ceil(init.value) ;
                                mhyp.value  = ((Math.abs(vPRIX) - Math.abs(vINIT))< 0) ? 0 : (Math.abs(vPRIX) - Math.abs(vINIT)) ;

										  init.focus() ;
                                break;
                        }
                        vCOMPT++;
                }
                if (vOk == "true") {
                        vINIT = Math.ceil(init.value) ;
                        mhyp.value  = ((Math.abs(vPRIX) - Math.abs(vINIT))< 0) ? 0 : (Math.abs(vPRIX) - Math.abs(vINIT)) ;

                }
        } else {
                alert("Le paiement initial est obligatoire\nThe put down price is required") ;
                init.value = Math.ceil(Math.abs(vPRIX) / 10) ;
                vINIT = Math.ceil(init.value) ;
                mhyp.value  = ((Math.abs(vPRIX) - Math.abs(vINIT))< 0) ? 0 : (Math.abs(vPRIX) - Math.abs(vINIT)) ;

                init.focus() ;
        }
}
}
function fCalcul() {
fPRIX();
with (document.hypo) {
      	mhyp.value  = ((Math.abs(vPRIX) - Math.abs(vINIT))< 0) ? 0 : (Math.abs(vPRIX) - Math.abs(vINIT)) ;
  		  vMHYP = Math.abs(mhyp.value) ;
		  vTPAY = t.options[t.selectedIndex].value ;
        vTAUX = i.options[i.selectedIndex].value ;
        vPERIODE = a.options[a.selectedIndex].value ;
        vPA = 1+(vTAUX/20000) ;
        if (vTPAY == "1") vPB = 14/365.25 ;
        if (vTPAY == "2") vPB = 28/365.25 ;
        if (vTPAY == "3") vPB = 2/12 ;
        vPC = Math.pow(vPA,vPB) - 1 ;
        vTPEH = Math.abs(vPC) * 100 ;

        if (vTPAY == "1" && vPERIODE == "10") vNEC = -522 ;
        if (vTPAY == "1" && vPERIODE == "15") vNEC = -783 ;
        if (vTPAY == "1" && vPERIODE == "20") vNEC = -1044 ;
        if (vTPAY == "1" && vPERIODE == "25") vNEC = -1304 ;
        if (vTPAY == "2" && vPERIODE == "10") vNEC = -261 ;
        if (vTPAY == "2" && vPERIODE == "15") vNEC = -381 ;
        if (vTPAY == "2" && vPERIODE == "20") vNEC = -522 ;
        if (vTPAY == "2" && vPERIODE == "25") vNEC = -652 ;
        if (vTPAY == "3" && vPERIODE == "10") vNEC = -120 ;
        if (vTPAY == "3" && vPERIODE == "15") vNEC = -180 ;
        if (vTPAY == "3" && vPERIODE == "20") vNEC = -240 ;
        if (vTPAY == "3" && vPERIODE == "25") vNEC = -300 ;

        vPA = 1+(vTPEH/100) ;
        vPC = Math.pow(vPA,vNEC) ;
        vPB = 1 - vPC ;
        vPD = vPB/(vTPEH/100) ;
        vVRAI = (vMHYP/vPD) + 0.005 ;
        versement.value = Math.ceil( vVRAI * 100 ) / 100  ;
        vVERS = versement.value  ;
        vLEN = vVERS.length ;
        vPOS = vVERS.lastIndexOf(".") ;
        if (vPOS == -1) vVERS += ".00" ;
        if (vPOS == (vLEN-2)) vVERS += "0" ;
        if (versement.value != vVERS) versement.value = vVERS ;

}
}
//fin fonction pour la calculette hypothécaire