//Copyright Andréa MAIRE
//Pyxis Ingeniérie
//pour toute duplication contactez nous :am@pyxis.fr


var test_form1,test_form2=0;
var test_form3,test_form4,test_form5=0;  
//définition de variables pour la séléction de la civilité
var civilite="";
var val_civ_melle,val_civ_mme,val_civ_mons=0;
  
//définition de variables pour la séléction de la m^me adress Facturation/Livraison
var Sel_adrlivsim=0;


//*****************************************************************************************************
//Début du Module de traitement pour la séléction de la civilité

//Début du Module de traitement la civilité pour Melle
function Etatcivmelle()
{
   civilite="";
   val_civ_melle=0;val_civ_mme=0;val_civ_mons=0;
  
   val_civ_melle=document.Abon.melle.checked;
   //alert("Melle"+val_civ_melle);
   if(val_civ_melle=="1")
   	{
		typeciv=1;
		civilite="Melle ";
		document.Abon.mme.checked=0;
		document.Abon.mons.checked=0;
		//alert(civilite);
		document.Abon.tit_civ.value=civilite;
		//Adr_livr();
	}	
   
}
//Fin du Module de traitement la civilité pour Melle

//Début du Module de traitement la civilité pour Mme
function Etatcivmme()
{
   civilite="";
   val_civ_melle=0;val_civ_mme=0;val_civ_mons=0;
   val_civ_mme=document.Abon.mme.checked;
   //alert("Madame"+val_civ_mme);
   if(val_civ_mme=="1")
   	{
		typeciv=2;
		civilite="Mme. ";
		document.Abon.melle.checked=0;
		document.Abon.mons.checked=0;
		//alert(civilite);
		document.Abon.tit_civ.value=civilite;
		//Adr_livr();
		
		
	}	
   
}
//Fin du Module de traitement la civilité pour Mme

//Début du Module de traitement la civilité pour Monsieur
function Etatcivmons()
{
   civilite="";
   val_civ_melle=0;val_civ_mme=0;val_civ_mons=0;
   val_civ_mons=document.Abon.mons.checked;
   //alert("Monsieu"+val_civ_mons);
   if(val_civ_mons=="1")
   	{
		typeciv=3;
		civilite="M. ";
		document.Abon.melle.checked=0;
		document.Abon.mme.checked=0;


		//alert(civilite);
		document.Abon.tit_civ.value=civilite;
		//Adr_livr();
	}	
   
}

//fin du Module de traitement la civilité pour Monsieur
//Fin du Module de traitement pour la séléction de la civilité
//*****************************************************************************************************


// fonction d'actualisation de coutx quand qtx est modifiée
function Adr_livr()
{
	
	//alert("fonction Adr_livaraison");
    Sel_adrlivsim=0;
    Sel_adrlivsim=document.Abon.adrlivsim.checked;
    if(Sel_adrlivsim==1)
  	{
	   		
			document.Abon.Comment_adresse.value="Identique à l'adresse de facturation";
			document.Abon.nom_livr.value=document.Abon.tit_civ.value+" "+document.Abon.nom.value;
	        document.Abon.prenom_livr.value=document.Abon.prenom.value;
			document.Abon.organisme_livr.value=document.Abon.organisme.value;
            document.Abon.adresse1_livr.value=document.Abon.adresse1.value;
			document.Abon.adresse2_livr.value=document.Abon.adresse2.value;
			document.Abon.CP_livr.value=document.Abon.CP.value;
			document.Abon.ville_livr.value=document.Abon.ville.value;
			
			document.Abon.pays_frdom.checked=document.Abon.pays_frdom2.checked;
			document.Abon.pays_etrang.checked=document.Abon.pays_etrang2.checked;
			
			document.Abon.pays_livr.value=document.Abon.pays.value;
			document.Abon.telephone_livr.value=document.Abon.telephone.value;
			document.Abon.Fax_livr.value=document.Abon.Fax.value;	 
	}
	else
	{
	   		document.Abon.Comment_adresse.value="Différente de l'adresse de facturation";
			//document.Abon.nom_livr.value="";
	        //document.Abon.prenom_livr.value="";
			//document.Abon.organisme_livr.value="";
            //document.Abon.adresse1_livr.value="";
			//document.Abon.adresse2_livr.value="";
			//document.Abon.CP_livr.value="";
			//document.Abon.ville_livr.value="";
			//document.Abon.pays_livr.value="";
	
	}	
	
}





//******************************************************************************************************
////////////////////////////////////////////////////////////////////////////////////////////////////////

function select_modpaie()
	{
		sel_p=""; mode_p="";
		sel_p=document.Abon.sel_mod_pai.selectedIndex;
		mode_p=document.Abon.sel_mod_pai.options[sel_p].value;
		if (mode_p=="Indéterminé !!")
			{
				//document.Abon.reset();
				document.Abon.Mode_reglement.value=mode_p;
				//return false;
			}
		else
			{
				document.Abon.Mode_reglement.value=mode_p;

			}
	}



//Test N°1
function formtest()
{
    
	Verif_Abon();
	verif_montant=0;verif_montapayfr=0;verif_montapayeu=0;verif_montport=0;	
	//Vérification du nombre d'exemplaire
	verif_nbex=0;
	verif_nbex=document.Abon.Qte_Tot_Abo.value;
	if (verif_nbex=="0" || verif_nbex=="0.00" ||verif_nbex=="")
	{
		alert("Veuillez commander au moins un abonnement° S.V.P !");
		document.Abon.selection_abpart.focus();
		document.Abon.selection_abpart.select();
		return false;
	}
	prenom=document.Abon.prenom.value;
	nom=document.Abon.nom.value;
	org=document.Abon.organisme.value;
	adr1=document.Abon.adresse1.value;
	adr2=document.Abon.adresse2.value;
	cpv=document.Abon.CP.value;
	vil=document.Abon.ville.value;
	valpays=document.Abon.pays.value;
	email=document.Abon.Email.value;
	if (nom=="" || prenom=="" || adr1=="" || cpv=="" || vil=="" || valpays=="" ) 
	{
		if (nom=="")
		{
			alert("Remplissez le champs NOM (Adresse de facturation)  S.V.P !\nChamps obligatoire !");
			document.Abon.nom.focus();
			document.Abon.nom.select();
			return false;
		}
		if (prenom=="")
		{
			alert("Remplissez le champs PRENOM (Adresse de facturation) S.V.P !\nChamps obligatoire !");
			document.Abon.prenom.focus();
			document.Abon.prenom.select();
			return false;
		}
		
		if (adr1=="" && adr2=="")
		{
			alert("Remplissez les champs ADRESSE & COMP.ADRESSE (Adresse de facturation) S.V.P !\nChamps obligatoire !");
			document.Abon.adresse1.focus();
			document.Abon.adresse1.select();
			return false;
		}

		if (cpv=="")
		{
			alert("Remplissez les champs CODE POSTAL (Adresse de facturation) S.V.P !\nChamps obligatoire !");
			document.Abon.CP.focus();
			document.Abon.CP.select();
			return false;
		}


		if (vil=="")
		{
			alert("Remplissez les champ VILLE (Adresse de facturation) S.V.P !\nChamps obligatoire !")
			document.Abon.ville.focus();
			document.Abon.ville.select();
			return false;
		}
		

		if (valpays=="")
		{
			alert("Remplissez les champs PAYS (Adresse de facturation) S.V.P !\nChamps obligatoire !")
			document.Abon.pays.focus();
			document.Abon.pays.select();
			return false;
		}

		//alert("Remplissez s'il vous plait tous les champs !")
		//document.Abon.nom.focus();
		//document.Abon.nom.select();
		//return false;
		
	}
	else
	{
	//alert("Test1 réussi jusqu'ici");
	test_form1=1;
	formtest2();

	}

}








//var prenomliv, nomliv, orgliv, adr1liv, adr2liv, cpvliv, villiv ,valpaysliv=""


//Test N°2
function formtest2()
{
  	prenomliv=document.Abon.prenom_livr.value;
	nomliv=document.Abon.nom_livr.value;
	orgliv=document.Abon.organisme_livr.value;
	adr1liv=document.Abon.adresse1_livr.value;
	adr2liv=document.Abon.adresse2_livr.value;
	cpvliv=document.Abon.CP_livr.value;
	villiv=document.Abon.ville_livr.value;
	valpaysliv=document.Abon.pays_livr.value;
	if (nomliv=="" || prenomliv=="" || adr1liv=="" || cpvliv=="" || villiv=="" || valpaysliv=="" ) 
	{
		if (nomliv=="")
		{
			alert("Remplissez le champ NOM (Adresse de livraison) S.V.P !\nChamp obligatoire !");
			document.Abon.nom_livr.focus();
			document.Abon.nom_livr.select();
			return false;
		}
		if (prenomliv=="")
		{
			alert("Remplissez le champ PRENOM (Adresse de livraison)  S.V.P !\nChamp obligatoire !");
			document.Abon.prenom_livr.focus();
			document.Abon.prenom_livr.select();
			return false;
		}
		
		if (adr1liv=="" && adr2liv=="")
		{
			alert("Remplissez le champ ADRESSE et eventuellement COMP.ADRESSE (Adresse de livraison)  S.V.P !\nChamp obligatoire !");
			document.Abon.adresse1_livr.focus();
			document.Abon.adresse1_livr.select();
			return false;
		}

		if (cpvliv=="")
		{
			alert("Remplissez le champ CODE POSTAL (Adresse de livraison)  S.V.P !\nChamp obligatoire !");
			document.Abon.CP_livr.focus();
			document.Abon.CP_livr.select();
			return false;
		}


		if (villiv=="")
		{
			alert("Remplissez le champ VILLE (Adresse de livraison)  S.V.P !\nChamp obligatoire !")
			document.Abon.ville_livr.focus();
			document.Abon.ville_livr.select();
			return false;
		}
		

		if (valpaysliv=="")
		{
			alert("Remplissez les champ PAYS (Adresse de livraison)  S.V.P !\nChamp obligatoire !")
			document.Abon.pays_livr.focus();
			document.Abon.pays_livr.select();
			return false;
		}
		
		
	}
	else
	{
		//alert("Test1 réussi jusqu'ici");
		if 	(test_form1==1)
			{
				test_form2=1;
				test_mail();
			}
		else
			{
				formtest1();
			}	


	}

}



//Test N°3
function test_mail()
	{
	arobase=0;
	point=0;
	email=document.Abon.Email.value;
	if (email=="")
		{
			alert("Remplissez le champ EMAIL S.V.P !\nChamp obligatoire !")
			document.Abon.Email.focus();
			document.Abon.Email.select();
			return false;
		}

	for (i=0; i<email.length; i++) 
		{
			if (email.charAt(i)=="@")
				{
					arobase=1;
				}
			if (email.charAt(i)==".")
				{
					point=1;
				}
		}
	if (arobase!=1 || point!=1 || email.length<7) 
	{
		alert("Ce n'est pas une adresse E-mail valide !");
		document.Abon.Email.focus();
		document.Abon.Email.select();
		return false;
	}
	else
	{
		if 	(test_form2==1)
			{
				test_form3=1;
				//alert("Test2 réussi jusqu'ici");
				test_mod_pai();
			}
		else
			{
				formtest2();
			}	


	}	
}


//Test N°4
function test_mod_pai()
{
	//sélecteur
	//var verif_montant,verif_montport,verif_montapayfr,verif_montapayeu=0;
	
	sel_p2="";mode_p2="";
	sel_p2=document.Abon.sel_mod_pai.selectedIndex;
	mode_p2=document.Abon.sel_mod_pai.options[sel_p2].value;
	if(mode_p2=="" || mode_p2=="Indéterminé !!")
		{
			alert("Veuillez sélectionner votre mode de paiement S.V.P !\nChamp obligatoire !");
			document.Abon.sel_mod_pai.focus();
			//document.Abon.sel_mod_pai.select();
			return false;
		}
	
	else
		{
			//Ok
		}
	verif_montapayfr=0;verif_montapayeu=0;
	verif_montapayfr=document.Abon.Mont_reg_fr.value;
	verif_montapayeu=document.Abon.Mont_reg_eu.value;
	if (verif_montapayfr=="" || verif_montapayfr=="0"  || verif_montapayfr=="0.00")
		{
			alert("Vous ne pouvez passer une comande dont le montant en Francs est Nul !");
			return false;
		}
	else
		{
			 if( verif_montapayeu == "" || verif_montapayeu == "0" || verif_montapayeu =="0.00")
				{
					alert("Vous ne pouvez passer une comande dont le montant en Euro est Nul !");
					return false;
				}
			else
				{
					//Ok
				}
		}	
		
if 	(test_form3==1)
	{
		test_form4=1;
		//alert("Test4 réussi jusqu'ici");
		Test_info1();
	}
else
	{
		formtest3();
	}	

}


function info_autre()
{
	val_aut=0;
	val_txt_autre="";
	val_aut=0;val_aut=document.Abon.autre.checked;
	val_txt_autre=document.Abon.autre_text.value;
	if(val_aut=="1")
		{
			alert("Veuillez nous énoncer brièvement comment vous avez connu la revue\nRubrique Comment avez vous connu la revue\nChamp Autre");
			document.Abon.autre_text.focus();
			document.Abon.autre_text.select();
			return false;
		}
	if(val_aut=="0")
		{
			document.Abon.autre_text.value="";
			return false;
		}
		Test_info1();	
}


//Test N°5
function Test_info1()
{

	var tstsel_tot,tstsel_info1,tstsel_info2=0;
	var val_inter,val_lib,val_col,val_prof,val_rela,val_aut=0;
	var Txt_autre="";
	val_inter=0;val_inter=document.Abon.inter.checked;
	val_lib=0;val_lib=document.Abon.lib.checked;
	val_col=0;val_col=document.Abon.col.checked;
	val_prof=0;val_prof=document.Abon.prof.checked;
	val_rela=0;val_rela=document.Abon.rela.checked;
	val_aut=0;val_aut=document.Abon.autre.checked;
	Txt_autre="";Txt_autre=document.Abon.autre_text.value;
   if(val_inter=="0" && val_lib=="0" && val_col=="0" && val_prof=="0" && val_rela=="0" && val_aut=="0")
   	{
		tstsel_info1=0;   
	}
	else
	{
		Txt_autre="Revue découverte grace ";
		if(val_inter=="1")
		{
		    document.Abon.Info.value="";		
			Txt_autre=Txt_autre+" à Internet,";
			document.Abon.Info.value=Txt_autre;
		}
		if(val_lib=="1")
		{
		    document.Abon.Info.value="";
			Txt_autre=Txt_autre+" aux Librairies, Bibilothèques,";
			document.Abon.Info.value=Txt_autre;
		}
		if(val_col=="1")
		{
		    document.Abon.Info.value="";		
			Txt_autre=Txt_autre+" à Colloque ou à un séminaire,";
			document.Abon.Info.value=Txt_autre;
		}
		if(val_prof=="1")
		{
		    document.Abon.Info.value="";
			Txt_autre=Txt_autre+"  à mon secteur professionnel,";
			document.Abon.Info.value=Txt_autre;
		}
		if(val_rela=="1")
		{
		    document.Abon.Info.value="";
			Txt_autre=Txt_autre+" Par relation,";
			document.Abon.Info.value=Txt_autre;

		}

	
	
	}
			
   if(Txt_autre=="")
   	{
		tstsel_info2=0;
		//alert("Veuillez nous signifier, si vous le voulez bien, comment vous avez connu la Revue ...");
	}		
   tstsel_tot=0;tstsel_tot=tstsel_info1+tstsel_info2;
   if(tstsel_tot==0)
   	{
		alert("Veuillez nous signifier, si vous le voulez bien,\nComment vous avez connu la Revue ...\nAfin de perfectionner notre mode de diffusion...");
		document.Abon.inter.focus();
		document.Abon.inter.select();
		return false;
	}
   else
   {
   
  
   }   

if 	(test_form4==1)
	{
		test_form5=1;
		//alert("Test4 réussi jusqu'ici");
		 confirm_print();
	}
else
	{
		test_mod_pai();
	}	

}



function envoi_form()

{
	 confirm_print();

}








