// section pour le cookie
var expDays = 30; 
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*30*24*60*60*1000)); 
// fin section pour le cookie

var isIE3 = (navigator.appVersion.indexOf("MSIE 3") != -1) ? true : false ;
if (isIE3 == false) self.window.focus();
var FureteurP = "Win" ;
var FureteurV = "3" ;
var FureteurT = "Exp" ;
var cookieValeures = "";

var theAgent = navigator.userAgent ;
if (theAgent.indexOf("Mac") >= 0) FureteurP = "Mac" ;

theAgent = navigator.appName ;
if (theAgent.indexOf("Netscape") >= 0) FureteurT = "Net" ;

theAgent = navigator.appVersion ;
if (theAgent.indexOf("2.") >= 0) FureteurV = "2" ;
if (theAgent.indexOf("3.") >= 0) FureteurV = "3" ;
if (theAgent.indexOf("4.") >= 0) FureteurV = "4" ;
if (theAgent.indexOf("5.") >= 0) FureteurV = "5" ;

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.") ;
                                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") ;      
                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.") ;
                                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") ;  
                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 == "1" && vPERIODE == "30") vNEC = -1564 ;
      if (vTPAY == "1" && vPERIODE == "40") vNEC = -2084 ;	  
      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 == "2" && vPERIODE == "30") vNEC = -782 ;
      if (vTPAY == "2" && vPERIODE == "40") vNEC = -1042 ;	  
      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 ;
      if (vTPAY == "3" && vPERIODE == "30") vNEC = -360 ;
      if (vTPAY == "3" && vPERIODE == "40") vNEC = -480 ;	  
      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 ;	  

		cookieValeures = vPRIX + "::" + vINIT + "::" + vMHYP + "::" + vTAUX + "::" + vPERIODE + "::" + vTPAY;
	}
	SetCookie('calcHypo', cookieValeures, exp);
}

function fClose() {
	window.opener.ouvert = false ;
	window.close();
}

