/* actions � faire au chargement des pages */
var menuSousThemeAffiche;
var couleurTitre;
var debutNewsTicker;
function onloadFunctions (){
	/* Date - Heure */	
	updateHeure();
	//setTimeout("stopDemain()",9000);
	
	/* Variable initialisation affichage du menu*/
	menuSousThemeAffiche = 0;
	
	/* Variables News Ticker */
	couleurTitre = 0;
	debutNewsTicker = 0;
}
window.onload=onloadFunctions;
window.onunload=function() {
jstoflash('unload');	
}

	
/********************************************************************************************************************/
/* Toutes les pages - barre Radio France */
function openMenu(id) {
	var menuEltA = 'menuEltA'+id;
	var menuSsElt = 'menuSsElt'+id;
	if (document.getElementById(menuSsElt).style.display =="none") {
		document.getElementById(menuSsElt).style.display ="block";
		document.getElementById(menuEltA).className="menuEltOpened";
	}
	else {
		document.getElementById(menuSsElt).style.display ="none";
		document.getElementById(menuEltA).className="";
	}
}
	
function openMenuBarre(menu) {
	var menuElt = 'menu'+menu;
	var menuSsElt = 'ssMenu'+menu;
	var imgElt = 'imgMenu'+menu;
	var imgOverElt = 'imgMenu'+menu+'Over';

	var menuSsEltDisplay = document.getElementById(menuSsElt).style.display;
	if(menuSsEltDisplay =="none") {
		document.getElementById(menuElt).style.backgroundColor  ="#7f7f7f";
		document.getElementById(menuSsElt).style.display ="block";
		document.getElementById(imgElt).style.display ="none";
		document.getElementById(imgOverElt).style.display ="block";
	}
	else {
		document.getElementById(menuElt).style.backgroundColor  ="#d0d0d0";
		document.getElementById(menuSsElt).style.display ="none";
		document.getElementById(imgElt).style.display ="block";
		document.getElementById(imgOverElt).style.display ="none";
	}
}
	
	
/********************************************************************************************************************/
/* Home - Fonctions bloc aujourd'hui - demain */
// Variables
var timeout;
var scrolling = 0;


function stopDemain () {
	if (document.getElementById("dep2")) document.getElementById("dep2").stop();
}
// FONCTION POUR SCROLLER VERS LE HAUT
function scrollToTop(longScroll, id) {
	if (longScroll == true) {
		document.getElementById("dep"+id).stop();
		document.getElementById("dep"+id).direction='up';
		document.getElementById("dep"+id).start();
	} else {
		document.getElementById("dep"+id).stop();
		if(id==1){
			document.getElementById("dep"+id).direction='up';
			document.getElementById("dep"+id).start();
		}
	}
}

// FONCTION POUR SCROLLER VERS LE BAS
function scrollBottom(longScroll, id) {
	if (longScroll == true) {
		document.getElementById("dep"+id).stop();
		document.getElementById("dep"+id).direction='down';
		document.getElementById("dep"+id).start();
	} else {
		document.getElementById("dep"+id).stop();
		document.getElementById("dep"+id).direction='up';
		document.getElementById("dep"+id).start();
	}
}

// GESTION DES EVENEMENTS SOURIS
function scroll(id) {
	
	if (document.getElementById("up"+id)) {
		document.getElementById("up"+id).onmouseover = function() {scrollToTop(true, id);};
		document.getElementById("up"+id).onmouseout = function() {scrollToTop(false, id); clearTimeout(timeout);};
	}

	if (document.getElementById("down"+id)) {
		document.getElementById("down"+id).onmouseover = function() {scrollBottom(true, id);};
		document.getElementById("down"+id).onmouseout = function() {scrollBottom(false, id); clearTimeout(timeout);};
	}
}

/********************************************************************************************************************/
/* Toutes les pages - affichage menu sous-th�mes */

function afficheMenuSousTheme(sousThemeId) {
	document.getElementById('menuSousTheme'+menuSousThemeAffiche).style.display='none';
	document.getElementById('menuSousTheme'+sousThemeId).style.display='block';
	menuSousThemeAffiche = sousThemeId;
}


/********************************************************************************************************************/
/* Toutes les pages - News Tickers */


/*
function fadeInText(paragraphId, couleur){ 
	document.getElementById(paragraphId).style.display="block";
	if(couleur<255) { //If color is not white yet
		couleur+=11; // increase color darkness
		document.getElementById(paragraphId).style.color="rgb("+couleur+","+couleur+","+couleur+")";
		setTimeout("fadeInText('"+paragraphId+"', "+couleur+")",10); 
	}
	else couleur=0; //reset couleurTitre value
}

function printParagraph(i, nb) {
	if(i>0) {
		debutNewsTicker=1;
		document.getElementById("sampleTheme"+(i-1)).style.display="none";
		document.getElementById("sample"+(i-1)).style.display="none";//fadeOutText("sample"+(i-1));
	} else {
		if(debutNewsTicker==1) {
			document.getElementById("sampleTheme"+(nb-1)).style.display="none";
			document.getElementById("sample"+(nb-1)).style.display="none";
		}
	}
	document.getElementById("sampleTheme"+i).style.display="block";
	fadeInText("sample"+i, 0);
	if(i<nb-1) i++;
	else i=0;
	//alert(i);
	setTimeout("printParagraph("+i+","+nb+")",5000); 
	
}

function initNewsTickers (nbNews){
	for(j=0;j<nbNews;j++) {
		document.getElementById("sample"+j).style.color="rgb(0,0,0)";
		document.getElementById("sample"+j).style.display="none";
		document.getElementById("sampleTheme"+j).style.display="none";
	}
	printParagraph(0, nbNews);
}*/

function fadeInText(paragraphId, couleur){ 
	//document.getElementById(paragraphId).style.display="block";
	if(couleur<255) { //If color is not white yet
		couleur+=11; // increase color darkness
		document.getElementById(paragraphId).style.color="rgb("+couleur+","+couleur+","+couleur+")";
		setTimeout("fadeInText('"+paragraphId+"', "+couleur+")",10); 
	}
	else couleur=0; //reset couleurTitre value
}
function printParagraph(i, nb) {
	document.getElementById("sampleTheme").innerHTML=theme[i];
	document.getElementById("sample").innerHTML=titre[i];

	fadeInText("sample"+i, 0);
	//document.getElementById("close").innerHTML="sample"+i;
	if(i<nb-1) i++;
	else i=0;
	//alert(i);
	setTimeout("printParagraph("+i+","+nb+")",5000); 
	
}

function initNewsTickers (nbNews){
	document.getElementById("sample0").style.color="rgb(0,0,0)";
	
	printParagraph(0, nbNews);
}

/********************************************************************************************************************/
/* Toutes les pages - Player */
// script pour r�cuperer les variables en javascript; peut �tre supprim� si c'est un fichier php
var req = window.location.search.substr(1,window.location.search.length);
var dbl = req.split('&');
var aPrm = new Array();
var aVal = new Array();
var objQS = new Object();
for (i=0;i < dbl.length;i++) {
   aPrm[i+1] = dbl[i].substring(0,dbl[i].indexOf('='));
   aVal[i+1] = unescape(dbl[i].substring(dbl[i].indexOf('=')+1,dbl[i].length));
   objQS[aPrm[i+1]] = aVal[i+1];
}
function getQueryStringByName(pname){
  return eval("objQS." + pname);
}
varLang=getQueryStringByName("lang");
id=getQueryStringByName("id");




/** popit**/

function pop_it(url,w,h) {
var newwindow4=window.open(url,'France Info - popup','width='+w+', height='+h+',resizable=yes,scrollbars=yes,menubar=yes');	
newwindow4.focus();	
}	


/* fonction de control t�moignages */

function ValidateForm(){

// je verifie que le titre existe et qu'il est bien renseigne
if($("#titre").size()==1){
	if($("#titre").val().length==0){
		alert("Vous n'avez pas saisi de titre");
		return false;
	}
}

var f=document.forms['formulaire_temoignage']; 

var n_oblig = new Array ('Auteur','Email');

var oblig = new Array('auteur','email_auteur');

var message = ""; var ret=true;

	for (var i=0; i<oblig.length;i++) {
	var e = 	f.elements[oblig[i]];		

		if (e) {
			/*if (e.type == 'select') {		
				if (e.options[e.selectedIndex].value == "") {
				message += '\t- '+n_oblig[i]+'\n';
				}		
			}*/	
			if (e.name == 'auteur' && (e.value == "")) { message += '<b>Vous devez remplir le champ Auteur.</b><br/><br/>' }
			if (e.name == 'email_auteur' && ! echeck(e.value) ){	
			/*alert ('Votre adresse e-mail est incorrecte.');*/
			message += '<b>Merci d\'indiquer un e-mail valide si vous souhaitez que France Info puisse vous recontacter suite &agrave; votre t&eacute;moignage.</b>'	
			}	
			
			if (e.value == "") {
			message += ' \n';
			}
		}	
		else {	
		message += ' \n';
		}

	}
	
	if (message!="") {
	
	document.getElementById("zone_erreur").innerHTML=message
	ret = false;
	}

return ret;
}

function echeck(str) { 
var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/;

return str.match(reg);
}


/** afp & sport show **/

function afp_show() {

	if (document.getElementById('afp')) {
	var afp = document.getElementById('afp');
	var sport = document.getElementById('sport');
	afp.style.display='block';
	afp.style.visibility='visible';	
	sport.style.visibility='hidden';
	sport.style.display='none';
	}
}

function sport_show() {

	if (document.getElementById('sport')) {
	var sport = document.getElementById('sport');
	var afp = document.getElementById('afp');
	sport.style.display='block';
	sport.style.visibility='visible';	
	afp.style.visibility='hidden';
	afp.style.display='none';
	}
}

function ouvrirDepeche(id){
	if(document.getElementById('depeche'+id).style.display=='block')
		document.getElementById('depeche'+id).style.display='none';
	else 
		document.getElementById('depeche'+id).style.display='block';
}


/** horraire modif fi **/

function afficheId(baliseId,nb) {
var horaireH="horaire"+baliseId;
var horaireC;
	
	if (document.getElementById && document.getElementById(horaireH) != null) {
	    document.getElementById(horaireH).style.visibility='visible';
    	document.getElementById(horaireH).style.display='block';
	}
		
	for(var i=1;i<=nb;i++) { 
		horaireC="horaire"+i;
		if (i!=baliseId){
			 if (document.getElementById(horaireC)){
			document.getElementById(horaireC).style.visibility='hidden';
			document.getElementById(horaireC).style.display='none';
			}
		}
	}
}

/** fonction  pour afficher ou non un �l�ment html en fonction de son id */

function openElementId (id) {
	if(document.getElementById(id).style.display=='block')
		document.getElementById(id).style.display='none';
	else
		document.getElementById(id).style.display='block';
}

/** show tems **/

function do_tems_show(){
var i=6;
if (document.getElementById('tems_show6')){
	
	while (document.getElementById('tems_show'+i)){
	
	var tems_show = document.getElementById('tems_show'+i);
	tems_show.style.display='block';
	tems_show.style.visibility='visible';
	i++;
	}
}
var last_item = document.getElementById('lastitem');
	last_item.style.display='none';
}

function show_hide_post(id_forum) {
var post = document.getElementById('post_'+id_forum);
var post_court = document.getElementById('post_court_'+id_forum);

	if (post_court) {
	var disp = ( post_court.style.display == '' || post_court.style.display == 'block' ? 'none' : 'block');
	
	post_court.style.display = disp;
	post.style.display = (disp == 'none' ? 'block' : 'none');
	}
}


// Fonction qui permet de deplier-replier dans le tutto
// podcast une petite zone de div pour recuperer les liens
function lien_rss(cet){
	a = $(cet).parent().parent("li").children(".lien_rss").css("display");
	if (a=="block"){
		$(cet).parent().parent("li").children(".lien_rss").css("display","none");
		$(cet).parent().parent("li").find('.le_lien').css('display','none')
	}else{
		$(cet).parent().parent("li").children(".lien_rss").css("display","block");
		$(cet).parent().parent("li").children(".lien_rss").children(".le_lien").css("display","block");
	}
}

function mvt_chro(cet){
		
		if ($(cet).parent("li").find(".titre_chro").css("display") == "none"){
			$(cet).parent("li").children().slideDown("fast");

			$(cet).parent("li").children(".lien_rss").hide();
			$(cet).css("background","url(imgs/picto/picto_pod_open.jpg) no-repeat")
		}else{
			$(cet).parent("li").css("padding-bottom","0px");
			$(cet).css("background","url(imgs/picto/picto_pod_close.jpg) no-repeat")
			$(cet).parent("li").children().hide();
			$(cet).show();
		}
}


function mvt_chro2(cet2){
		if ($(cet2).parent(".deplier_chro").find(".titre_chro").css("display") == "none"){
			$(cet2).parent(".deplier_chro").children().slideDown("fast");
			$(cet2).parent(".deplier_chro").children(".lien_rss").hide();
			$(cet2).css("background","url(imgs/picto/picto_pod_open-bouquet.jpg) no-repeat")
		}else{
			$(cet2).parent(".deplier_chro").css("padding-bottom","0px");
			$(cet2).css("background","url(imgs/picto/picto_pod_close-bouquet.jpg) no-repeat")
			$(cet2).parent(".deplier_chro").children().hide();
			$(cet2).show();
		}
}

// Fonction pour bookmarker une page
function bookmarksite(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

// gestion de l'animation du menu FI

$(function(){
$(".menu ul li a").hover(function(){
   $(this).parent().parent().find("ul").css('display','none');
   $(this).next("ul").css('display','block');
 },function(){});
 $("#menuInfo .menu").hover(function(){},function(){
	$(this).find("ul ul").css('display','none');
	$(this).find(".actif ul").css('display','block');
   });
 });	
 
 
// menu actif ou pas 

// http://url.info.pix-l.eu:82/sport-autres-2008-05-27-Euro-2008-82849-27-28.html?var_mode=recalcul
function set_menu_actif(){
	a = location.href+"";
	a = a.split("-");
	rub = a[a.length-1].split(".")[0];
	sec = a[a.length-2];
	$("#id_rub_"+rub).addClass('actif');
	$(".menu_theme_"+sec).addClass('actif');
}


/* target _blank */

$(function(){
$(".pdf").attr("target","_blank");
$(".spip_out").attr("target","_blank");
$(".spip_out").each(function(){

  title =  " (nouvelle fenêtre)";
  if($(this).attr("title")) title = $(this).attr("title") + " (nouvelle fenêtre)";
 $(this).attr("title",title);
})

})

 	