// JavaScript Document
$(document).ready(function(){
	//précharge les images
	var liste_images = new Array("/FRONT/COLAS/images/puce_rotative_yellow.png","/FRONT/COLAS/images/puce_rotative_blue.png","/FRONT/COLAS/images/puce_rotative_red.png","/FRONT/COLAS/images/puce_rotative_pink.png","/FRONT/COLAS/images/puce_rotative_green.png","/FRONT/COLAS/images/puce_rotative_brown.png","/FRONT/COLAS/images/puce_rotative_purple.png","/FRONT/COLAS/images/puce_rotative_off.png");
	for(var i=0;i<liste_images.length;i++){
		var image = new Image();
		image.src = liste_images[i];
	}
	
	/**
	 * Rajouté par Manuelle GUSTAVE pour la page gestion des
	 * onglets*
	 */
	// initialisation des variables avec les valeurs du premier
	// onglet
	var old_object = $(".article .section .tabs ul:not(.sansjs) li a")[0];
	if(old_object){
	var old_title = old_object.title;
	
	old_object.title=old_object.title+ $("#label_onglet_actif").html();
	}
	
	//alert('ok');
	$(".home .rotative").css({overflow:'hidden'});
	$(".controles .play").css({display:'block'});
	$(".home .rotative .info").css({height:'auto'});
	$(".home .rotative .info").hide();
	$(".home .controles ul li a").click(function(){
		arreterDiaporama();
		diaporamaActif = Number($(this).attr('href').substr(9,1))-1;
		afficherDiaporama();
		return false;
	})
	$(".home .controles .play a").click(function(){
		if(drapeau==1){
			arreterDiaporama();
		}else{
			lancerDiaporama();
		}
		return false;
	})
	
	$(".article .section .accordeon .texte").each(function(i){
		if(i!=0){
			$(this).hide();
		}
	})
	$(".article .section .accordeon .top_cache").hide();
	$(".article .section .liste_accordeon").hide();
	$(".article .section .accordeon h2 a").click(function(){
		$(this).parent().parent().find(".accordeon .texte").stop();
		//$(this).parent().parent().siblings(".accordeon").find(".texte").hide();
		$(this).parent().parent().siblings(".accordeon").find(".texte:visible").animate({height:"0",opacity:"show",opacity:"hide"},1000);
		$(this).parent().parent().find(".texte").show();
		$(this).parent().parent().find(".texte").css({height:"0"});
		$(this).parent().parent().find(".texte").animate({height:($(this).parent().parent().find(".texte .texte_wrap").height()+10)+"px"},1000);
		return false;
	})
	$(".article .section form.commander_publication .erreur span").hide();
	$(".article .section form.commander_publication button").click(function(){
	 	var erreur = false;
	 	/**Rajouter par Manuelle GUSTAVE pour la gestion des pays**/
		$(".article form.commander_publication .obligatoire select").each(function(n){
	
			if($(this).attr("value")=="-1"){
				$(this).parent().find('.erreur span').show();
				erreur = true;
			}else{
				$(this).parent().find('.erreur span').hide();
			}
		});
		$(".article form.commander_publication .obligatoire input:text").each(function(n){
			if($(this).attr("value")==""){
				$(this).parent().find('.erreur span').show();
				erreur = true;
			}else{
				$(this).parent().find('.erreur span').hide();
			}
		})
		$(".article form.commander_publication .obligatoire textarea").each(function(n){
			if($(this).val()==""){
				$(this).parent().find('.erreur span').show();
				erreur = true;
			}else{
				$(this).parent().find('.erreur span').hide();
			}
		})
		var civilite = false;
		$(".article form.commander_publication .obligatoire input:radio:checked").each(function(n){
			civilite = true;
		})
		if(civilite != true){
			erreur = true;
			$(".article form.commander_publication .coche .erreur span").show();
		}else{
			$(".article form.commander_publication .coche .erreur span").hide();
		}
		if (erreur != false) return false;
	})
	
	
	$(".article .section form.publications .erreur span").hide();
	$(".article .section form.publications button").click(function(){
	 	var erreur = false;
		var choix = false;
		$(".article form.publications input:checkbox:checked").each(function(n){
			choix = true;
		})
		if(choix != true){
			erreur = true;
			$(".article form.publications .erreur span").show();
		}else{
			$(".article form.publications .erreur span").hide();
		}
		if (erreur != false) return false;
	})
	
	$(".article .section form.inscription .erreur span").hide();
	$(".article .section form.inscription button").click(function(){
	 	var erreur = false;
		if ($(".article form.inscription .mail input").attr("value")==""){
			erreur = true;
			$(".article form.inscription .erreur span").show();
		}else{
			$(".article form.inscription .erreur span").hide();
		}
		if (erreur != false) return false;
	})
	
	

	$(".article .section form.selection_objectifs .erreur span").hide();
	$(".article .section form.selection_objectifs button").click(function(){
	 	var choix = false;
		$(".article form.selection_objectifs input:radio:checked").each(function(n){ /* Modifié par Manuelle GUSTAVE le 030809 input:checkbox*/
			choix = true;
		})
		if(choix != true){
			$(".article .section form.selection_objectifs .erreur span").show();
		}
		return choix;
	})
	
	$(".article .section form.selection_profils .erreur span").hide();
	$(".article .section form.selection_profils button").click(function(){
	 	var choix_radio = false;
		$(".article form.selection_profils input:radio:checked").each(function(){
			choix_radio = true;
		})
		if(choix_radio != true){
			$(".article .section form.selection_profils .erreur span").show();
		}
		return choix_radio;
	})
	
	
	$(".article  form.filtre_google_earth .erreur span").hide();
	$(".article  form.filtre_google_earth button").click(function(){
	 	var choix = false;
		$(".article form.filtre_google_earth input:checkbox:checked").each(function(n){
			choix = true;
		})
		if(choix != true){
			$(".article  form.filtre_google_earth .erreur span").show();
			return false;
		}
	})
	
	$(".article  form.envoyer_candidature .erreur span").hide();
	
	$(".article  form.envoyer_candidature button").click(function(){
		var erreur = false;
		
		$(".article form.envoyer_candidature .obligatoire input:text").each(function(n){
			if($(this).attr("value")==""){
				$(this).parent().find('.erreur span').show();
				erreur = true;
			}else{
				$(this).parent().find('.erreur span').hide();
			}
		})
		var civilite = false;
		$(".article form.envoyer_candidature .obligatoire input:radio:checked").each(function(n){
			civilite = true;
		})
		if(civilite != true){
			erreur = true;
			$(".article form.envoyer_candidature .coche .erreur span").show();
		}else{
			$(".article form.envoyer_candidature .coche .erreur span").hide();
		}
		if (erreur != false) return false;
	})
	$(".article  form.filtre_recherche .erreur span").hide();
	$(".article  form.filtre_recherche button").click(function(){
		if($(".article form.filtre_recherche select").val()=="0"){
			$(".article  form.filtre_recherche .erreur span").show();
			return false;
		}
	})
	
	
	$(".article form.cherche_google_earth .erreur span").hide();
	$(".article form.cherche_google_earth button").click(function(){
	 	var erreur = false;
		var value = $(".article form.cherche_google_earth input#cherche_cp").attr("value");
		if (value==""){
			erreur = true;
			$(".article form.cherche_google_earth .erreur span").show();
			$(".article form.cherche_google_earth .erreur span.erreur2").hide();
		}else if(isNaN(Number(value)) || value.length !=5){
			erreur = true;
			$(".article form.cherche_google_earth .erreur span").show();
			$(".article form.cherche_google_earth .erreur span.erreur1").hide();
		}
		//alert();
		if (erreur != false) return false;
	})
	
	$(".article .section .tabs_contents .tab_content").each(function(n){
		if(n!=0){
			$(this).hide();
		}
	})

	$(".article .section .tabs ul:not(.sansjs) li a").click(function(){
		
		/* Rejouté par Manuelle GUSTAVE 20090312 */
		if (old_object.title != "") {
			old_object.title = old_title; // reinitialise
			// le titre de
			// l'onglet
			// precedent
		}
	
		old_object = this; // stocke l'objet precedent dans
		// une variable
		old_title = this.title; // stocke le titre de
		// longlet d'origine
		this.title = this.title + " "
				+ $("#label_onglet_actif").html(); // rajoute
		// onglet
		// actif
		// à
		// l'onglet
		// selectionné
		$(this).parent().addClass('on');
		$(this).parent().siblings('li').removeClass('on');
		$($(this).attr('href')).show();
		$($(this).attr('href')).siblings('.tab_content').hide();
		return false;
	})
	
	$(".controles_texte ul li.petit a").click(function(){
		$("#ancrecontenu").css({'font-size':"1em"});
		return false;
	})
	$(".controles_texte ul li.moyen a").click(function(){
		$("#ancrecontenu").css({'font-size':"2em"});
		return false;
	})
	$(".controles_texte ul li.grand a").click(function(){
		$("#ancrecontenu").css({'font-size':"3em"});
		return false;
	})
	
	changerDiaporama();
	
	

})
function changerDiaporama(){
	afficherDiaporama();
	attendre();
}
function arreterDiaporama(){
	drapeau = 0;
	changerimage($(".home .controles .play a img"),"_pause","_play",".png");
}
function lancerDiaporama(){
	drapeau = 1;
	changerimage($(".home .controles .play a img"),"_play","_pause",".png");
	changerDiaporama();
}
function afficherDiaporama(){
	$(".home .rotative .info").each(function(i){
		$(this).stop();
		if(i==diaporamaActif){
			//$(this).animate({opacity:"show"},1000,attendre);
			$(this).show();
			
		}else{
			$(this).hide();
		}
	})
	$(".home .controles ul li").each(function(i){
		if(i==diaporamaActif){
			changerimage($(this).find('img'),"_off","_"+$(this).attr("class"),".png");
		}else{
			changerimage($(this).find('img'),"_"+$(this).attr("class"),"_off",".png");
		}
	})
}
function attendre(){
	 setTimeout(incrementerDiaporama,5000);
}
function incrementerDiaporama(){
	if(drapeau == 1){
		if(diaporamaActif<$(".home .controles ul li").length-1){
			diaporamaActif++;
		}else{
			diaporamaActif =0;
		}
		changerDiaporama();
	}
}
var diaporamaActif = 0;
var drapeau = 1;


function changerimage(element,etatdebut,etatfin,extension){
	var ancienne_source = element.attr("src");
	var verif = ancienne_source.split(etatfin+extension); 
	if(etatfin!="" && verif[0] != ancienne_source) return;
	var off = ancienne_source.split(etatdebut+extension); 
	if(off[0] != ancienne_source){
		element.attr({src: off[0]+etatfin+extension});
		//alert(element.attr("src"));
	}
	
}

/****Manuelle GUSTAVE*/
function ouvrePopup(page,label) //ouvre la popup envoyer Ã  un ami
{ 
		var popHeight = 650;
		var popWidth = 450;
		var posX = (screen.width/2)-(popWidth/2);
		var posY = (screen.height/2)-(popHeight/2);
		
		window.open(page,label,'width='+popWidth+', height='+popHeight+', left='+posX+' ,top='+posY+',resizable=yes');
		
	}

function select_all(id)
{
	var select  = document.getElementById(id);
	var longueur = select.options.length;

	for (i =1 ; i< longueur ; i++)
	{ select.options[i].selected = true;  	}}	


function launchPopin() {
	
	
	jQuery('body').prepend('<div id="content-popin" ><div id="load-popin"><div id="flash-popin"></div></div></div><div id="popin-background"></div>');
	var background = jQuery('#popin-background');
	var content = jQuery('#content-popin');

	var close_popin = '/FRONT/COLAS/images/bt_close.png';
	
	var popin = jQuery('#load-popin');
	var marginLeft = '-'+parseInt(popin.css('width'))/2+'px';
	popin.css('margin-left',marginLeft)
	
	var xH = document.documentElement.scrollHeight+'px';
	background.height(xH);

	//if (close != false) {
		popin.prepend('<a href="#" class="close"><img src="'+close_popin+'" alt="close" /></a>');
	
		//popin.prepend('<iframe class="iframeVideo" src="_blank" width="640" height="100%"></iframe>');
		
		jQuery('.close').click(function(){
			closePopins();
		
		});
		// ferme la fenetre lors de la pression de la touche echap
		if (navigator.appName === "Microsoft Internet Explorer") {
			jQuery('body').keypress( function(evenement) {
				if (evenement.keyCode == 27) {
					closePopins();
				}
			}); // associe la fermeture de la popin sur l'evement echap
		} else {
			jQuery('body').keyup( function(evenement) {
				if (evenement.which == 27) {
					closePopins();
				}
			}); // associe la fermeture de la popin sur l'evement echap
		}
	//}

	return true;
}

function closePopins() {
	
	jQuery('#popin-background').remove();
	jQuery('#content-popin').remove();
}


/* =FLASH_POPIN
---------------------------------------------------------------------------------------*/


var datas = {};
function openPopinFla (itemData){
	
    if (itemData){
    
	if (jQuery('#load-popin').length == 0)	{launchPopin();}

	var popin = jQuery('#load-popin');
		datas = itemData;
		so = new SWFObject("/FRONT/COLAS/swf/loader_initiatives.swf", "flashID", "640", "505", "9", "#000000");
		
	/*	so.useExpressInstall('/FRONT/COLAS/swf/expressinstall.swf');*/
		so.addVariable("confFile", "/FRONT/COLAS/swf/xml/conf_initiatives.xml");
		so.addParam('wmode','transparent');
		
		so.write("flash-popin");
		//return false;
    }else{
        return datas;
    }
    //alert( "URL DU MEDIA : "+itemData.url );
    //alert( "SOUS TITRE DU MEDIA (flv): "+itemData.subtitle );
    //alert( "LEGENDE DU MEDIA : "+itemData.description );
}
/*** GESTION RH*/

function activeFrance()
{
	
	var select = document.getElementById('select_zone');
	
	var longueur=select.options.length;


	var isfrance = false; var checkfrance=false;

	

	for (var i=1;i< longueur;i++)
	{
		
	
		if( select.options[i].value=="france")
		{
			isfrance =true;
			checkfrance = select.options[i].selected;
		}
		
		if(isfrance==true){ select.options[i].selected= checkfrance;}
		
	}	
}

function action_select(id)
{
	switch(document.getElementById(id).value)
	{
		case "-1":  select_all(id);break;
		case "france" : activeFrance();break;
	}
}

/*** GESTION RH*/