function verifValeurs() {
	var msg="";
	var verifValeurs=0;
	var f = document.frm;
	var nbpersonne=parseInt(f.nbpersonne.value);
	var MaxEtape = nbpersonne+2;
	if (f.a2n1.value=="" || f.a2n1.value < 1900) msg+="   * Veuillez indiquer l'ann\351e de naissance\n";
	if (f.npa1.value=="") msg+="   * Veuillez indiquer le NPA\n";
	if (parseInt(f.npa1.value) < 1000 || parseInt(f.npa1.value) > 2000) {
		msg+="   * le calculer de nos prime est bas\351 uniquement pour le canton de Vaud.\n";
	}
	
	var cpta2n=0; var cptnpa=0; var testnpa=0;
	
	if(msg == "") {
		for(i=1;i<=nbpersonne; i++) {
			if (eval("f.a2n"+i+".value")==""  || eval("f.a2n"+i+".value") < 1900) cpta2n++;
			if (eval("f.npa"+i+".value")=="") cptnpa++;
			if (parseInt(eval("f.npa"+i+".value")) < 1000 || parseInt(eval("f.npa"+i+".value")) > 2000) testnpa++;
		}	
	}
	if(cpta2n > 0) msg+="   * Pour chaque personne \340 assurer, il faut indiquer l'ann\351e de naissance\n";
	if(cptnpa > 0) msg+="   * Pour chaque personne \340 assurer, il faut indiquer le NPA\n";
	if(testnpa > 0) msg+="  * le calculer de nos prime est bas\351 uniquement pour le canton de Genève.\n";

	if(etape >=3 && etape <=MaxEtape) {
		var p=etape-2;				
		if (eval("f.nom"+p+".value")=="") msg+="   * Veuillez indiquer le nom.\n";
		if (eval("f.prenom"+p+".value")=="") msg+="   * Veuillez indiquer le pr\351nom.\n";
		if (eval("f.jour"+p+".value")=="" || eval("f.mois"+p+".value")=="" || eval("f.annee"+p+".value")=="") 
			msg+="   * Veuillez indiquer la date de naissance.\n";
		if (eval("f.cp"+p+".value")=="") msg+="   * Veuillez indiquer le num\351ro postal.\n";
		if (eval("f.domicile"+p+".value")=="") msg+="   * Veuillez indiquer le domicile.\n";			
		if (eval("f.tel"+p+".value")=="") msg+="   * Veuillez indiquer le t\351l\351phone.\n";	
		var e=eval("f.email"+p+".value");
		if(e!="") {
			var t=e.indexOf('@');
			if (t<1 || t==(e.length-1)) msg+="   * E-mail non valide.\n";
		} else { 
			msg+="   * Veuillez indiquer l'e-mail.\n";
		}
		if (eval("f.medecin"+p+".value")=="") msg+="   * Veuillez indiquer le m\351decin choisi.\n";	
	}
	
	if(msg=="")	verifValeurs=1;
	else alert("Les données saisies contiennent des erreurs.\n"+msg);
	return verifValeurs;
}

function etapeClick(obj) {
	var f = document.frm;
	var l="calculez-vos-primes.php?etape="+obj+"&nbpersonne="+f.nbpersonne.value;
	if (etape==1) {
		for(x=1;x<=10; x++) for (i=0;i<eval("f.sexe"+x+".length");i++) 
			if (eval("f.sexe"+x+"["+i+"].checked")) eval("sexe"+x+"=f.sexe"+x+"["+i+"].value")
		for(x=1;x<=10; x++)	for (i=0;i<eval("f.acc"+x+".length");i++) 
			if (eval("f.acc"+x+"["+i+"].checked")) eval("acc"+x+"=f.acc"+x+"["+i+"].value")
	} else { 
		for(i=1;i<=10; i++) eval("sexe"+i+"=f.sexe"+i+".value");
		for(i=1;i<=10; i++) eval("acc"+i+"=f.acc"+i+".value"); 
	}
	
	if (etape > 2) {
		for(x=1;x<=10; x++)	for (i=0;i<eval("f.contacter"+x+".length");i++) 
			if (eval("f.contacter"+x+"["+i+"].checked")) eval("contacter"+x+"=f.contacter"+x+"["+i+"].value")
	} else { 
		for(i=1;i<=10; i++) {
			eval("contacter"+i+"=f.contacter"+i+".value"); 
		}
	}
	
	for(i=1;i<=10; i++) {
		l+="&a2n"+i+"="+eval("f.a2n"+i+".value");	
		l+="&frch"+i+"="+eval("f.frch"+i+".value");				
		l+="&acc"+i+"="+eval("acc"+i+"");
		l+="&npa"+i+"="+eval("f.npa"+i+".value");	
		l+="&sexe"+i+"="+eval("sexe"+i+"");
		
		l+="&nom"+i+"="+eval("f.nom"+i+".value");				
		l+="&prenom"+i+"="+eval("f.prenom"+i+".value");				
		l+="&jour"+i+"="+eval("f.jour"+i+".value");				
		l+="&mois"+i+"="+eval("f.mois"+i+".value");		
		l+="&annee"+i+"="+eval("f.annee"+i+".value");		
		l+="&cp"+i+"="+eval("f.cp"+i+".value");				
		l+="&domicile"+i+"="+eval("f.domicile"+i+".value");				
		l+="&tel"+i+"="+eval("f.tel"+i+".value");				
		l+="&periode"+i+"="+eval("f.periode"+i+".value");				
		l+="&email"+i+"="+eval("f.email"+i+".value");	
		l+="&contacter"+i+"="+eval("contacter"+i+"");			
		l+="&message"+i+"="+eval("f.message"+i+".value");				
		l+="&medecin"+i+"="+eval("f.medecin"+i+".value");				
	}

	location=l;
	return false;
}

function calcClick(n) {
	if (verifValeurs()) {	
		return etapeClick(n);
	}
}

function ajouterPersonne() {
	if (verifValeurs()) {
		var nb=parseInt(document.frm.nbpersonne.value)+1;
		var ligne="ligne1";
		if (nb<=10) {
			document.frm.nbpersonne.value=nb;
			var o=document.getElementById("x"+nb);
			if(nb/2 == Math.round(nb/2)) ligne="ligne2";
			o.className=ligne;
		} else {
			alert ("Nombre maximum de personne atteint");
		}
		return false;
	}
}

function supprimerPersonne() {
	var nb=parseInt(document.frm.nbpersonne.value);
	if (nb>1) {
		var agree=confirm("Voulez vous supprimer un personne");	
		if(agree) {
			document.frm.nbpersonne.value=nb-1;
			var o=document.getElementById("x"+nb);
			o.className="nonvisible";
			eval("document.frm.a2n"+nb+".value=''");	
			eval("document.frm.npa"+nb+".value=''");
		}
	} else {
		alert ("Nombre minimum de personne est 1");
	}
}

function calcAge(d, d2n)  {
	var today = d.split("-");
	var today_annee = today[0];
	var today_mois = today[1];
	var today_jour = today[2];
	
	var tabd2n = d2n.split("-");
	var annee = tabd2n[0];
	var mois = tabd2n[1];
	var jour = tabd2n[2];

	var annees = today_annee - annee;
	if (today_mois <= mois) {
		if (mois == today_mois) {
		  if (jour > today_jour)
			annees--;
		}
		else
		  annees--;
	}
	return annees;
}

function selectFrch(d, val, n) {
  if(etape == 1) {
	var a2n = eval("document.frm.a2n"+n+".value"); 
	var d2n = a2n+"-01-01";
	var age = calcAge(d, d2n);
	if(age <= 18) {
	  eval("document.frm.frch"+n+".options.length = 7");	
	  eval("document.frm.frch"+n+".options[0].value='0'");   eval("document.frm.frch"+n+".options[0].text='0'"); 
	  eval("document.frm.frch"+n+".options[1].value='100'"); eval("document.frm.frch"+n+".options[1].text='100'"); 
	  eval("document.frm.frch"+n+".options[2].value='200'"); eval("document.frm.frch"+n+".options[2].text='200'"); 
	  eval("document.frm.frch"+n+".options[3].value='300'"); eval("document.frm.frch"+n+".options[3].text='300'"); 
	  eval("document.frm.frch"+n+".options[4].value='400'"); eval("document.frm.frch"+n+".options[4].text='400'"); 
	  eval("document.frm.frch"+n+".options[5].value='500'"); eval("document.frm.frch"+n+".options[5].text='500'"); 
	  eval("document.frm.frch"+n+".options[6].value='600'"); eval("document.frm.frch"+n+".options[6].text='600'");
	  if(val==0) index=0; else if(val==100) index=1; else if(val==200) index=2; else if(val==300) index=3;
	  else if(val==400) index=4; else if(val==500) index=5; else if(val==600) index=6; else index=0;
	} else {
	  eval("document.frm.frch"+n+".options.length = 6");	
	  eval("document.frm.frch"+n+".options[0].value='300'");  eval("document.frm.frch"+n+".options[0].text='300'"); 
	  eval("document.frm.frch"+n+".options[1].value='500'");  eval("document.frm.frch"+n+".options[1].text='500'"); 
	  eval("document.frm.frch"+n+".options[2].value='1000'"); eval("document.frm.frch"+n+".options[2].text='1000'"); 
	  eval("document.frm.frch"+n+".options[3].value='1500'"); eval("document.frm.frch"+n+".options[3].text='1500'"); 
	  eval("document.frm.frch"+n+".options[4].value='2000'"); eval("document.frm.frch"+n+".options[4].text='2000'"); 
	  eval("document.frm.frch"+n+".options[5].value='2500'"); eval("document.frm.frch"+n+".options[5].text='2500'"); 		
	  if(val==300) index=0; else if(val==500) index=1; else if(val==1000) index=2; else if(val==1500) index=3; 
	  else if(val==2000) index=4; else if(val==2500) index=5; else index=0;
	}
	eval("document.frm.frch"+n+".options.selectedIndex = "+index+"");
	
  }
}