//fonction addEvent
function addEvent(oElem, sEvType, fn, bCapture){
 return oElem.addEventListener? oElem.addEventListener(sEvType, fn, bCapture) : oElem.attachEvent?  oElem.attachEvent('on' + sEvType, fn) : oElem['on' + sEvType] = fn;
}
/***** DIAPORAMA EDITO *******/
my_time=5000;
l_actif=1;
l_ex_actif=0;
var the_timeout; 
var en_marche = true;
var bouge=0;
function activer_bouge(){bouge=1;}
function desactiver_bouge(){bouge=0;}

effect_time_ms=300;
effect_time_s=effect_time_ms/1000;
deplace=0;
tab_pos=[0,21,41,61,81];

function suivant(){
if (bouge == 0) {
  	en_marche = false;
  	l_ex_actif = l_actif;
  	l_actif = l_actif + 1;
  	if (l_actif > 4) {
  		l_actif = 1;
  	}
  	deplace = tab_pos[l_actif] - tab_pos[l_ex_actif];
  	show_volet(l_actif);
  }
}

function precedent(){
if (bouge == 0) {
  	en_marche = false;
  	l_ex_actif = l_actif;
  	l_actif = l_actif - 1;
  	if (l_actif < 1) {
  		l_actif = 4;
  	}
  	deplace = tab_pos[l_actif] - tab_pos[l_ex_actif];
  	show_volet(l_actif);
  }
}

function update_active(){
if (bouge == 0) {
  	l_ex_actif = l_actif;
  	l_actif = l_actif + 1;
  	if (l_actif > 4) {
  		l_actif = 1;
  	}
  	deplace = tab_pos[l_actif] - tab_pos[l_ex_actif];
  	show_volet(l_actif);
  }
}

function action_user(no_volet){
if (bouge == 0) {
  	en_marche = false;
  	l_ex_actif = l_actif;
  	l_actif = no_volet;
  	deplace = tab_pos[l_actif] - tab_pos[l_ex_actif];
  	show_volet(no_volet);
  }
}
function show_volet(no_volet){	
if(bouge == 0) {  
	activer_bouge();		
  	clearTimeout(the_timeout);
	
  	if ((l_ex_actif != 0) && ($('volet_' + l_ex_actif)) ) {		
  		new Effect.Opacity('volet_' + l_ex_actif, {
  			duration: effect_time_s,
  			transition: Effect.Transitions.linear,
  			from: 1.0,
  			to: 0.3
  		});
  	}
 	if($("cadre"))
	  	new Effect.Move($("cadre"), {
	  		duration: effect_time_s,
	  		x: deplace,
	  		y: 0,
	  		mode: 'relative',
				afterFinish:desactiver_bouge
	  	});
	change_style(no_volet);
	if (en_marche == true) the_timeout = setTimeout('update_active()', my_time);	
	}
}
function change_style(no_volet){
	for (i=1;i<=4;i++){
		if(document.getElementById('volet_'+i))	document.getElementById('volet_'+i).style.display='none';
		if(document.getElementById('link_'+i)) 	document.getElementById('link_'+i).style.color='#505050';  
	}
	if(document.getElementById('volet_'+no_volet)) document.getElementById('volet_'+no_volet).style.opacity='0.3';			
	if(document.getElementById('volet_'+no_volet)) document.getElementById('volet_'+no_volet).style.display='block';
	if(document.getElementById('volet_'+no_volet))  new Effect.Opacity('volet_'+no_volet,{ duration: effect_time_s,transition: Effect.Transitions.linear,from: 0.3, to: 1.0 });
	if(document.getElementById('link_'+no_volet)) document.getElementById('link_'+no_volet).style.color='#FFFFFF';	
}
/*** Gestion des blocs d'infos ***/
function bloc_desc_on(no_bloc,no_info,nbr_bloc,nbr_info){
	
	for (i=1;i<=nbr_info;i++){
		if (i!=no_info){
			if($('bloc'+no_bloc+'_info'+i) && Element.hasClassName('bloc'+no_bloc+'_info'+i,'menu_on'))
			{
				$('bloc'+no_bloc+'_info'+i).removeClassName('menu_on');
				$('bloc'+no_bloc+'_info'+i).toggleClassName('menu_off');
				$('bloc'+no_bloc+'_content_'+i).style.display='none';
			}
		}
		else{
			if($('bloc'+no_bloc+'_content_'+i) && Element.hasClassName('bloc'+no_bloc+'_info'+i,'menu_off'))
			{
				$('bloc'+no_bloc+'_content_'+i).style.display='block';				
				$('bloc'+no_bloc+'_info'+i).removeClassName('menu_off');
				$('bloc'+no_bloc+'_info'+i).toggleClassName('menu_on');
			}
		}
	}
}
function changepays(){
	var ancre = document.forms[0].Lpays[document.forms[0].Lpays.selectedIndex].value ;
	self.location.href = "#" + ancre;
}

/**
 * Affichage des partenaires suivant la valeur de l'ancre #
 */
function loadListRegies(){	
	var url = window.location.href;
	if( url.lastIndexOf("#") != -1 ){	
		paramObject = url.substring(url.lastIndexOf("#")+1,url.length);
		displayListRegies(paramObject);
	}else		
		displayListRegies('AC'); /* default */
}
/**
 * Affichage des partenaires suivant la valeur de id_div
 * @param {String} id_div : id de l'index qui doit �tre affich�
 * id_div ='AC','DG','HJ','KM','NP','QS','TV','WZ'
 */
function displayListRegies(id_div){
	var tableListRegies=['AC','DG','HJ','KM','NP','QS','TV','WZ'];
	var badId = 0;
	
	if( id_div.lastIndexOf("#") != 	-1 ){		
		var firstLetter=id_div.substring(id_div.lastIndexOf("#")+1,id_div.lastIndexOf("#")+2);	
		for(var i=0; i< tableListRegies.length ;i++){
			if( (firstLetter >= tableListRegies[i].substring(0,1)) && (firstLetter <= tableListRegies[i].substring(1,2)) ) 
			{	
				id_div = tableListRegies[i];
				break;
			}
		}
	}
	
	for(var i=0; i< tableListRegies.length ;i++){
		if(	tableListRegies[i] != id_div && document.getElementById(tableListRegies[i]))
		{
			document.getElementById(tableListRegies[i]).style.display = 'none';
			document.getElementsByClassName(tableListRegies[i])[0].style.fontWeight= 'normal';
		}
		else{	
			badId = 1 ;
			if(document.getElementById(id_div)) document.getElementById(id_div).style.display = 'block';			
			if(document.getElementsByClassName(id_div)) document.getElementsByClassName(id_div)[0].style.fontWeight = 'bold';
		}
	}
	
	if(badId == 0)
		displayListRegies('AC'); 
}	
/* Display of cobranding by country */
function displayListCobranding(id_div){
	if( document.getElementById(id_div) ){
		for(i=0;i<tableauIdPays.length;i++)
		{
			if( (tableauIdPays[i] == id_div) && (document.getElementById(id_div)) )	
				document.getElementById(id_div).style.display = 'block';
			else
				if(document.getElementById(tableauIdPays[i]))
					document.getElementById(tableauIdPays[i]).style.display = 'none';
		}
	}
}	
/**
 * Affichage de la navigation principale 
 * @param {String} num_id : id de la rubrique principale a activer
 */
function etat_menu(num_id){	
	for (i=1;i<=9;i++){
		if (i!=num_id){
			if(Element.hasClassName('rublevel1_'+i,'link_nav_on')){
				$('rublevel1_'+i).removeClassName('link_nav_on');
				$('rublevel1_'+i).addClassName('link_nav_off');				
			}
		}
		else{			
			if(Element.hasClassName('rublevel1_'+i,'link_nav_off')){
				$('rublevel1_'+i).removeClassName('link_nav_off');
				$('rublevel1_'+i).addClassName('link_nav_on');				
			}
		}
	}
}
/**
 * fonction loadingPageFunctions: affichage de la navigation principale et transversale
 * fonction loadListRegies : affichade des r�gies
 * @param {String} id1 : id de la rubrique principale
 * @param {String} id2 : id de la rubrique de niveau 2
 * @param {String} id3 : id de l'objet en cours de niveau 3 (pas obligatoire)
 * @param {string} type : nom de la structure de l'objet en cours (obligatoire si id3 est renseign�)
 */
function loadRegiesFunctions(id1,id2,id3,type){	
	loadingPageFunctions(id1,id2,id3,type);
	loadListRegies();
}
/**
 * fonction etat_menu: affichage de la navigation principale 
 * fonction displayMenu : affichage de la navigation transversale (si id2 n'est pas vide)
 * @param {String} id1 : id de la rubrique principale
 * @param {String} id2 : id de la rubrique de niveau 2
 * @param {String} id3 : id de l'objet en cours de niveau 3 (pas obligatoire)
 * @param {string} type : nom de la structure de l'objet en cours (obligatoire si id3 est renseign�)
 */
function loadingPageFunctions(id1,id2,id3,type){
	etat_menu(id1);
	if(id2!='')	displayMenu(id2,id3,type);
}
/**
 * fonction etat_menu: affichage de la navigation principale 
 * fonction show_volet : affichage du bloc editorial
 * @param {String} id1 : id de la rubrique principale
 */
function indexPageFunctions(id1){
	etat_menu(id1);
	show_volet(l_actif);
}
/**
 * @param {String} targ
 * @param {String} selObj
 * @param {String} restore
 */
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function bs(url1,large,haut,resizable) {
		var bs = window.open(url1,'','scrollbars=yes,menubar=no,status=no,resizable=yes,top=100,left=100,width='+large+',height='+haut+'');
		bs.focus();
}

function displayId(name_id, link_id,num_id){
	var id_link = link_id+num_id;
	if($(name_id) && (document.getElementById(name_id).style.display == 'none') )
	{
		if(document.getElementById(name_id))document.getElementById(name_id).style.display = 'block';
		if(document.getElementById(id_link))
		{
			$(id_link).removeClassName(link_id+'_off');		
			$(id_link).addClassName(link_id+'_on');
		}
	}
	else
	if($(name_id) && (document.getElementById(name_id).style.display == 'block') )
		if(document.getElementById(name_id))document.getElementById(name_id).style.display = 'none';
		if(document.getElementById(id_link)){
			$(id_link).removeClassName(link_id+'_on');
			$(id_link).addClassName(link_id+'_off');
		}
}

/* Modification de la couleur des labels. champs valide couleur normal, champs non valide couleur rouge */
function changeColor(arg,color){
	var labels= document.getElementsByTagName("label"); 
	if (labels) {	
		for (i = 0; i < labels.length; i++) {
			if( labels[i] && (labels[i].htmlFor == arg) )
			{
			 labels[i].style.color=color;
			 break;
			}
		}
	}
}

function doSubmit() {	
	var fieldValue = document.form_mail['send'].value;	

	if(!fieldValue && !document.form_mail['send'])
	return;
	
	document.form_mail['send'].value="true";
	document.form_mail['send'].submit();
}
/* affichage du bouton d'envoie */
function toggleDisplayButton(flag) {
  var pnode = document.getElementById('submit_form');
  if(pnode){
     pnode.style.display = (flag == true ? 'block': 'none') ;
  }
}	

/**
 * fonction qui cache ou montre un bloc 
 * @param {Object} idElement
 * @param (Object) displ : pour savoir si on met l'�l�ment inline ou block
 */
function cacheBlock(id) {	
	var el = document.getElementById(id);
	if(el){
		el.style.display = (el.style.display == 'block' ? 'none' : 'block' );
	}
}

function redirect(url){
	if(!url || url=='' )
	document.location = "/"; 
	else
		document.location = url; 
}



function initialize() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_ci"));
		map.setCenter(new GLatLng(48.881973, 2.268308), 14);
		map.addMapType(G_SATELLITE_3D_MAP);
		map.addControl(new GOverviewMapControl());
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		geocoder = new GClientGeocoder();
	}
}
function afficherAdresse(address) {
	if (geocoder) {
		geocoder.getLatLng(
		address,
		function(point) {
			if (!point) {
				alert("NO FOUND :" +address);
				} else {
				map.setCenter(point, 13);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml(address);
					}
				}
			);
	}
}	