function checkInscStep3(myForm,lang){
var value=0;
	for(i=0;i<myForm.type_client.length;i++){
		if (myForm.type_client[i].checked == true){
		value++;
		break;
		}
	} 
	
	if (value == 0){
	alert(_textAlert['SelectTypeClient']);
	return false;
	}
	else {
	myForm.action="#";
	myForm.target="";
	}
}

function alerte(erreur){
	if(erreur==1){
	alert(""+logon_alert+"");
	}
}

function goInscription(){
	window.location="inscription.php?step=1";
}

function goStep2 () {
	window.location="inscription.php?step=2";
}

function checkMail(x) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(x);
}

function doError(displayId, inputId, errType) {
	document.getElementById(inputId).className = "inputError";
	document.getElementById('err_'+displayId).style.display = 'block';

	if (_textAlert[errType])
	document.getElementById('err_'+displayId).innerHTML = _textAlert[errType];
	else
	document.getElementById('err_'+displayId).innerHTML = 'Erreur <strong>'+errType+'</strong> non definie';

// 	document.getElementById('err_'+inputId).innerHTML = _textAlert[errType];
}

function undoError(inputId) {
	if (document.getElementById(inputId) && document.getElementById('err_'+inputId)) {
		document.getElementById(inputId).className = "input";
		document.getElementById('err_'+inputId).style.display = 'none';
		document.getElementById('err_'+inputId).innerHTML = '';
	}
}

function checkInscStep1bis(myForm,lang){
	if (confirm (_textAlert['AnnuleInscription'])){
	myForm.target="_exec";
	myForm.wtd.value="abort";
	myForm.action="/outils/eval_insc.php";
	myForm.submit();
//	window.location="/inscription.php?annul=now";	
	}
	else{
		return false;	
	}
return false;
}  

// J'en suis la
function RetourPagePrec(){
	if (confirm (_textAlert['BackInscription'])){
		window.location="/inscription.php?prec=oui"
	}
	else{
		return false;	
	}
}


function checkInscStep1(lang){
	var myForm = document.getElementById('inscForm');

	if (checkMail(myForm.email.value)) {
		myForm.target="_exec";
		myForm.action="devenirMembre.php";
		myForm.submit();
		return true ;
	} else {
		doError('insc','email', 'badEmail');
		myForm.email.focus();
		return false;
	}
	return false;
}

function checkMdpOublie() {
	var myForm = document.getElementById('mdpForm');

	if (checkMail(myForm.mdp.value)) {
		myForm.submit();
		return true;
	} else {
		doError('mdp', 'mdp', 'badEmail');
		showTip('email', 'mdp');
		myForm.mdp.focus();
		return false;
	}
}

function abortInsc(myForm,lang,pic,step){
	var myForm = document.getElementById('inscForm');
//	overlib('login_name', STICKY, CAPTION, 'login_name', CLOSECLICK, CLOSETEXT, '<img src="'+pic+'" width=16px>', FGCOLOR, 'white', FIXX, 1, FIXY, 1, RELX, 300, RELY, 60);
	if(step>2) message = 'annuleInscPostKey'; else message = 'annuleInscPreKey';
	if(confirm(_textAlert[message])){
	myform.wtd.value="abort";
	myForm.target="_exec";
	myForm.action="/outils/eval_insc.php";
	myForm.submit();
	}
	
}

function checkInscStep2(myForm) {
//	var myForm = document.getElementById('inscForm');
	if ( isNaN(myForm.key.value)) {
		doError('key', 'key','mustBeANumber');
	} else {
		if (myForm.key.value.length < 10) {
			doError('key', 'key','toShoort');
		} else {
			myForm.action="/outils/eval_insc.php";
			myForm.target="_exec";
			myForm.submit();
			return true;
		}
	}
	myForm.key.focus();
	return false;
}

function checkSelect(fieldTocheck,errorMsg,fieldTofocus) {
	myField = document.getElementById(fieldTocheck).value ;
	if ( myField == 0 ){
		doError(fieldTocheck,errorMsg,fieldTocheck);
		nbErr++;
		if (fieldTofocus == 'none') fieldTofocus = document.getElementById(fieldTocheck);
	} else undoError(fieldTocheck);

	return fieldTofocus;
}

function checkField(fieldTocheck,errorMsg,fieldTofocus) {
	myField = document.getElementById(fieldTocheck).value ;
	if ( myField.length < 1 ){
		doError(fieldTocheck,errorMsg,fieldTocheck);
		nbErr++;
		if (fieldTofocus == 'none') fieldTofocus = document.getElementById(fieldTocheck);
	} else undoError(fieldTocheck);

	return fieldTofocus;
}

var nbErr;

function checkInscStep4(){

	//civilité
	unfocus_field('Fcivilite_client');
	if(_Elem('Fcivilite_client').value == 0)
	{
		alert(_textAlert['textCompteCivilite']);
		focus_field('Fcivilite_client');
		return false;
	}
	//prénom
	unfocus_field('Fprenom_client');
	if(_Elem('Fprenom_client').value.length == 0)
	{
		alert(_textAlert['textComptePrenom']);
		focus_field('Fprenom_client');
		return false;
	}
	//nom
	unfocus_field('Fnom_client');
	if(_Elem('Fnom_client').value.length == 0)
	{
		alert(_textAlert['textCompteNom']);
		focus_field('Fnom_client');
		return false;
	}
	//adresse
	unfocus_field('Frue1_client');
	if(_Elem('Frue1_client').value.length == 0)
	{
		alert(_textAlert['textCompteAdresse']);
		focus_field('Frue1_client');
		return false;
	}

/*******************************************************************************************/	
	if(_Elem('Fpays_client').selectedIndex==0)
	{
	alert(_textAlert['pays_expo_nc']);
	focus_field('Fpays_client');
	return false;
	}
	else
	{
	unfocus_field('Fpays_client');
	}	

	// Si le pays et dans la liste des zones developpées (Bases de données complétée)
	if(in_array(_L_reg_pays,_Elem('Fpays_client').value))
	{
		// Selection d'un region obligatoire : 
		if(_Elem('region_geo').selectedIndex==0)
		{
		alert(_textAlert['region_expo_nc']);
		focus_field('region_geo');
		return false;
		}
		else
		{
		unfocus_field('region_geo');
		}

		// Selection d'un departement obligatoire (FR)
		if(in_array(_L_dep_pays,_Elem('Fpays_client').value))
		{
			if(_Elem('departement_geo').selectedIndex==0)
			{
			alert(_textAlert['departement_expo_nc']);
			focus_field('departement_geo');
			return false;
			}
			else
			{
			unfocus_field('departement_geo');
			}		
		}

		// selection ou saisie d'un ville obligatoire
		if(_Elem('ville_geo').selectedIndex==0 && _Elem('Fville_client').value=="")
		{
		alert(_textAlert['ville_nc']);
		focus_field('ville_geo');
		focus_field('Fville_client');
		return false;
		}
		else
		{
		unfocus_field('ville_geo');
		unfocus_field('Fville_client');
		}	
	}
	// si le pays n'est pas dans la base de données complétée
	else
	{
		if(_Elem('Fzip_client').value=="")
		{
		alert(_textAlert['cp_nc']);
		focus_field('Fzip_client');
		return false;
		}
		else
		{
		unfocus_field('Fzip_client');
		}
			
		if(_Elem('Fville_client').value=="")
		{
		alert(_textAlert['ville_nc_moins']);
		focus_field('Fville_client');
		return false;
		}
		else
		{
		unfocus_field('Fville_client');
		}
	
	}

	if(_Elem('region_geo')!=null)
			_Elem('Fregion_client').value		=_Elem('region_geo').value;
	
	if(_Elem('departement_geo')!=null)	
			_Elem('Fdepartement_client').value =_Elem('departement_geo').value;

	if(_Elem('ville_geo')!=null)
			_Elem('Fville_id_client').value		=_Elem('ville_geo').value;
/*****************************************************************************/

	//téléphone
	unfocus_field('ftel_client');
	if(_Elem('ftel_client').value.length == 0)
	{
		alert(_textAlert['textCompteTelephone']);
		focus_field('ftel_client');
		return false;
	}

	if(_Elem('know').value == 0)
	{
		alert(_textAlert['textConnaissance']);
		focus_field('know');
		return false;
	}	
	
		myForm=document.getElementById('inscForm');
		myForm.action="/outils/eval_insc.php";
		myForm.target="_exec";
		myForm.submit();
}

//########################################################################
//#### Validation de la derniere etape de l'inscription des particuliers #
//########################################################################
function checkInscStep5Part() {
	fieldTofocus = 'none';
	nbChat = document.getElementById('nbchat').value;
	nbErr = 0;
	// Si le particulier n'inscrit pas d'animal
	// on ne verifie que l'acceptation des CGU
	cgu = document.getElementById('cgu').checked ;

	if (nbChat > 0)
	{
		for (i = 1; i <= nbChat ; i++)
		{
			// verifie la presence du nom de l'animal
			nomChat = document.getElementById('nom'+i).value ;
			if ( nomChat.length < 1 )
			{
			doError('nom'+i,'nomChat');
			nbErr++;
			if (fieldTofocus == 'none') fieldTofocus = document.getElementById('nom'+i);
			} else undoError('nom'+i);
				
			// verifie la presence de la race de l'animal
			raceChat = document.getElementById('race'+i).value ;
			if (raceChat == 0)
			{
			doError('race'+i,'raceChat');
			nbErr++;
			if (fieldTofocus == 'none') fieldTofocus = document.getElementById('race'+i);
			} else undoError('race'+i);

			// verifie la date de naissance de la race de l'animal
			dateChat = document.getElementById('date_naissance'+i).value ;
			if (dateChat.length == 0) 
			{
			doError('date_naissance'+i,'dateChat');
			nbErr++;
				if (fieldTofocus == 'none')
				{
				fieldTofocus = document.getElementById('date_naissance'+i);
				}
			} 
			else 
			{
				aujourdhui = new Date();

				tmp = dateChat.split("/");
				datenaiss = new Date (tmp[2],tmp[1]-1,tmp[0]);
				diffTime = datenaiss - aujourdhui ;
				if (diffTime > 0)
				{
				doError('date_naissance'+i,'dateChatPostToday');
				nbErr++;
					if (fieldTofocus == 'none')
					{ 
					fieldTofocus = document.getElementById('date_naissance'+i); 
					}
				} 
				else 
				{
				undoError('date_naissance'+i);
				}
			}

			// verifie la qualite de la nourriture de l'animal
			bouffeChat = document.getElementById('nourriture'+i).value ;
			if (bouffeChat == 0) {
			doError('nourriture'+i,'bouffeChat');
			nbErr++;
				if (fieldTofocus == 'none') fieldTofocus = document.getElementById('nourriture'+i);
			} else undoError('nourriture'+i);
		} // fin de boucle 'chat'
	} 

	// que la particulier inscrive un animal ou non il doit valider les CGU pour
	// terminer son inscription
		if ( ! cgu )
		{
		doError('cgu','cgu');
		nbErr++;
		if (fieldTofocus == 'none') fieldTofocus = document.getElementById('cgu');
		} else undoError('cgu');

	// Si tous les champs requis ont été correctement saisis
	// l'inscription est valider, le client peut acceder à son compte
		if (nbErr == 0) {
			document.getElementById('wtd').value = 'goFinalStep';
			document.getElementById('inscForm').submit();
			return false;
		}
	return false;
}

//########################################################################
//#### Validation de la derniere etape de l'inscription des eleveurs #####
//########################################################################

function checkInscStep5Elv(pays) {
	fieldTofocus = 'none';
	nbErr = 0;
	affixe = document.getElementById('affixe').value ;
	if ( affixe.length < 1 ){
		doError('affixe','affixe');
		nbErr++;
		if (fieldTofocus == 'none') fieldTofocus = document.getElementById('affixe');
	} else undoError('affixe');

	if (pays == 'fr') {
		certcap = document.getElementById('certcap').value ;
		if ( certcap.length < 1 ){
			doError('certcap','certcap');
			nbErr++;
			if (fieldTofocus == 'none') fieldTofocus = document.getElementById('certcap');
		} else undoError('certcap');
	}

	cga = document.getElementById('cga').checked ;
	if ( ! cga ){
		doError('cga','cga');
		nbErr++;
		if (fieldTofocus == 'none') fieldTofocus = document.getElementById('cga');
	} else undoError('cga');

	if (nbErr == 0) {
		document.getElementById('inscForm').submit();
		return true;
	}
	fieldTofocus.focus();
	return false;
}

function checkInscStep5Pro(pays) {
	fieldTofocus = 'none';
	nbErr = 0;

	fieldTofocus = checkSelect('nomEntr','nomEntr',fieldTofocus);
	fieldTofocus = checkField('pro_rue1','pro_rue1',fieldTofocus);
	fieldTofocus = checkField('pro_rue2','pro_rue2',fieldTofocus);
	fieldTofocus = checkField('siege_pro_cp','siege_pro_cp',fieldTofocus);
	fieldTofocus = checkField('pro_ville','pro_ville',fieldTofocus);
	fieldTofocus = checkField('pro_region','pro_region',fieldTofocus);
	fieldTofocus = checkSelect('pro_pays','pro_pays',fieldTofocus);
	fieldTofocus = checkField('pro_enreg','pro_enreg',fieldTofocus);
	fieldTofocus = checkSelect('pro_tva','pro_tva',fieldTofocus);
	fieldTofocus = checkSelect('activite','activite',fieldTofocus);

	if (nbErr == 0) {
		document.getElementById('inscForm').submit();
		return true;
	} else {
		fieldTofocus.focus();
		return false;
	}
	
	//cga
	cga = document.getElementById('cgu').checked ;
	if ( ! cga ){
		doError('cgu','cgu');
		nbErr++;
		if (fieldTofocus == 'none') fieldTofocus = document.getElementById('cgu');
	} else undoError('cgu');

	if (nbErr == 0) {
		document.getElementById('inscForm').submit();
		return true;
	}
	fieldTofocus.focus();
	return false;
}



function checkInscStep5Autre() {
	fieldTofocus = 'none';
	nbErr = 0;
	commentaire = document.getElementById('commentaire').value ;
	if ( commentaire.length < 1 ){
		doError('commentaire','commentaire');
		nbErr++;
		if (fieldTofocus == 'none') fieldTofocus = document.getElementById('commentaire');
	} else undoError('commentaire');

	cgu = document.getElementById('cgu').checked ;
	if ( ! cgu ){
	doError('cgu','cgu');
	nbErr++;
	if (fieldTofocus == 'none') fieldTofocus = document.getElementById('cgu');
	} else undoError('cgu');

	if (nbErr == 0) {
		document.getElementById('inscForm').submit();
		return true;
	}
	fieldTofocus.focus();
	return false;
}

function nbSelOption(selectId){
	mySel = document.getElementById(selectId);
	nbSel = 0 ;
	for (i=0 ; i< mySel.length; i++){
		if (mySel.options[i].selected == true) nbSel++;
	}
	return nbSel;
}

function checkInscStep5Club(myForm){
	fieldTofocus = 'none';
	nbErr = 0;

	fieldTofocus = checkSelect('type_asso_id','type_asso_id',fieldTofocus);
	fieldTofocus = checkField('nom_asso','nom_asso',fieldTofocus);
	fieldTofocus = checkField('num_ident','num_ident',fieldTofocus);
	fieldTofocus = checkField('siege_rue1','siege_rue1',fieldTofocus);
	fieldTofocus = checkField('siege_cp','siege_cp',fieldTofocus);
	fieldTofocus = checkField('siege_ville','siege_ville',fieldTofocus);
	fieldTofocus = checkSelect('siege_pays_id','siege_pays_id',fieldTofocus);
	fieldTofocus = checkField('siege_tel','siege_tel',fieldTofocus);
	fieldTofocus = checkField('siege_email','siege_email',fieldTofocus);
	fieldTofocus = checkField('date_creation','date_creation',fieldTofocus);

	if (_Elem('type_asso_id').value == 1) {
		nbSel = nbSelOption('race_id');
		if (nbSel > 30) {
			doError('race_id','race_tooMuch');
			nbErr++;
			if (fieldTofocus == 'none') fieldTofocus = document.getElementById('race_id');
		} else undoError('race_id');
		fieldTofocus = checkSelect('race_id','race_id',fieldTofocus);
	}

	fieldTofocus = checkField('president_prenom','president_prenom',fieldTofocus);
	fieldTofocus = checkField('president_nom','president_nom',fieldTofocus);
	fieldTofocus = checkField('secretaire_prenom','secretaire_prenom',fieldTofocus);
	fieldTofocus = checkField('secretaire_nom','secretaire_nom',fieldTofocus);

	cgu = document.getElementById('cgu').checked ;
	if ( ! cgu ){
	doError('cgu','cgu');
	nbErr++;
	if (fieldTofocus == 'none') fieldTofocus = document.getElementById('cgu');
	} else undoError('cgu');

	if (nbErr == 0) {
		myForm.submit();
		return true;
	} else {
	fieldTofocus.focus();
	}
	return false;
	
}

function checkRace(raceId) {
	if (raceId == 1){
		document.getElementById('tr1race_id').style.display='';
		document.getElementById('tr2race_id').style.display='';
	} else {
		document.getElementById('tr1race_id').style.display='none';
		document.getElementById('tr2race_id').style.display='none';
	}
}

function login(){
	fieldTofocus = 'none';
	nbErr = 0;
	login_name = document.getElementById('login_name').value ;
	if ( login_name.length < 1 ){
		doError('login','login_name','login_name');
		nbErr++;
		if (fieldTofocus == 'none') fieldTofocus = document.getElementById('login_name');
	} else undoError('login_name');

	passwd = document.getElementById('passwd').value ;
	if ( passwd.length < 1 ){
		doError('login','passwd','passwd');
		nbErr++;
		if (fieldTofocus == 'none') fieldTofocus = document.getElementById('passwd');
	} else undoError('passwd');

	if (nbErr == 0) {
		tmp = document.getElementById('postform');
		//alert(document.getElementById('postform').name);
		tmp.submit();
		return true;
	} else {
		fieldTofocus.focus();
		return false;
	}
}

function lireCGA(){
        var myParam = getCenterWin(600,400);
        divOpen("informations/cga.html",'Conditions G&eacute;n&eacute;rales d\'abonnement',myParam['top'], myParam['left'], myParam['width'], myParam['height']);

        var myPop = document.getElementById("myPopup");
        myPop.scrolling='auto';
}

function lireCGU(){
	debug = false;
	if (debug) alert('avant getCenterWin');
        var myParam = getCenterWin(600,400);
	if (debug) alert('apres getCenterWin');
        divOpen("informations/cgu.html",'Conditions G&eacute;n&eacute;rales d\'utilisation',myParam['top'], myParam['left'], myParam['width'], myParam['height']);

        var myPop = document.getElementById("myPopup");
        myPop.scrolling='auto';
}

function popAlert(titre, message){
        var myParam = getCenterWin(10,10);
        divOpen("/overPopupMessages.php?messId="+message,titre,myParam['top']+10, myParam['left'], myParam['width'], myParam['height']);

        var myPop = document.getElementById("myPopup");
        myPop.scrolling='auto';
}

/** affichage du detail des services **/
function afficheServiceInfos(myForm,id){
	myForm=document.getElementById('inscForm');
	myForm.target="_overlib";
	myForm.action='/outils/genereServiceInfos.php?service='+id+'';
	myForm.submit();
}