//************************** FORMAT CHAMP CO-EMPRUNTEUR ***************************************
//*********************************************************************************************


function coEmp(){
	var A=document.forme_demande;
	
	if (A.co_emp.checked==false) {
		
		A.coemprunteur.value='pok';
	
		A.emp2[0].disabled="disabled";
		A.emp2[0].checked=false;
		A.emp2[1].disabled="disabled";
		A.emp2[1].checked=false;
		A.emp2[2].disabled="disabled";
		A.emp2[2].checked=false;
		
		A.nom2.disabled="disabled";
		A.nom2.style.background="#EDEBE8";		
		
		A.prenom2.disabled="disabled";
		A.prenom2.style.background="#EDEBE8";
		
		A.naissance2.disabled="disabled";
		A.naissance2.style.background="#EDEBE8";
		
		A.situFam2.disabled="disabled";
		A.situFam2.style.background="#EDEBE8";
		
		A.ad2.disabled="disabled";
		A.ad2.style.background="#EDEBE8";
		
		A.cp2.disabled="disabled";
		A.cp2.style.background="#EDEBE8";
		
		A.ville2.disabled="disabled";
		A.ville2.style.background="#EDEBE8";
		
		A.tel2.disabled="disabled";
		A.tel2.style.background="#EDEBE8";
		
		A.port2.disabled="disabled";
		A.port2.style.background="#EDEBE8";
		
		A.mail2.disabled="disabled";
		A.mail2.style.background="#EDEBE8";
		
		A.fumeur2[0].disabled="disabled";
		A.fumeur2[1].disabled="disabled";
		
		A.prof2.disabled="disabled";
		A.prof2.style.background="#EDEBE8"; 
		
		A.nat2.disabled="disabled";
		A.nat2.style.background="#EDEBE8"; 
		
		A.cadre2[0].disabled="disabled";
		A.cadre2[1].disabled="disabled";
		
		A.km2.disabled="disabled";
		A.km2.style.background="#EDEBE8";
		
		A.manuel2[0].disabled="disabled";
		A.manuel2[1].disabled="disabled";
		
		A.temps2.disabled="disabled";
		A.temps2.style.background="#EDEBE8";
	}
	else{
		
		A.coemprunteur.value='ok';
		
		A.emp2[0].disabled="";
		A.emp2[1].disabled="";
		A.emp2[2].disabled="";
		
		A.nom2.disabled="";
		A.nom2.style.background="#ffffff";
		
		/*A.nomj2.disabled="";
		A.nomj2.style.background="#ffffff";*/
		
		A.prenom2.disabled="";
		A.prenom2.style.background="#ffffff";
		
		A.nom2.disabled="";
		A.nom2.style.background="#ffffff";
		
		A.naissance2.disabled="";
		A.naissance2.style.background="#ffffff";
		
		/*A.nation2.disabled="";
		A.nation2.style.background="#ffffff";*/
		
		/*A.lieuNaiss2.disabled="";
		A.lieuNaiss2.style.background="#ffffff";
		
		A.deptNais2.disabled="";
		A.deptNais2.style.background="#ffffff";*/
		
		A.situFam2.disabled="";
		A.situFam2.style.background="#ffffff";
		
		A.ad2.disabled="";
		A.ad2.style.background="#ffffff";
		
		A.cp2.disabled="";
		A.cp2.style.background="#ffffff";
		
		A.ville2.disabled="";
		A.ville2.style.background="#ffffff";
		
		/*A.pays2.disabled="";
		A.pays2.style.background="#ffffff";*/
		
		A.tel2.disabled="";
		A.tel2.style.background="#ffffff";
		
		A.port2.disabled="";
		A.port2.style.background="#ffffff";
		
		A.mail2.disabled="";
		A.mail2.style.background="#ffffff";
		
		/*A.enf1_2.disabled="";
		A.enf1_2.style.background="#ffffff";
		
		A.bank2.disabled="";
		A.bank2.style.background="#ffffff";*/
		
		A.fumeur2[0].disabled="";
		A.fumeur2[1].disabled="";
		
		A.prof2.disabled="";
		A.prof2.style.background="#ffffff"; 
		
		A.nat2.disabled="";
		A.nat2.style.background="#ffffff"; 
		
		A.cadre2[0].disabled="";
		A.cadre2[1].disabled="";
		
		A.km2.disabled="";
		A.km2.style.background="#ffffff";
		
		A.manuel2[0].disabled="";
		A.manuel2[1].disabled="";
		
		A.temps2.disabled="";
		A.temps2.style.background="#ffffff";
		
		
	}
}


function nomJF1_Co(){
	var A=document.forme_demande;
	A.nomj2.value="";
	A.nomj2.disabled="disabled";
	A.nomj2.style.background="#EDEBE8";
}

function nomJF1_Co2(){
	var A=document.forme_demande;
	A.nomj2.disabled="";
	A.nomj2.style.background="#ffffff";
}





//************************** FORMAT CHAMP NOM DE JEUNE FILLE ***************************************
//**************************************************************************************************
function nomJF(){
	var A=document.forme_demande;
	A.nomj1.value="";
	A.nomj1.disabled="disabled";
	A.nomj1.style.background="#EDEBE8";
}
function nomJF2(){
	var A=document.forme_demande;
	A.nomj1.disabled="";
	A.nomj1.style.background="#ffffff";
}




//*************************** FORMAT FONT CHAMP ***************************************
//*************************************************************************************

function chg_font(nom,nom2,nom3,nom4,nom5,nom6,nom7,nom8,nom9,nom10,nom11,nom12,nom13,nom14,nom15,nom16,nom17,nom18,nom19,nom20,nom21,nom22){
	var nomId=nom;
	var nomIdD=nom+'D';
	var nomId2=nom2;
	var nomIdD2=nom2+'D';
	var nomId3=nom3;
	var nomIdD3=nom3+'D';
	var nomId4=nom4;
	var nomIdD4=nom4+'D';
	var nomId5=nom5;
	var nomIdD5=nom5+'D';
	var nomId6=nom6;
	var nomIdD6=nom6+'D';
	var nomId7=nom7;
	var nomIdD7=nom7+'D';
	var nomId8=nom8;
	var nomIdD8=nom8+'D';
	var nomId9=nom9;
	var nomIdD9=nom9+'D';
	var nomId10=nom10;
	var nomIdD10=nom10+'D';
	var nomId11=nom11;
	var nomIdD11=nom11+'D';
	var nomId12=nom12;
	var nomIdD12=nom12+'D';
	var nomId13=nom13;
	var nomIdD13=nom13+'D';
	var nomId14=nom14;
	var nomIdD14=nom14+'D';
	var nomId15=nom15;
	var nomIdD15=nom15+'D';
	var nomId16=nom16;
	var nomIdD16=nom16+'D';
	var nomId17=nom17;
	var nomIdD17=nom17+'D';
	var nomId18=nom18;
	var nomIdD18=nom18+'D';
	var nomId19=nom19;
	var nomIdD19=nom19+'D';
	var nomId20=nom20;
	var nomIdD20=nom20+'D';
	var nomId21=nom21;
	var nomIdD21=nom21+'D';
	var nomId22=nom22;
	var nomIdD22=nom22+'D';
	document.getElementById(nomId).style.color='#cc0000';
	document.getElementById(nomIdD).style.background='#C5BEB5';
	//document.getElementById(nomId).style.font='bold';
	document.getElementById(nomId2).style.color='#756653';
	document.getElementById(nomIdD2).style.background='';
	document.getElementById(nomId3).style.color='#756653';
	document.getElementById(nomIdD3).style.background='';
	document.getElementById(nomId4).style.color='#756653';
	document.getElementById(nomIdD4).style.background='';
	document.getElementById(nomId5).style.color='#756653';
	document.getElementById(nomIdD5).style.background='';
	document.getElementById(nomId6).style.color='#756653';
	document.getElementById(nomIdD6).style.background='';
	document.getElementById(nomId7).style.color='#756653';
	document.getElementById(nomIdD7).style.background='';
	document.getElementById(nomId8).style.color='#756653';
	document.getElementById(nomIdD8).style.background='';
	document.getElementById(nomId9).style.color='#756653';
	document.getElementById(nomIdD9).style.background='';
	document.getElementById(nomId10).style.color='#756653';
	document.getElementById(nomIdD10).style.background='';
	document.getElementById(nomId11).style.color='#756653';
	document.getElementById(nomIdD11).style.background='';
	document.getElementById(nomId12).style.color='#756653';
	document.getElementById(nomIdD12).style.background='';
	document.getElementById(nomId13).style.color='#756653';
	document.getElementById(nomIdD13).style.background='';
	document.getElementById(nomId14).style.color='#756653';
	document.getElementById(nomIdD14).style.background='';
	document.getElementById(nomId15).style.color='#756653';
	document.getElementById(nomIdD15).style.background='';
	document.getElementById(nomId16).style.color='#756653';
	document.getElementById(nomIdD16).style.background='';
	document.getElementById(nomId17).style.color='#756653';
	document.getElementById(nomIdD17).style.background='';
	document.getElementById(nomId18).style.color='#756653';
	document.getElementById(nomIdD18).style.background='';
	document.getElementById(nomId19).style.color='#756653';
	document.getElementById(nomIdD19).style.background='';
	document.getElementById(nomId20).style.color='#756653';
	document.getElementById(nomIdD20).style.background='';
	document.getElementById(nomId21).style.color='#756653';
	document.getElementById(nomIdD21).style.background='';
	document.getElementById(nomId22).style.color='#756653';
	document.getElementById(nomIdD22).style.background='';
}


//*************************** SAISIE DES CHAMPS ***************************************
//*************************************************************************************
function testzone_demande(){
	var A=document.forme_demande;
	var B = 0;
	var F = 0; 
	
	//TITRE-------------------------------------
	for (B ; B<3 ; B++) {
			if (A.emp1[B].checked) {
				F=1;}
				}
				
	if (F==0)  {
		alert('Veuillez sélectionner votre qualité (Mlle, Mme, M.)');
		return false;
		}
	
	if (A.co_emp.checked==true) {	
			B=0;
			F=0;
			for (B ; B<3 ; B++) {
			if (A.emp2[B].checked) {
				F=1;}
				}				
			if (F==0)  {
				alert('Veuillez sélectionner la qualité (Mlle, Mme, M.) du co-emprunteur');
				return false;
				}
		}
			
	
	//NOM-----------------------------------------
	if (A.nom1.value==""){
		alert("Vous devez saisir votre nom");
		A.nom1.focus();
		return false;
	}
	if (A.co_emp.checked==true) {
		if (A.nom2.value==""){
			alert("Vous devez saisir le nom du co-emprunteur");
			A.nom2.focus();
			return false;
		}
	}
	
	//PRENOM-----------------------------------------
	if (A.prenom1.value==""){
		alert("Vous devez saisir votre prénom");
		A.prenom1.focus();
		return false;
	}
	if (A.co_emp.checked==true) {
		if (A.prenom2.value==""){
			alert("Vous devez saisir le prénom du co-emprunteur");
			A.prenom2.focus();
			return false;
		}
	}
	
	//NAISSANCE------------------------------------------
	if ((A.naissance1.value=="")||(A.naissance1.value=="JJ/MM/AAAA")){
		alert("Vous devez votre date de naissance");
		A.naissance1.focus();
		return false;
	}
	else {
		champ=eval('document.forme_demande.naissance1');
		d=champ.value;
		message1="Le format de la date doit être : jj/mm/aa  ou  jj/mm/aaaa";
		message2="  Mauvais format de date !  ";
		  if (d != ""){ 
		    e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$");
		  if ((!e.test(d))&&(d!="")) {
			alert(message1); 
			champ.focus();
		    return false; 
			}
		 j = parseInt(d.split("/")[0], 10); // jour
		 m = parseInt(d.split("/")[1], 10); // mois
		 a = parseInt(d.split("/")[2], 10); // année		
		  if (a < 1000) {
		    if (a < 89)  a+=2000; 
		    else a+=1900;
		  }
		 if (a%4 == 0 && a%100 !=0 || a%400 == 0) fev = 29;
		  else fev = 28;
		  nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
		 if( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] ){
		 }else{
		 	alert(message2);
		 	champ.focus();
			return false;
	      }
		  }
    }
	
	if (A.co_emp.checked==true) {
		if ((A.naissance2.value=="")||(A.naissance2.value=="JJ/MM/AAAA")){
			alert("Vous devez saisir la date de naissance du co-emprunteur");
			A.naissance2.focus();
			return false;
		}
		else {
			champ=eval('document.forme_demande.naissance2');
			d=champ.value;
			message1="Le format de la date pour le co-emprunteur doit être : jj/mm/aa  ou  jj/mm/aaaa";
			message2="  Mauvais format de date pour le co-emprunteur !  ";
			  if (d != ""){ 
			    e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$");
			  if ((!e.test(d))&&(d!="")) {
				alert(message1); 
				champ.focus();
			    return false; 
				}
			 j = parseInt(d.split("/")[0], 10); // jour
			 m = parseInt(d.split("/")[1], 10); // mois
			 a = parseInt(d.split("/")[2], 10); // année		
			  if (a < 1000) {
			    if (a < 89)  a+=2000; 
			    else a+=1900;
			  }
			 if (a%4 == 0 && a%100 !=0 || a%400 == 0) fev = 29;
			  else fev = 28;
			  nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
			 if( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] ){
			 }else{
			 	alert(message2);
			 	champ.focus();
				return false;
		      }
			  }
	    }
	}

	//ADRESSE-----------------------------------------
	if (A.ad1.value==""){
		alert("Vous devez saisir votre adresse");
		A.ad1.focus();
		return false;
	}
	if (A.co_emp.checked==true) {
		if (A.ad2.value==""){
			alert("Vous devez saisir l\'adresse du co-emprunteur \n si cette derniére est différente de celle de l'emprunteur");
			A.ad2.focus();
			return false;
		}
	}
	
	//CP-----------------------------------------
	if (A.cp1.value==""){
		alert("Vous devez saisir votre code postal");
		A.cp1.focus();
		return false;
	}
	if (A.co_emp.checked==true) {
		if ((A.cp2.value=="")&&(A.ad2.value!="idem")){
			alert("Vous devez saisir le code postal du co-emprunteur");
			A.cp2.focus();
			return false;
		}
	}
	
	//VILLE-----------------------------------------
	if (A.ville1.value==""){
		alert("Vous devez saisir votre ville");
		A.ville1.focus();
		return false;
	}
	if (A.co_emp.checked==true) {
		if ((A.ville2.value=="")&&(A.ad2.value!="idem")){
			alert("Vous devez saisir la ville du co-emprunteur");
			A.ville2.focus();
			return false;
		}
	}
	
	//TELEPHONE + PORTABLE-----------------------------------------
	if ((A.tel1.value=="")&&(A.port1.value=="")){
		alert("Vous devez saisir au minimum votre téléphone fixe ou votre téléphone portable");
		A.tel1.focus();
		return false;
	}
	if (A.co_emp.checked==true) {
		if ((A.tel2.value=="")&&(A.port2.value=="")&&(A.ad2.value!="idem")){
			alert("Vous devez saisir au minimum le téléphone fixe ou le téléphone portable du co-emprunteur");
			A.tel2.focus();
			return false;
		}
	}
	
	//MAIL-----------------------------------------
	adresse = document.forme_demande.mail1.value;
	var place = adresse.indexOf("@",1);
	var point = adresse.indexOf(".",place+2);
	var espac = adresse.indexOf(" ",1);
	var ptvirgule = adresse.indexOf(";",1);
	var etoile = adresse.indexOf("*",1);
	if ((place > -1)&&(adresse.length >2)&&(point > 1)&&(espac < 0)&&(ptvirgule < 0)&&(etoile < 0))
		{
		//document.forme.submit();
		}
	else
		{
		alert('Veuillez saisir une adresse mail valide');
		A.mail1.focus();
		return false;
		}
	
	if ((A.co_emp.checked==true)&&(adresse=="")) {	
		adresse2 = document.forme_demande.mail2.value;
		var place2 = adresse2.indexOf("@",1);
		var point2 = adresse2.indexOf(".",place+2);
		var espac2 = adresse2.indexOf(" ",1);
		var ptvirgule2 = adresse2.indexOf(";",1);
		var etoile2 = adresse2.indexOf("*",1);
		if ((place2 > -1)&&(adresse2.length >2)&&(point2 > 1)&&(espac2 < 0)&&(ptvirgule2 < 0)&&(etoile2 < 0))
			{
			//document.forme.submit();
			}
		else
			{
			alert('Veuillez saisir une adresse mail valide');
			A.mail2.focus();
			return false;
			}
	}
	
	//FUMEUR------------------------------------
	B=0;
	F=0;
	for (B ; B<2 ; B++) {
			if (A.fumeur1[B].checked) {
				F=1;}
				}
				
	if (F==0)  {
		alert('Veuillez préciser si vous fumez ou non');
		return false;
		}
	
	if (A.co_emp.checked==true) {	
			B=0;
			F=0;
			for (B ; B<2 ; B++) {
			if (A.fumeur2[B].checked) {
				F=1;}
				}				
			if (F==0)  {
				alert('Veuillez préciser si le co-emprunteur fume ou non');
				return false;
				}
		}
	
	//PROFESSION-----------------------------------------
	if (A.prof1.value==""){
		alert("Vous devez indiquer votre profession");
		A.prof1.focus();
		return false;
	}
	if (A.co_emp.checked==true) {
		if ((A.prof2.value=="")&&(A.prof2.value!="idem")){
			alert("Vous devez indiquer la profession du co-emprunteur");
			A.prof2.focus();
			return false;
		}
	}
	
	
	//MONTANT EMPRUNTE-----------------------------------------
	if ((A.montant1.value=="")||((isNaN(A.montant1.value)))){
		alert("Vous devez indiquer le montant du prêt");
		A.montant1.focus();
		return false;
	}
	
	
	//TAUX-----------------------------------------
	if ((A.taux1.value=="")||((isNaN(A.taux1.value)))){
		alert("Vous devez indiquer le taux du prêt");
		A.taux1.focus();
		return false;
	}
	
	
	//DUREE EMPRUNTE-----------------------------------------
	if ((A.duree1.value=="")||((isNaN(A.duree1.value)))){
		alert("Vous devez indiquer la durée du prêt");
		A.duree1.focus();
		return false;
	}
	
	
	//DIFFERE EMPRUNTE-----------------------------------------
	if ((A.differe1.value!="")&&((isNaN(A.differe1.value)))){
		alert("Vous devez saisir une durée numérique");
		A.differe1.focus();
		return false;
	}
	
	//co-emprunteur-----------------------------------------
	if (A.montant2.value!="") {	
		//MONTANT EMPRUNTE-----------------------------------------
		if ((A.montant2.value=="")||((isNaN(A.montant2.value)))){
			alert("Vous devez indiquer le montant du second prêt");
			A.montant2.focus();
			return false;
		}
		
		
		//TAUX-----------------------------------------
		if ((A.taux2.value=="")||((isNaN(A.taux2.value)))){
			alert("Vous devez indiquer le taux du second prêt");
			A.taux2.focus();
			return false;
		}
		
		
		//DUREE EMPRUNTE-----------------------------------------
		if ((A.duree2.value=="")||((isNaN(A.duree2.value)))){
			alert("Vous devez indiquer la durée du second prêt");
			A.duree2.focus();
			return false;
		}
		
		
		//DIFFERE EMPRUNTE-----------------------------------------
		if ((A.differe2.value!="")&&((isNaN(A.differe2.value)))){
			alert("Vous devez saisir une durée numérique concernant le second prêt");
			A.differe2.focus();
			return false;
		}
	}
	
	
	return true;
}


function verifSitu(){
	if ((document.forme_demande.situFam1.value==1)&&(document.forme_demande.co_emp.checked==false)){
		alert('Si vous êtes marié(e) sous le régime de la communauté de bien\nvous devez cocher la case co-emprunteur');
		document.forme_demande.co_emp.checked=true;
		document.forme_demande.emp2[1].checked=true;
		document.forme_demande.situFam2[1].selected=true;	
		coEmp();
		document.forme_demande.nom2.focus();
	}
}
