function Verif_Formulaire() {

	if (document.getElementById("Nom").value == '')
	{
		alert('Veuillez saisir le champ Nom ! ');
		document.getElementById("Nom").focus();
		return false ;     
	}
		
	if (document.getElementById("Prenom").value == '')
	{
		alert('Veuillez saisir le champ Prénom ! ');
		document.getElementById("Prenom").focus();
		return false ;     
	}

	if (document.getElementById("Email").value == '' )
	{
		alert('Veuillez saisir le champ Adresse Mail ! ');
		document.getElementById("Email").focus();
		return false ;     
	}
	 else
	{
		if( !Verif_Email(document.getElementById("Email").value) )
		{
			alert('Adresse Mail non valide ! ');
			document.getElementById("Email").focus();
			return false ; 
		}
	}

	if (document.getElementById("CP").value == '')
	{
		alert('Veuillez saisir le champ Code Postal ! ');
		document.getElementById("CP").focus();
		return false ;     
	}

	if (document.getElementById("Telephone").value == '')
	{
		alert('Veuillez saisir le champ Telephone ! ');
		document.getElementById("Telephone").focus();
		return false ;     
	}

	//envoieRequete();	
	
	//return true;	
	
	document.formulaire.submit();
	
}

function Verif_Email ( my_email) {

	var new_string = new String(my_email);
	if (!new_string.match('^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$')) 
		return false;
	else 
		return true;
}

function Affiche_Formulaire() { 

	var pForm ; 
	
	pForm	=	'<FORM method="POST" name="formulaire" action="validation_formulaire.php">';

	pForm 	+=	'<TABLE BORDER="0" WIDTH="100%" class="form_box"> ' ;

	pForm	+=	'<TR>';
	pForm 	+=	'<TD WIDTH="50%" ALIGN="RIGHT">Nom :</TD>';
	pForm 	+=	'<TD WIDTH="50%" ><INPUT TYPE="text" name="Nom" id="Nom" size="25" maxlength="40" onblur="javascript:this.value=this.value.toUpperCase();"></TD>';
	pForm	+=	'</TR>';

	pForm	+=	'<TR>';
	pForm 	+=	'<TD ALIGN="RIGHT">Prénom :</TD>';
	pForm 	+=	'<TD><INPUT TYPE="text" name="Prenom" id="Prenom" size="25" maxlength="40"></TD>';
	pForm	+=	'</TR>';

	pForm	+=	'<TR>';
	pForm 	+=	'<TD ALIGN="RIGHT">Email :</TD>';
	pForm 	+=	'<TD><INPUT TYPE="text" name="Email" id="Email" size="25" maxlength="100"></TD>';
	pForm	+=	'</TR>';

	pForm	+=	'<TR>';
	pForm 	+=	'<TD ALIGN="RIGHT">Code Postal :</TD>';
	pForm 	+=	'<TD><INPUT TYPE="text" name="CP" id="CP" size="10" maxlength="6"></TD>';
	pForm	+=	'</TR>';

	pForm	+=	'<TR>';
	pForm 	+=	'<TD ALIGN="RIGHT">Téléphone :</TD>';
	pForm 	+=	'<TD><INPUT TYPE="text" name="Telephone" id="Telephone" size="10" maxlength="20"></TD>';
	pForm	+=	'</TR>';

	pForm	+=	'<TR>';
	pForm 	+=	'<TD COLSPAN="2" ALIGN="CENTER">';
	pForm 	+=	'<INPUT type="button" Onclick="return Verif_Formulaire()" value="Transmettre">';
	pForm	+=	'</TD>';
	pForm	+=	'</TR>';

	pForm	+=	'<TR>';
	pForm 	+=	'<TD COLSPAN="2">';
	pForm 	+=	'<INPUT TYPE="hidden" name="nb_enfants" id="nb_enfants">';
	pForm 	+=	'<INPUT TYPE="hidden" name="situation" id="situation">';
	pForm 	+=	'<INPUT TYPE="hidden" name="revenus" id="revenus">';
	pForm	+=	'</TD>';
	pForm	+=	'</TR>';
	
	pForm	+=	'</TABLE>';
	
	pForm	+=	'</FORM>';

	return pForm ;

}

function Affiche_Formulaire_Agences() { 

	var pForm ; 

	pForm 	=	'<TABLE BORDER="0" WIDTH="100%" class="form_box_agences"> ' ;

	pForm	+=	'<TR>';
	pForm 	+=	'<TD WIDTH="50%" ALIGN="RIGHT"><font color="#003464">Nom :</font> </TD>';
	pForm 	+=	'<TD WIDTH="50%" ><INPUT TYPE="text" name="Nom" id="Nom" size="25" maxlength="40" onblur="javascript:this.value=this.value.toUpperCase();"></TD>';
	pForm	+=	'</TR>';

	pForm	+=	'<TR>';
	pForm 	+=	'<TD ALIGN="RIGHT"><font color="#003464">Prénom : </font></TD>';
	pForm 	+=	'<TD><INPUT TYPE="text" name="Prenom" id="Prenom" size="25" maxlength="40"></TD>';
	pForm	+=	'</TR>';

	pForm	+=	'<TR>';
	pForm 	+=	'<TD ALIGN="RIGHT"><font color="#003464">Email : </font></TD>';
	pForm 	+=	'<TD><INPUT TYPE="text" name="Email" id="Email" size="25" maxlength="100"></TD>';
	pForm	+=	'</TR>';

	pForm	+=	'<TR>';
	pForm 	+=	'<TD ALIGN="RIGHT"><font color="#003464">Code Postal : </font></TD>';
	pForm 	+=	'<TD><INPUT TYPE="text" name="CP" id="CP" size="10" maxlength="6"></TD>';
	pForm	+=	'</TR>';

	pForm	+=	'<TR>';
	pForm 	+=	'<TD ALIGN="RIGHT"><font color="#003464">Téléphone : </font></TD>';
	pForm 	+=	'<TD><INPUT TYPE="text" name="Telephone" id="Telephone" size="10" maxlength="20"></TD>';
	pForm	+=	'</TR>';

	pForm	+=	'<TR>';
	pForm 	+=	'<TD COLSPAN="2" ALIGN="CENTER">';
	pForm 	+=	'<INPUT type="submit" Onclick="return Verif_Formulaire()" value="Transmettre">';
	pForm	+=	'</TD>';
	pForm	+=	'</TR>';

	pForm	+=	'<TR>';
	pForm 	+=	'<TD COLSPAN="2">';
	pForm 	+=	'<INPUT TYPE="hidden" name="nb_enfants" id="nb_enfants">';
	pForm 	+=	'<INPUT TYPE="hidden" name="situation" id="situation">';
	pForm 	+=	'<INPUT TYPE="hidden" name="revenus" id="revenus">';
	pForm 	+=	'<INPUT TYPE="hidden" name="no_agence" id="no_agence">';
	pForm	+=	'</TD>';
	pForm	+=	'</TR>';
	
	pForm	+=	'</TABLE>';

	return pForm ;

}

function Validation_Simulateur( pNom )	{ 

		var pResult ; 

		var Marie_0 = ["532","1 858","3 370","5 068","8 308","11 548","14 788","18 028","21 268"];
		var Marie_1 = ["368","1 188","2 700","4 212","5 972","9 212","12 452","15 692","18 932"];
		var Marie_2 = ["204","798","2 031","3 543","5 055","6 876","10 116","13 356","16 596"];
		var Marie_3 = ["0","470","1 064","2 204","3 716","5 228","6 740","8 684","11 924"];
		var Marie_4 = ["0","142","736","1 330","2 377","3 889","5 401","6 913","8 425"];

		var Celib_0 = ["1 685","4 154","7 394","10 634","13 874","17 639","22 067","26 495","29 600"];
		var Celib_1 = ["1 015","2 527","5 058","8 298","11 538","15 303","19 731","24 159","28 587"];
		var Celib_2 = ["346","1 858","3 370","5 962","9 202","12 967","17 395","21 823","26 251"];
		var Celib_3 = ["204","798","2 031","3 543","5 055","8 295","12 723","17 151","21 579"];
		var Celib_4 = ["0","470","1 064","2 204","3 716","5 228","8 051","12 479","16 907"];

		var CelibSeul_0 = ["1 685","4 154","7 394","10 634","13 874","17 639","22 067","26 495","29 600"];
		var CelibSeul_1 = ["532","1 858","3 369","6 594","9 834","13 599","18 027","22 455","25 560"];
		var CelibSeul_2 = ["368","1 188","2 700","4 258","7 498","11 263","15 691","20 119","23 224"];
		var CelibSeul_3 = ["0","634","1 361","2 873","4 385","6 591","11 019","15 447","18 552"];
		var CelibSeul_4 = ["0","306","900","1 534","3 046","4 558","6 070","10 775","13 880"];

		if ( document.getElementById("sim_situation").value == 0 ) {	//Marié ou Pacsé
		
			pResult = eval('Marie_'+document.getElementById("sim_nb_enfants").value+'['+document.getElementById("sim_revenus").value+']') ;
		
		}

		if ( document.getElementById("sim_situation").value == 1 ) {	//Célibataire Union Libre

			pResult = eval('Celib_'+document.getElementById("sim_nb_enfants").value+'['+document.getElementById("sim_revenus").value+']') ;

		}

		if ( document.getElementById("sim_situation").value == 2 ) {	//Célibataire Vivant seul
		
			pResult = eval('CelibSeul_'+document.getElementById("sim_nb_enfants").value+'['+document.getElementById("sim_revenus").value+']') ;

		}
		
		pResult =	"<center>Votre économie d'impôt annuelle : <b>" + pResult + " € </b></center><BR><BR>" ;
		
		pResult	+=	"Pour bénéficier d´une étude fiscale totalement <br/>gratuite et sans engagement, merci de remplir<br/> les champs ci-dessous :<BR><div id='div_formulaire'></div>";
		
		document.getElementById("div_result").innerHTML	= pResult ; 

		if ( pNom != 'Simulateur_Agences' )
			document.getElementById("div_formulaire").innerHTML = Affiche_Formulaire();
		else
			document.getElementById("div_formulaire").innerHTML = Affiche_Formulaire_Agences();

		Formulaire_Visible() ; 
		
		document.getElementById("nb_enfants").value		=	document.getElementById("sim_nb_enfants").value ;
		document.getElementById("situation").value		=	document.getElementById("sim_situation").value ;
		document.getElementById("revenus").value		=	document.getElementById("sim_revenus").value ;
		
		if ( pNom == 'Simulateur_Agences' )
			document.getElementById("no_agence").value		=	document.getElementById("sim_agence").value ;

		document.getElementById("Nom").focus();
		
		return false ;
} 
	
function Formulaire_Visible()	{ 
		document.getElementById("div_result").style.visibility='visible' ;
		document.getElementById("div_formulaire").style.visibility='visible' ;
}
	
function Formulaire_Non_Visible()	{ 
		document.getElementById("div_result").style.visibility='hidden' ;
		document.getElementById("div_formulaire").style.visibility='hidden' ;
}

function envoieRequete()
{
	var OAjax;
	if (window.XMLHttpRequest) OAjax = new XMLHttpRequest();
	else if (window.ActiveXObject) OAjax = new ActiveXObject('Microsoft.XMLHTTP'); 
	OAjax.open('POST',"validation_formulaire.php",true);
	OAjax.onreadystatechange = function()
	{
		if (OAjax.readyState == 4 && OAjax.status==200)
		{
			if (document.getElementById) 
			{    
				document.getElementById('contenu').innerHTML=OAjax.responseText;
			}     
		}
	}
	OAjax.setRequestHeader('Content-type','application/x-www-form-urlencoded');    
  
	OAjax.send('Nom='+document.getElementById('Nom').value+'&Prenom='+document.getElementById('Prenom').value+'&Email='+document.getElementById('Email').value+'&CP='+document.getElementById('CP').value+'&Telephone='+document.getElementById('Telephone').value+'&nb_enfants='+document.getElementById('nb_enfants').value+'&situation='+document.getElementById('situation').value+'&revenus='+document.getElementById('revenus').value+'&Nom_agence='); 
} 

