function calc(fen,h,l){
	PopupCentre(fen,h,l,'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes')
}
function PopupCentre(page,largeur,hauteur,options) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

// Teste si le mail a une forme correcte
function checkmail(EMAIL) {
   var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,4}$/
   return (reg.exec(EMAIL)!=null)
}
// Teste le contenu des champs du form contacts avant submit
function testc(NOM,EMAIL){
   if(NOM.value=="") {
      alert("Indiquez votre nom !"); NOM.focus(); return false;
   }
   if(!checkmail(EMAIL.value)) {
      alert("Email incorrect !"); EMAIL.focus(); return false;
   }
   return true;
}
// Teste le contenu des champs du form demande de bordereau avant submit
function testb(NOM,PRENOM,NAISSANCE_DATE,NAISSANCE_LIEU,ADRESSE,PROFESSION,EMAIL,VERSEMENT_INITIAL,VERSEMENT_LIBRE,PERIODICITE){
   if(NOM.value=="") {
      alert("Indiquez votre nom !"); NOM.focus(); return false;
   }
   if(PRENOM.value=="") {
      alert("Indiquez votre prénom !"); PRENOM.focus(); return false;
   }
   if(NAISSANCE_DATE.value=="") {
      alert("Indiquez votre date de naissance !"); NAISSANCE_DATE.focus(); return false;
   }
   if(NAISSANCE_LIEU.value=="") {
      alert("Indiquez votre lieu de naissance !"); NAISSANCE_LIEU.focus(); return false;
   }
   if(ADRESSE.value=="") {
      alert("Indiquez votre adresse !"); ADRESSE.focus(); return false;
   }
   if(PROFESSION.value=="") {
      alert("Indiquez votre profession !"); PROFESSION.focus(); return false;
   }
   if(!checkmail(EMAIL.value)) {
      alert("Email incorrect !"); EMAIL.focus(); return false;
   }
   if(VERSEMENT_INITIAL.value=="") {
      alert("Indiquez le montant du versement initial !"); VERSEMENT_INITIAL.focus(); return false;
   }
   if(VERSEMENT_LIBRE.value=="") {
      alert("Indiquez le montant des versement libres !"); VERSEMENT_LIBRE.focus(); return false;
   }
   if(PERIODICITE.value=="") {
      alert("Indiquez la périodicité des versement libres !"); PERIODICITE.focus(); return false;
   }
   return true;
}

var bookmarkurl="http://www.discount-placements.com"
var bookmarktitle="DISCOUNT-PLACEMENTS"
function addbookmark(){
if (document.all)
window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

//********variable pour les calculettes*******
//a Année par défaut
//t Taux par défaut
//n Anné naissance par defaut
var a=10;		
var t=5;
var n=1965;		

function calc1(){
	var initial=document.o.ical_2.value
	var mensuel=document.o.ical_1.value
	var duree=document.o.duree.value
	var taux=document.o.taux.value
	if (duree=="") return ;
	if (taux=="") return ;
	if (initial=="" & mensuel=="") return ;
	if (mensuel=="") {mensuel=0; document.o.ical_1.value=0}  ;
	if (initial=="") {initial=0; document.o.ical_2.value=0};
	taux = taux/100 ;
	mtt = initial * Math.pow(1+taux,duree) + mensuel * (Math.pow(1+taux/12,duree*12)-1) / ( taux /12 ) ;
	mtt = Math.round(mtt,0);
	document.o.res_1.value=mtt;	
}

function calc2(){
	var initial=document.o.ical_4.value
	var souhait=document.o.ical_3.value
	var duree=document.o.duree.value
	var taux=document.o.taux.value	
	if ( duree == "" ) return ;
	if ( taux == "" ) return ;	
	if (initial=="" & souhait=="") return ;
	if (souhait=="") {souhait=0; document.o.ical_3.value=0}  ;
	if (initial=="") {initial=0; document.o.ical_4.value=0};
	taux = taux/100 ;
	mtt = ((souhait-(initial * Math.pow(1+taux/12,duree*12)))*(taux/12)/((Math.pow(1+taux/12,duree*12))-1));
	mtt = Math.round(mtt,0);
	document.o.res_2.value=mtt;
}

function calc3(){
	var capital=document.o.ical_5.value
	var mensuel=document.o.ical_6.value
	var duree=document.o.duree.value
	var taux=document.o.taux.value	
	if (duree=="") return ;
	if (taux=="") return ;	
	if (capital=="" & mensuel=="") return ;
	if (capital=="") {capital=0; document.o.ical_5.value=0}  ;
	if (mensuel=="") {mensuel=0; document.o.ical_6.value=0};
	taux = taux/100 ;
		
	mtt=(capital - mensuel * (Math.pow(1+taux/12,duree*12)-1) / ( taux /12 )) /Math.pow(1+taux,duree) ;

	mtt = Math.round(mtt,0);
	document.o.res_3.value=mtt;
}


function calc4(){
	var today= new Date();
	var year = today.getFullYear();
	var capital
	var rente_annu
	var rente_mens
	var taux=document.o.taux.value
	var mensuel=document.o.ical_1.value	
	
	if (((eval(document.o.naissance.value) + eval(document.o.depart_retraite.value))- eval(year))<=0){
		window.alert ("pb")
	}else{		
		var duree=(eval(document.o.naissance.value) + eval(document.o.depart_retraite.value))- eval(year)
		if (taux=="") return ;
		if (mensuel=="") {mensuel=0; document.o.ical_1.value=0}  ;
		taux = taux/100 ;
		capital = mensuel * (Math.pow(1+taux/12,duree*12)-1) / ( taux /12 ) ;
				
		rente_annu= capital* trouveTaux(document.o.naissance.value,document.o.depart_retraite.value)/100
		rente_mens=rente_annu/12
		
		rente_annu=Math.round(rente_annu,0);
		rente_mens=Math.round(rente_mens,0);
		
		document.o.res_1.value=rente_annu;	
		document.o.res_2.value=rente_mens;	
	}
}


function trouveTaux(dn,dr)
{
	var x
	var y= dr-60
	if (dn>=1932 & dn<=1939){x=0}
	if (dn>=1938 & dn<=1947){x=1}
	if (dn>=1946 & dn<=1954){x=2}
	if (dn>=1953 & dn<=1960){x=3}
	if (dn>=1959 & dn<=1967){x=4}
	if (dn>=1966 & dn<=1974){x=5}
	if (dn>=1973 & dn<=1981){x=6}
	if (dn>=1980){ x=7}
	
	tprv= new Array(8,6);
	
//entre 1932-1939
	tprv[0,0]=5.0942; tprv[0,1]=5.2201; tprv[0,2]=5.3548; tprv[0,3]=5.4995; tprv[0,4]=5.6554; tprv[0,5]=5.8237;
//entre 1938-1947
	tprv[1,0]=4.9771; tprv[1,1]=5.0942; tprv[1,2]=5.2201; tprv[1,3]=5.3548; tprv[1,4]=5.4995; tprv[1,5]=5.6554;
//entre 1946-1954
	tprv[2,0]=4.8677; tprv[2,1]=4.9771; tprv[2,2]=5.0942; tprv[2,3]=5.2201; tprv[2,4]=5.3548; tprv[2,5]=5.4995;	
//entre 1953-1960
	tprv[3,0]=4.7652; tprv[3,1]=4.8677; tprv[3,2]=4.9771; tprv[3,3]=5.0942; tprv[3,4]=5.2201; tprv[3,5]=5.3548;
//entre 1959-1967
	tprv[4,0]=4.6691; tprv[4,1]=4.7652; tprv[4,2]=4.8677; tprv[4,3]=4.9771; tprv[4,4]=5.0942; tprv[4,5]=5.2201;
//entre 1966-1974
	tprv[5,0]=4.5786; tprv[5,1]=4.6691; tprv[5,2]=4.7652; tprv[5,3]=4.8677; tprv[5,4]=4.9771; tprv[5,5]=5.0942;
//entre 1973-1981
	tprv[6,0]=4.4933; tprv[6,1]=4.5786; tprv[6,2]=4.6691; tprv[6,3]=4.7652; tprv[6,4]=4.8677; tprv[6,5]=4.9771;
//>1980
	tprv[7,0]=4.4126; tprv[7,1]=4.4933; tprv[7,2]=4.5786; tprv[7,3]=4.6691; tprv[7,4]=4.7652; tprv[7,5]=4.8677;
	
	//window.alert(x +" - " + y)
	return tprv[x,y];
}


function ctaux(){
var d=document.o.taux.value
	if (d='' || d<=0 || d>99 ){ 
		window.alert("Le taux n'est pas valide.") 
		document.o.taux.value=t
	}
}


function cduree()
{
	var d=document.o.duree.value
	if (d!='' & d>0 & d<99 ){
		document.o.ans1.value=document.o.duree.value;
		document.o.ans2.value=document.o.duree.value;
		document.o.ans3.value=document.o.duree.value;
	}else{
		window.alert("La durée n'est pas valide.")
		document.o.duree.value=a
	}
}

function init(){
	document.o.ans1.value=a;document.o.ans2.value=a;document.o.ans3.value=a;
	document.o.ical_1.value=0;document.o.ical_2.value=0;document.o.ical_3.value=0;document.o.ical_4.value=0;document.o.ical_5.value=0;document.o.ical_6.value=0;
	document.o.res_1.value="";document.o.res_2.value="";document.o.res_3.value="";
	document.o.taux.value=t;document.o.duree.value=a;
}

function Formatc(c){
	var tl = parseInt(c);
	var tr = c - tl;
	var fr = (Math.round(tr*100))/100;
	if (fr==0){
		return eval(tl)+eval(fr)+'.00';
	}else{
		if (fr==.9 || fr==.8 || fr==.7 || fr==.6 || fr==.5 || fr==.4 || fr==.3 || fr==.2 || fr==.1){
			return eval(tl)+eval(fr)+'0';
		}else{
			xx=c.toString();
			i=xx.indexOf('.');
			return xx.substring(0,i+3);
		}
	}
}