
function changeState(id) 
{
	var d = document.getElementById('sMenu'+ id);
	
	var icone = document.getElementById('icone'+ id);
	
	
	if (d.style.display == 'none') 
	{ 
		d.style.display = 'block';
		icone.setAttribute('src', 'IMG/publication/commande/moins.jpg');
		
	}
	else if (d.style.display == 'block') 
	{ 
		d.style.display = 'none';
		icone.setAttribute('src', 'IMG/publication/commande/plus.jpg');
	}
}

function popup(page,largeur,hauteur,options)
{
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

req	 = null ;
function query(argv)
{
	
	// Récupérer les informations sur le navigateur
			if(navigator.appName.search("Internet Explorer") != -1)
			{
				req = new ActiveXObject("Microsoft.XMLHTTP") ;
				
			}
			else
			{
				req = new XMLHttpRequest() ;
			}

				// Définit la fonction à appeler lorsque l\'attribut readyState est modifié
				req.onreadystatechange = pop_up_alert ;
				req.open(0, 'lib/ajax_query.php?' + argv) ;
				req.send(null) ;
				
}

function pop_up_alert()
{
	
	if(req.readyState == 4)
	{
		if(req.status == 200)
		{
			reponse =  req.responseText;
			//alert(reponse);
			var idRubrique = reponse.substring(0, reponse.indexOf("&"));
			//alert(idRubrique);
			var selectType = reponse.substring(reponse.indexOf("&") + 1, reponse.indexOf("="));
			//alert(selectType);
			var argv = reponse.substring(reponse.indexOf("=") + 1, reponse.length);
			//alert(argv);
			var select = document.createElement('select');
			if(selectType == 'Pays')
			{
   				select.setAttribute('name', 'selectPays');
   				select.setAttribute('id', 'selectPays');
   				
   				select.onchange = function(){query('idRubrique='+idRubrique+'&numPays='+ this.value);};
   				
			}
			
			if(selectType == 'Region')
			{
   				select.setAttribute('name', 'selectRegion');
   				select.setAttribute('id', 'selectRegion');
   				
			}
			
			
   
   			var size = argv.length;
   			//alert(size);
   			var j = 0;
   			var nb = 1;
   			var selectOption = new Array();
   			for(i = 1; i < size; i++)
   			{
   				if(argv.charAt(i) == "|")
   				{
   					selectOption[nb] = argv.substring(j, i);
   					j = i + 1;
   					nb = nb + 1;
   				}	
   			}
   			
   			for(i = 1; i < nb; i++)
   			{
   				ind = selectOption[i].indexOf(";");
   				option = selectOption[i].substring(0, ind);
   				text = selectOption[i].substring(ind + 1, selectOption[i].length); 
   				select.options[i] = new Option(text, option);
   				//alert(option + ' '+text);
   			}
   			
   			
   			var selectPaysDiv = document.getElementById('selectPaysDiv');
   			var child = selectPaysDiv.childNodes;
   			var nbChild = child.length;
   			//alert(nbChild);
   			
   			if(selectPaysDiv.hasChildNodes() == true) 
   			{
   				
   				
   					if((nbChild == 2) && (selectType == 'Region'))
   					{
   						var oldSelectRegion = document.getElementById('selectRegion');
   						selectPaysDiv.removeChild(oldSelectRegion); 
   					}
   				
   					else if(nbChild == 2)
   					{
   					
   						var oldSelectRegion = document.getElementById('selectRegion');
   						selectPaysDiv.removeChild(oldSelectRegion); 
   						var oldSelectPays = document.getElementById('selectPays');
   						selectPaysDiv.removeChild(oldSelectPays); 
   					
   					}
   				
   				
   					else if((nbChild == 1) && (selectType == 'Pays'))
   					{
   						var oldSelectPays = document.getElementById('selectPays');
   						selectPaysDiv.removeChild(oldSelectPays); 
   					}
   				}
   				
   			if(select.options.length > 0)
   			{
   				if(selectType == 'Region') select.options[0] = new Option('--- région française ---', '');
   				if(selectType == 'Pays') select.options[0] = new Option('--- pays --------------', '');
   				select.options[0].selected = 'selected';
   				selectPaysDiv.appendChild(select);
   			}
		
		}
	}
}

numAmi = 1;
function ajoutAmi(){
	var divAjoutAmi = document.getElementById('divAjoutAmi');
   	var newAmi = document.createElement('input');
   	newAmi.setAttribute('name', 'emailAmi[]');
   	newAmi.setAttribute('id', 'emailAmi' + numAmi);
	newAmi.setAttribute('size', 20);
	//newAmi.style.marginLeft = '80px';
	
	var labelAmi = document.createElement('span');
   	labelAmi.appendChild(document.createTextNode("autre courriel:"));
   	//labelAmi.style.padding-left = '20';
	labelAmi.setAttribute('id', 'labelAmi' + numAmi);
	//labelAmi.style.fontWeight = 'bold';
   
   
   	var br = document.createElement('br');
	br.setAttribute('name', 'brAmi' + numAmi);
	br.setAttribute('id', 'brAmi' + numAmi);
	
	var buttonSupprimer = document.createElement('button');
	buttonSupprimer.setAttribute('name', 'delAmi_' + numAmi);
	
	
	buttonSupprimer.setAttribute("onclick",function(){
		delName = this.name;
		delSize = delName.length;
		num = this.name.substring(7, delSize);
		var d = document.getElementById('divAjoutAmi');
		var oldLabelAmi = document.getElementById('labelAmi' + num);
		var oldNewAmi = document.getElementById('emailAmi' + num);
		var oldBr = document.getElementById('brAmi' + num);
  		
  		d.removeChild(oldLabelAmi);
  		d.removeChild(oldNewAmi);
  		d.removeChild(oldBr);
  		d.removeChild(this);
  		});
	
	buttonSupprimer.onclick=function(){
		delName = this.name;
		delSize = delName.length;
		num = this.name.substring(7, delSize);
		var d = document.getElementById('divAjoutAmi');
		var oldLabelAmi = document.getElementById('labelAmi' + num);
		var oldNewAmi = document.getElementById('emailAmi' + num);
		var oldBr = document.getElementById('brAmi' + num);
  		
  		d.removeChild(oldLabelAmi);
  		d.removeChild(oldNewAmi);
  		d.removeChild(oldBr);
  		d.removeChild(this);
	};
	buttonSupprimer.appendChild(document.createTextNode("retirer"));
	buttonSupprimer.style.backgroundColor = "#FFFFFF";
	buttonSupprimer.style.fontFamily = "Courier";
	buttonSupprimer.style.color = "#0000CC";
	
	divAjoutAmi.appendChild(labelAmi);
	divAjoutAmi.appendChild(newAmi);
	divAjoutAmi.appendChild(buttonSupprimer);
	divAjoutAmi.appendChild(br);
	
	numAmi++;
	
	
}


function verifPanier(form)
{ 
	
 	var message_alert = "";
 	var first_element = true;
 	for(var i = 0; i < form.length - 1; i++) 
 	{
     	var rechRapide = form.elements[i].value;
     	var nom_champ = form.elements[i].name;
  		if((nom_champ == 'email') || (nom_champ == 'emailAmi[]')) 
       	{
       		if(!(rechRapide.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.fr)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi))) 
       		{
				if(first_element) form.elements[i].focus();
				first_element = false;
				form.elements[i].style.backgroundColor = "#CCCCCC";
          		message_alert ="Email invalide";
       		}
       }
    }
    if(message_alert == "") return true;
    else 
    {
    	alert(message_alert);
    	return false;
    }
    
}


function verifAnnoncesAssoc()
{ 
	
 	var message_alert = "";
 	var nom = document.getElementById('auteur');
 	if(nom.value == '') message_alert = "Vous devez enter un nom";
 	nom.focus();
 	
 	var email = document.getElementById('email_auteur');
 	if(!(email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.fr)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi))) 
 	{
 		message_alert = message_alert + "\nVotre Email est invalide";
 		email.focus();
 	}
 	
    if(message_alert == "") return true;
    else 
    {
    	alert(message_alert);
    	return false;
    }
    
}

function verifFormulaireFormation()
{ 
	
 	var message_alert = "Erreur dans la saisie du formulaire";
 	var nom = document.getElementById('nom');
 	var prenom = document.getElementById('prenom');
 	var profession = document.getElementById('profession');
 	var structure = document.getElementById('organisme');
 	var adresse = document.getElementById('adresse');
 	var tel = document.getElementById('tel');
 	var email = document.getElementById('courriel');
 	var pass = false;
 	if(nom.value == '') 
 	{
 		message_alert = message_alert + "\nVeuillez entrer votre nom";
 		nom.focus();
 		pass = true;
 	}
 	if(prenom.value == '') 
 	{
 		message_alert = message_alert + "\nVeuillez entrer votre prénom";
 		if(!pass) prenom.focus();
 		pass = true;
 	}
 	
 	if(profession.value == '') 
 	{
 		message_alert = message_alert + "\nVeuillez entrer votre profession ou fonction";
 		if(!pass) profession.focus();
 		pass = true;
 	}
 	
 	if(structure.value == '') 
 	{
 		message_alert = message_alert + "\nVeuillez entrer votre organisme employeur";
 		if(!pass) structure.focus();
 		pass = true;
 	}
 	
 	if(adresse.value == '') 
 	{
 		message_alert = message_alert + "\nVeuillez entrer votre adresse";
 		if(!pass) adresse.focus();
 		pass = true;
 	}
 	
 	if(!(email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.fr)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi))) 
 	{
 		message_alert = message_alert + "\nVotre courriel est invalide";
 		if(!pass) email.focus();
 		pass = true;
 	}
 	
 	if(!pass) return true;
    else 
    {
    	alert(message_alert);
    	return false;
    }
    
}

function verifFormulaireAbonnement()
{ 
	
 	var message_alert = "Erreur dans la saisie du formulaire";
 	var nom = document.getElementById('nom');
 	var prenom = document.getElementById('prenom');
 	var structure = document.getElementById('organisme');
 	var zoneGeo = document.getElementById('zoneGeo');
 	var email = document.getElementById('courriel');
 	var abonnementDocAlerte = document.getElementById('InscriptionDocAlerte').checked;
 	var abonnementRdpAfrique = document.getElementById('InscriptionRdpAfrique').checked;
 	var abonnementInvitation = document.getElementById('InscriptionInvitation').checked;
 	var abonnementlettreInfo = document.getElementById('InscriptionlettreInfo').checked;
 	
 	var abonnementRdpH = document.getElementById('InscriptionRdpH').checked;
	var abonnementRdpQ = document.getElementById('InscriptionRdpQ').checked;
 	
 	
 	var pass = false;
 	
 	if((!(abonnementDocAlerte)) && 
	(!abonnementRdpAfrique) && 
	(!abonnementInvitation) && 
	(!abonnementRdpH) && 
	(!abonnementRdpQ) && 
	(!abonnementlettreInfo)

	)
 	{
 		message_alert = message_alert + "\nVeuillez choisir un abonnement";
 		pass = true;
 	}
 	
 	
 	if(nom.value == '') 
 	{
 		message_alert = message_alert + "\nVeuillez entrer votre nom";
 		nom.focus();
 		pass = true;
 	}
 	if(prenom.value == '') 
 	{
 		message_alert = message_alert + "\nVeuillez entrer votre prénom";
 		if(!pass) prenom.focus();
 		pass = true;
 	}
 	
 	if(!(email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.fr)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi))) 
 	{
 		message_alert = message_alert + "\nVotre courriel est invalide";
 		if(!pass) email.focus();
 		pass = true;
 	}
 	
 	if(zoneGeo.value == '') 
 	{
 		message_alert = message_alert + "\nVeuillez entrer votre zone d'habitation";
 		if(!pass) prenom.focus();
 		pass = true;
 	}
 	
 	var selectDivZoneGeo = document.getElementById('selectZoneGeoAbonnement');
   	var child = selectDivZoneGeo.childNodes;
   			
   	if(selectDivZoneGeo.hasChildNodes() == true) 
   	{
 		
   		var zoneGeo2 = document.getElementById('selectNewZoneGeoAbonnement');
   		if(zoneGeo2.value == '') 
   		{
   			message_alert = message_alert + "\nVeuillez entrer votre zone d'habitation";
 			if(!pass) zoneGeo2.focus();
 			pass = true;
   		}
 	}
 	
 	if(!pass) return true;
    else 
    {
    	alert(message_alert);
    	return false;
    }
    
}

req	 = null ;
function queryZoneGeoAbonnement(argv)
{
	
	// Récupérer les informations sur le navigateur
			if(navigator.appName.search("Internet Explorer") != -1)
			{
				req = new ActiveXObject("Microsoft.XMLHTTP") ;
				
			}
			else
			{
				req = new XMLHttpRequest() ;
			}

				// Définit la fonction à appeler lorsque l\'attribut readyState est modifié
				req.onreadystatechange = buildSelect ;
				req.open(0, 'lib/ajax_query.php?' + argv) ;
				req.send(null) ;
				
}

function buildSelect()
{
	
	if(req.readyState == 4)
	{
		if(req.status == 200)
		{
			
			reponse =  req.responseText;
			if(reponse == "") return;
			
			var selectType = reponse.substring(0, reponse.indexOf(":"));
			var argv = reponse.substring(reponse.indexOf(":") + 1, reponse.length);
			var select = document.createElement('select');
			select.setAttribute('name', 'selectNewZoneGeoAbonnement');
   			select.setAttribute('id', 'selectNewZoneGeoAbonnement');
   				
	
			
			var size = argv.length;
   			//alert(size);
   			var j = 0;
   			var nbOption = 1;
   			for(i = 1; i < size; i++)
   			{
   				if(argv.charAt(i) == ";")
   				{
   					text = argv.substring(j, i);
   					j = i + 1;
   					select.options[nbOption] = new Option(text, text);
   					nbOption++;
   					
   					
   				}	
   			}
   			
   			
   			
   			var selectDivZoneGeo = document.getElementById('selectZoneGeoAbonnement');
   			var child = selectDivZoneGeo.childNodes;
   			
   			if(selectDivZoneGeo.hasChildNodes() == true) 
   			{
   				
   				var oldSelect = document.getElementById('selectNewZoneGeoAbonnement');
   				selectDivZoneGeo.removeChild(oldSelect); 
   					
   			}
   				
   			if(select.options.length > 1)
   			{
   				if(selectType == 'france') 
   				{
   					select.options[0] = new Option('--- région française ---', '');
   					select.options[select.options.length] = new Option('Province', 'Province');
   					select.options[select.options.length] = new Option('DOM-TOM', 'DOM-TOM');
   					
   				}
   				if(selectType == 'afrique') 
   				{
   					select.options[0] = new Option('------------ pays ------------', '');
   					select.options[select.options.length] = new Option('Autre', 'Afrique-Autre');
   				}
   				select.options[0].selected = 'selected';
   				selectDivZoneGeo.appendChild(select);
   			}
		
		}
		
	}
}


// Vérification de la bonne saisie d'un organisme

function verifNewOrganisme()
{
	var message_alert = "Erreur dans votre saisie :";
 	var nom_libelle = document.getElementById('nom_libelle');
 	var str_auteur = document.getElementById('str_auteur');
 	var str_email_auteur = document.getElementById('str_email_auteur');
 	var adresse = document.getElementById('adresse');
 	var cp = document.getElementById('cp');
 	var ville = document.getElementById('ville');
 	var pays = document.getElementById('pays');
 	var tel = document.getElementById('tel');
 	var email = document.getElementById('courriel');
 	
 	
 	var pass = false;
 	
 	if(str_auteur.value == '') 
 	{
 		message_alert = message_alert + "\n-Veuillez entrer votre nom et/ou le nom de votre organisme";
 		str_auteur.focus();
 		pass = true;
 		str_auteur.style.backgroundColor = "#FF9999";
 	}
 	else str_auteur.style.backgroundColor = "lightblue"; 
 	
 	
 	if(!(str_email_auteur.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.fr)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi))) 
 	{
 		message_alert = message_alert + "\n-Veuillez entrer votre courriel";
 		if(!pass) str_email_auteur.focus();
 		pass = true;
 		str_email_auteur.style.backgroundColor = "#FF9999";
 	}
 	else str_email_auteur.style.backgroundColor = "lightblue"; 
 	
 	
 	
 	
 	if(nom_libelle.value == '') 
 	{
 		message_alert = message_alert + "\n-Veuillez entrer un nom de structure";
 		if(!pass) nom_libelle.focus();
 		pass = true;
 		nom_libelle.style.backgroundColor = "#FF9999";
 	}
 	else nom_libelle.style.backgroundColor = "lightblue"; 
 	
 	
 	
 	
 	
 	if(adresse.value == '') 
 	{
 		message_alert = message_alert + "\n-Veuillez entrer l'adresse de la structure";
 		if(!pass) adresse.focus();
 		pass = true;
 		adresse.style.backgroundColor = "#FF9999";
 	}
 	else adresse.style.backgroundColor = "lightblue"; 
 	
 	if(cp.value == '') 
 	{
 		message_alert = message_alert + "\n-Veuillez entrer le code postal de la structure";
 		if(!pass) cp.focus();
 		pass = true;
 		cp.style.backgroundColor = "#FF9999";
 	}
 	else cp.style.backgroundColor = "lightblue"; 
 	
 	if(ville.value == '') 
 	{
 		message_alert = message_alert + "\n-Veuillez entrer la ville de la structure";
 		if(!pass) ville.focus();
 		pass = true;
 		ville.style.backgroundColor = "#FF9999";
 	}
 	else ville.style.backgroundColor = "lightblue"; 
 	
 	if(pays.value == '') 
 	{
 		message_alert = message_alert + "\n-Veuillez entrer le pays de la structure";
 		if(!pass) ville.focus();
 		pass = true;
 		pays.style.backgroundColor = "#FF9999";
 	}
 	else pays.style.backgroundColor = "lightblue"; 
 	
 	if(tel.value == '') 
 	{
 		message_alert = message_alert + "\n-Veuillez entrer le téléphone ";
 		if(!pass) tel.focus();
 		pass = true;
 		tel.style.backgroundColor = "#FF9999";
 	}
 	else tel.style.backgroundColor = "lightblue"; 
 	
 	if(!(email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.fr)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi))) 
 	{
 		message_alert = message_alert + "\n-Veuillez entrer le courriel de la structure";
 		if(!pass) email.focus();
 		pass = true;
 		email.style.backgroundColor = "#FF9999";
 	}
 	else email.style.backgroundColor = "lightblue"; 
 	
 	if(!pass) return true;
    else 
    {
    	alert(message_alert);
    	return false;
    }
}








