<!--


var nothingImg = '/images/nothing.gif';
var trueImg = '/images/true_2.gif';
var falseImg = '/images/false_2.gif';

function valideIndex()
{
	var f = window.document.simul || window.document.forms[0];
	
	var revenu = f.i_revenu.value;
	if(revenu == '' || isNaN(revenu) || revenu == 0)
	{
		alert("Indiquez votre revenu.");
		f.i_revenu.focus();
		return;
	}
	// if(revenu < 10000)
	// {
		// if(!confirm("Vérifiez que vous avez bien indiqué les revenus annuels du foyer.\nContinuer ?"))
		// {
			// f.i_revenu.focus();
			// return;
		// }
	// }
	if(f.c_sit_fam.selectedIndex == 0)
	{
        alert("Indiquez votre situation familiale.");
		f.c_sit_fam.focus();
		return;
	}
	if(f.i_enfants.selectedIndex == 0)
	{
        alert("Indiquez votre nombre d'enfants.");
		f.i_enfants.focus();
        return;
	}
	var cp = f.p_cp.value;
	if(cp == '' || cp.search(/\d{5}/) == -1) //no_ph
	{
		alert("Indiquez votre code postal à 5 chiffres.");
		f.p_cp.focus();
        return;
	}
	var mail = f.e_mail.value;
	if(mail == '' || mail.search(/[\w\.-]+@[a-z0-9\.\-]+\.[a-z]{2,}$/) == -1) //no_ph
	{
		alert("Indiquez votre adresse e-mail.");
		f.e_mail.focus();
        return;
	}
	var tel = f.t_tel.value;
	if(tel == '' || tel.search(/^0[1-9]\D?\d{2}\D?\d{2}\D?\d{2}\D?\d{2}$/) == -1) //no_ph
	{
		alert("Indiquez votre n° de téléphone.");
		f.t_tel.focus();
        return;
	}
	
	if(f.c_loi)
	{
		if (f.c_loi[0].checked)
			f.action = "/cgi-bin/simul/scellier/simul.cgi";
		else if (f.c_loi[1].checked)
			f.action = "/cgi-bin/simul/lmnp_bouvard/simul.cgi";
		else
		{
			alert("Indiquez la loi.");
			return;
		}
	}

	f.submit();
}


function valideIndexAux(){
	
	 var f = window.document.simul || window.document.forms[0];
	
	/*
	**	Verification de la charge
	*/
	if(f.i_charge){
		var charge = f.i_charge.value;
		if(charge == '' || isNaN(charge) || charge == 0){
			alert("Indiquez vos charges.");
			f.i_charge.focus();
			return;
		}
	}
	
	/*
	**	Verification de la civilité
	*/
	if( f.x_civ ){
		var bChecked = false;
		
		for(var nIndex=0; nIndex < f.x_civ.length; nIndex++ ){
			var element = f.x_civ[ nIndex ];
			
			if( element.checked == true ){
				bChecked = true;
			}
		}		
		
		if( !bChecked ){
			alert("Indiquez votre civilité.");
			return;
		}
	} 
	
	/*
	**	Verification du nom
	*/
	if( f.c_nom ){
		if( f.c_nom.value == "" ){
			alert("Indiquez votre nom.");
			f.c_nom.focus();
			return;
		} 	
	}
	
	valideIndex();
}

function post()
{
	if (checkAll())
		document.forms[0].submit();
	else
		alert("Vous devriez vérifier les feux rouges");
}

function checkAll()
{
	var f = window.document.forms[0];
	var tel1;
	var tel2;
	var tel3;
	
	var ok = setLight("civ_img", f.x_civ.selectedIndex != 0);
	if( f.c_nom )
		ok &= setLight("nom_img", f.c_nom.value != "");
	if( f.c_prenom )
		ok &= setLight("prenom_img", f.c_prenom.value != "");
	if( f.x_adresse )
		ok &= setLight("adresse_img", f.x_adresse.value != "");
	if( f.p_cp )
		ok &= setLight("cp_img", f.p_cp.value != '' && f.p_cp.value.search(/\d{5}/) != -1);
	if( f.c_ville )
		ok &= setLight("ville_img", f.c_ville.value != "");
		
	if( f.t_port )
		tel1 = (f.t_port.value != '' && f.t_port.value.search(/^0[1-9]\D?\d{2}\D?\d{2}\D?\d{2}\D?\d{2}$/) != -1) //no_ph
	if( f.t_prof )
		tel2 = (f.t_prof.value != '' && f.t_prof.value.search(/^0[1-9]\D?\d{2}\D?\d{2}\D?\d{2}\D?\d{2}$/) != -1) //no_ph
	if( f.t_perso )
		tel3 = (f.t_perso.value != '' && f.t_perso.value.search(/^0[1-9]\D?\d{2}\D?\d{2}\D?\d{2}\D?\d{2}$/) != -1) //no_ph

	ok &= setLight("tel_img", tel1 || tel2 || tel3);

	if( f.e_mail )
		ok &= setLight("mail_img", f.e_mail.value != '' && f.e_mail.value.search(/[\w\.-]+@[a-z0-9\.\-]+\.[a-z]{2,}$/) != -1) //no_ph
	
	return(ok);
}

function setLight(o, i)
{
	var toto = document.getElementById(o);
	if (! toto) return(i);
	
	toto.src = (i ? trueImg : falseImg);
	return(i);
}
//-->

