// JavaScript Document

if (!window.mainsite) var mainsite='/';
else mainsite=window.mainsite;

var t="";
var id_courant="";
var mActif="";
var mActif2="";
if(!menuActif) var menuActif=48;
function showsubmenu(id_arbo,obj) {
  if(document.getElementById("submenu"+id_arbo)) {
    if(id_courant==id_arbo) { clearTimeout(t); }
    else if(id_courant!="" && document.getElementById("submenu"+id_arbo)) {
      if (document.getElementById("submenu"+id_courant)) document.getElementById("submenu"+id_courant).style.display="none";
      if(obj != mActif) {
        mActif.className = turnOffButton(mActif.className);
      }
      clearTimeout(t);
    }
    id_courant=id_arbo;
    if(obj) {
      obj.className = turnOnButton(obj.className);
      mActif=obj;
    }
    document.getElementById("submenu"+id_arbo).style.display="block";
    if(document.getElementById("menu_cache")) {
      document.getElementById("menu_cache").setAttribute("onmouseover", "showsubmenu("+id_arbo+")");
      document.getElementById("menu_cache").setAttribute("onmouseout", "hidesubmenu2("+id_arbo+")");
    }
  }
	else{
		if(obj) {
			hidesubmenu(id_courant);
      obj.className = turnOnButton(obj.className);
			mActif2=obj;
     }
	}
}
function onmouseoutmenu(){
  mActif2.className = turnOffButton(mActif2.className);
}
function hidesubmenu(id_arbo) {
  if(document.getElementById("submenu"+id_arbo)) {
    document.getElementById("submenu"+id_arbo).style.display="none";
    mActif.className = turnOffButton(mActif.className);
    activeMenu(menuActif);
  }
}
function hidesubmenu2(id_arbo) {
  clearTimeout(t);
  window.t=setTimeout('hidesubmenu('+id_arbo+')',500);
}
function activeMenu(id_arbo) {
  document.getElementById("menu"+id_arbo).className = turnOnButton(document.getElementById("menu"+id_arbo).className);
  document.getElementById("submenu"+id_arbo).style.display="block";
  id_courant=id_arbo;
  mActif=document.getElementById("menu"+id_arbo);
}
function turnOnButton(classValue) {
  classValue = classValue.split(" ");
  var ext = (classValue.length!=1)?" "+classValue[1]:"";
  if(classValue[0].substr((classValue[0].length-3), 3) != '_on') classValue = classValue[0]+"_on"+ext;
  else classValue = classValue[0]+ext;
  return classValue;
}
function turnOffButton(classValue) {
  classValue = classValue.split(" ");
  var ext = (classValue.length >1)?" "+classValue[1]:"";
  if(classValue[0].substr((classValue[0].length-3), 3) == '_on') classValue = classValue[0].substr(0, (classValue[0].length-3))+ext;
  else classValue = classValue[0]+ext;
  return classValue;
}


function replaceAll(oldStr,findStr,repStr) {
  var srchNdx = 0;
  var newStr = "";
  while (oldStr.indexOf(findStr,srchNdx) != -1)
  {
    newStr += oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));
    newStr += repStr;
    srchNdx = (oldStr.indexOf(findStr,srchNdx) + findStr.length);
  }
  newStr += oldStr.substring(srchNdx,oldStr.length);
  return newStr;
}

function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	var noms = decodeURIComponent(document.cookie.substring(offset, endstr));
	noms=replaceAll(noms, '+', ' ');
	return noms;
}

function GetCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}


function SetCookie(nom, valeur)
{
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

function openArticle1(idArt) {
  idBloc = idArt.substr(0, (idArt.length-1));
  for(i=1; document.getElementById(idBloc+i+"b"); i++)
  {
    itemA = eval(document.getElementById(idBloc+i+"a"));
    itemB = eval(document.getElementById(idBloc+i+"b"));
    if(idBloc+i!=idArt) {
      itemA.className = itemA.className.substr(0, (itemA.className.length-4))+"clos";
      itemB.style.display = 'none';
    }
    else {
      itemA.className = itemA.className.substr(0, (itemA.className.length-4))+"open";
      itemB.style.display = 'block';
    }
  }
}

function openArticle2(idArt) {
  idBloc = idArt.substr(0, (idArt.length-1));
  if (!eval(document.getElementById(idArt+"b"))) return;
  for(i=1; document.getElementById(idBloc+i+"b") || document.getElementById(idBloc+(i+1)+"b"); i++)
  {
    itemA = eval(document.getElementById(idBloc+i+"a"));
    itemB = eval(document.getElementById(idBloc+i+"b"));
    if(idBloc+i!=idArt) {
      if(itemA.className.substr((itemA.className.length-3), 3)=="_on") itemA.className = itemA.className.substr(0, (itemA.className.length-3));
      if(itemB) itemB.style.display = 'none';
    }
    else {
      if(itemA.className.substr((itemA.className.length-3), 3)!="_on") itemA.className = itemA.className+"_on";
      if(itemB) itemB.style.display = 'block';
    }
  }
}

function addArtistLink(aName, linkName) {
  if(document.getElementById('linklist')) {
    document.getElementById('linklist').innerHTML += '<a href="#'+aName+'" class="sp_linkno"><span class="sp_sstitre2">'+linkName+'</span></a>';
  }
}

function addAPIArtistLink(baseLink, aName, linkName) {
  if(document.getElementById('linklist')) {
    document.getElementById('linklist').innerHTML += '<a href="'+baseLink+'#'+aName+'" class="sp_linkno"><span class="sp_sstitre2">'+linkName+'</span></a>';
  }
}

function addArticleLink(aName, linkName, separator) {
  if(document.getElementById('linklist')) {
	if(separator!=undefined){
		document.getElementById('linklist').innerHTML += separator+'<a href="#'+aName+'">'+linkName+'</a>';
	}
	else{
		document.getElementById('linklist').innerHTML += '<a href="#'+aName+'">'+linkName+'</a>';
	}
  }
}

function sendbymail() {
	var div = document.getElementById("envoi");
	if(div.style.display == 'none') div.style.display = "block";
	else div.style.display = "none";

	location.href='#sendfriendform';
}

function sendFriend(){
	var id_article = document.getElementById('sendfriend_id_article').value;
	var url = document.getElementById('sendfriend_url').value;
	var nom = document.getElementById('sendfriend_nom').value;
	var titre = (id_article=="")?document.getElementsByTagName('title')[0].innerHTML:"";
	var from = document.getElementById('sendfriend_from').value;
	var dest = document.getElementById('sendfriend_dest').value;
	var email = document.getElementById('sendfriend_email').value;
	var message = document.getElementById('sendfriend_message').value;
	if ((nom=='')||(nom==null)||(nom==undefined) || (from=='')||(from==null)||(from==undefined)|| (dest=='')||(dest==null)||(dest==undefined)|| (email=='')||(email==null)||(email==undefined)|| (message=='')||(message==null)||(message==undefined))
	{
	alert('Veuillez remplir tous les champs');
	return false;
	}
	else
	{
	if(!req){
		loadXMLDocGeneric('/dynamic/web.php?q=sendfriend&id_article='+encodeURIComponent(id_article)+'&url='+encodeURIComponent(url)+'&nom='+encodeURIComponent(nom)+'&from='+encodeURIComponent(from)+'&dest='+encodeURIComponent(dest)+'&email='+encodeURIComponent(email)+'&message='+encodeURIComponent(message)+'&titre='+encodeURIComponent(titre), 'SendFriend', 'text/html', 'sendfriends_results', 'envoi');
	}
	return true;
	}
}

function blogArtiste(artiste){
	if(!req) loadXMLDocGeneric('/dynamic/blog_artiste.php?type=creation&artiste='+encodeURIComponent(artiste), 'blogArtiste', 'text/html', 'result_artist', '');
}

function blogme(id){
	var div = document.getElementById("bloguer");

	if(div.style.display == 'none') div.style.display = "block";
	else div.style.display = "none";
}

/* AJAX GENERIC */
var req = false;
function loadXMLDocGeneric(url, typeaction, mimetype, cible1, cible2)
{
	if (window.req!=false)
	{
		if (window.req.abort) window.req.abort();
		window.req=null;
		window.req=false;
	}

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		window.req = new XMLHttpRequest();
		if (window.req.overrideMimeType) {
			window.req.overrideMimeType(mimetype);
		}
	} else if (window.ActiveXObject) { // IE
		try {
			window.req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				window.req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!window.req) {
		alert('Abandon :( Impossible de créer une instance XMLHTTP');
		return false;
	}
	
	window.req.onreadystatechange = function() { processReqChangeGeneric(typeaction,cible1,cible2); };
	window.req.open('GET', url, true);
	window.req.send(null);
}

function processReqChangeGeneric(typeaction, cible1, cible2) {
	if (window.req.readyState == 4)
	{
		if (window.req.status == 200)
		{
			if (typeaction=='innerHTML' && document.getElementById(cible1))
			{
				document.getElementById(cible1).innerHTML = req.responseText;
			}
			else if (typeaction=='CommentsIns')
			{
				var tableau = new Array();
				if (document.getElementById(cible1))
				{
					tableau = req.responseText.split(';');
					if (tableau[0]==1){
						document.getElementById(cible2).style.display='none';
					}
					document.getElementById(cible1).innerHTML = tableau[1];
					document.getElementById('commentaire').value = '';
				}
			}
			else if (typeaction=='SendFriend')
			{
				var tableau = new Array();
				if (document.getElementById(cible1))
				{
					tableau = req.responseText.split(';');
					if (tableau[0]==1){
						document.getElementById(cible2).style.display='none';
					}
					document.getElementById(cible1).innerHTML = tableau[1];
				}
			}
			else if (typeaction=='Rating')
			{
				var tableau = new Array();
				if (document.getElementById(cible1) && document.getElementById(cible2))
				{
					tableau = req.responseText.split('|');
					if (tableau[0]=='1'){
						document.getElementById(cible1).innerHTML = tableau[1];
						document.getElementById(cible2).innerHTML = tableau[2];
					}
					else document.getElementById(cible1).innerHTML = tableau[1];
				}
			}
			else if (typeaction=='CommentsIns')
			{
				var tableau = new Array();
				if (document.getElementById(cible1))
				{
					tableau = req.responseText.split(';');
					if (tableau[0]==1){
						document.getElementById(cible2).style.display='none';
					}
					document.getElementById(cible1).innerHTML = tableau[1];
					document.getElementById('commentaire').value = '';
				}
			}
			else if (typeaction=='Alert')
			{
				alert(window.req.responseText);
			}
			else if (typeaction=='Javascript')
			{
				eval(cible1);
			}
			else if(typeaction=='login'){
				var tableau = new Array();
				if (document.getElementById(cible1))
				{
					tableau = req.responseText.split(';');
					if (tableau[0]==0)	document.getElementById(cible1).innerHTML = tableau[1];
					else if (tableau[0]==1)	{
						window.document.location.reload();
					}
				}
			}
			else if(typeaction=='blogArtiste'){
				var result=req.responseText;
				result=replaceAll(result,"<!--BO SEARCH_BY_FIELDS_RESULTS-->\n","");
				result=replaceAll(result,'<!--BO-->',"");
				document.getElementById(cible1).value = result.replace(/^\s+/,"");
				document.getElementById(cible1).select();
				//document.getElementById(cible1).innerHTML = result;
			}
			else if (typeaction=='Hits40Vote')
			{
				var tableau = new Array();
				tableau = req.responseText.split(';');
				if (tableau[0]==1){
					alert(tableau[1]);
					window.document.location.reload();
				}
				else{
					alert(tableau[1]);
				}
			}
      else if(typeaction=='show_likedislike'){
        var result=req.responseText;
        if(result!=0 && result!=",") {
          var result=eval("new Array("+result+")");
        }
        else {
          result=0;
        }

        for(var i=0; i<result.length; i++) {
          var myref = result[i][0];
          var nbyes = parseInt(result[i][1]);
          var nbno = parseInt(result[i][2]);
          var total = nbyes+nbno;
          var plvotes = (total>1)?' votes':' vote';
          var nbvotes = (total>0)?total+plvotes:'Sois le premier à voter !';
          var perc_yes = (total==0)?50:Math.round((nbyes/total)*100);
          var perc_no = (total==0)?50:Math.round((nbno/total)*100);
          var result_pos = (total==0)?50:perc_yes;
          var content = '';
//compter nombre de caractères de la question, agrandir en hauteur
          content += '<a href="javascript:;" onclick="javascript:voteLikeDislike(\'no\',\''+myref+'\');" class="sp_lien_vote sp_lien_vote_non" title="Non">non</a>';
          content += '<span class="sp_titre_vote">'+cible2+'</span>';
          content += '<a href="javascript:;" onclick="javascript:voteLikeDislike(\'yes\',\''+myref+'\');" class="sp_lien_vote sp_lien_vote_oui" title="Oui">oui</a>';
          content += '<span class="sp_txt_pourcentage sp_txt_pourcentage_non" id="no'+myref+'">'+perc_no+'%</span>';
          content += '<div class="sp_degrade_votes">';
          content += '<img src="/images/img_curseur_vote.gif" width="8" height="13" class="curseur_vote" style="left:'+perc_yes+'%; margin-left:-4px" alt="Curseur" id="cursor'+myref+'" />';
          content += '</div>';
          content += '<span class="sp_txt_pourcentage sp_txt_pourcentage_oui" id="yes'+myref+'">'+perc_yes+'%</span>';
          content += '<span class="sp_txt_nb_votes" id="nbvotes'+myref+'">'+nbvotes+'</span>';
          if(document.getElementById(myref)) {
            if(cible2.length>19) document.getElementById(myref).className += ' sp_adjustHeight';
            document.getElementById(myref).innerHTML = content;
          }
        }
      }
			else if(typeaction=='choose_likedislike'){
			  var result=req.responseText;
			  if(result!=0 && result!=",") {
			    var result=eval(result);
			    var nbyes = parseInt(result[1]);
			    var nbno = parseInt(result[2]);
			    var total = nbyes+nbno;
			    var nbvotes = (total>1)?total+' votes':total+' vote';
			    var perc_yes = (total==0)?50:Math.round((nbyes/total)*100);
			    var perc_no = (total==0)?50:Math.round((nbno/total)*100);
			    var result_pos = (total==0)?50:perc_yes;
			
			    document.getElementById('no'+cible1).innerHTML = perc_no+'%';
			    document.getElementById('yes'+cible1).innerHTML = perc_yes+'%';
			    document.getElementById('cursor'+cible1).style.left = perc_yes+'%';
			    document.getElementById('nbvotes'+cible1).innerHTML = nbvotes;
			  }
			}
			else if(typeaction=='show_onair') {
				var result=req.responseText;
				var result = result.split(",");
				var myArtiste = result[0];
				var myTitre = result[1];
				var myCover = result[2];
				document.getElementById(cible1).innerHTML = '<img src="'+myCover+'" width="40" height="40" alt="couverture de '+myTitre+'" class="sp_hOnairImg" /><p class="sp_hOnairText"><b>'+myArtiste+'</b><br />'+myTitre+'</p>';
				window.setTimeout(function(){loadXMLDocGeneric(cible2, 'show_onair', 'text/html', cible1, cible2);},45000);
			}
			else if (typeaction=='innerHTMLReload' && document.getElementById(cible1))
			{
				document.getElementById(cible1).innerHTML = req.responseText;
				timeXml = window.setTimeout(function(){loadXMLDocGeneric(cible2, 'innerHTMLReload', 'text/html', cible1, cible2);},45000);
			}
		}
		else
		{

		}
		window.req.abort();
		window.req=null;
		window.req=false;
	}
}

function eventSearch()
{
	location.href=mainsite+'loisirs/vie-locale/recherche/'+document.getElementById('categorie').value+'/'+document.getElementById('codepostal').value;
	return;
}

function animateurSearch()
{
	var ville=document.getElementById('ville').value;
	ville=replaceAll(ville, '-', '%%');
	ville=replaceAll(ville, ' ', '-');
	ville=replaceAll(ville, '%%', '--');
	location.href=mainsite+'radio/animateurs/recherche/'+ville;
	return;
}
  
var image_curr='';
var tmp_pubPave;
var tmp_pubTop;

function hasloaded(image,wintop,largeur,hauteur){
	
  if(hauteur-image.height>0){
    var posh=wintop+(hauteur-image.height)/2;
  }else{
    var posh=wintop+10;
  }
  if(largeur-image.width>0){
    var posl=(largeur-image.width)/2;
  }
  else{
    var posl=10;
  }
	var img1 = '<img src="/images/shadow.png" border="0" width="10" height="'+image.height+'" class="png" alt="" />';
  var img2 = '<img src="/images/shadow_bottom.png" border="0" width="'+image.width+'" height="10" class="png" alt="" />';
  var img3 = '<img src="/images/shadow_corner.png" border="0" width="10" height="10" class="png" alt="" />';
	if((image_curr!='') && (image_curr!=image.src) && (document.getElementById("fullimage").style.display=="block"))
  {
    /*document.getElementById("fullimage").innerHTML = "";
    document.getElementById("fullimage").style.display = "none";
    document.getElementById("fullimage").style.top = posh+"px";
    document.getElementById("fullimage").style.left = posl+"px";
    document.getElementById("fullimage").innerHTML = "<a href=\"javascript:FullImage('"+image.src+"')\"><img title=\"Fermer\" alt=\"Fermer\" src=\""+image.src+"\" width="+image.width+" height="+image.height+" border=\"0\" /></a>";
    document.getElementById("fullimage").style.display = "block";
    document.getElementById("fullimage").style.zIndex = 101000;*/
		document.getElementById("fullimage").innerHTML = "";
    document.getElementById("fullimage").style.display = "none";
    document.getElementById("fullimage").style.top = posh+"px";
    document.getElementById("fullimage").style.left = posl+"px";
    document.getElementById("fullimage").innerHTML = "<div class=\"dropshadow2\"><div class=\"dropshadow2\"><a href=\"javascript:FullImage('"+image.src+"')\"><img title=\"Fermer\" alt=\"Fermer\" src=\""+image.src+"\" width="+image.width+" height="+image.height+" border=\"0\" /></a>"+img1+"</div>"+img2+""+img3+"</div>";
    document.getElementById("fullimage").style.display = "block";
    document.getElementById("fullimage").style.zIndex = 101000;
		if(document.getElementById("pubPave")){
			tmp_pubPave = document.getElementById("pubPave").innerHTML;
			document.getElementById("pubPave").innerHTML = '<img src="/images/calage.gif" width="300" height="250" alt="pub" border="0">';
		}
		if(document.getElementById("pubTop")){
			tmp_pubTop = document.getElementById("pubTop").innerHTML;
			document.getElementById("pubTop").innerHTML = '<img src="/images/calage.gif" width="728" height="90" alt="pub" border="0">';
		}
  }else if(document.getElementById("fullimage").style.display=="none"){
    /*document.getElementById("fullimage").style.top = posh+"px";
    document.getElementById("fullimage").style.left = posl+"px";
    document.getElementById("fullimage").innerHTML = "<a href=\"javascript:FullImage('"+image.src+"')\"><img title=\"Fermer\" alt=\"Fermer\" src=\""+image.src+"\" width="+image.width+" height="+image.height+" border=\"0\" /></a>";
    document.getElementById("fullimage").style.display = "block";
    document.getElementById("fullimage").style.zIndex = 500000;*/
		document.getElementById("fullimage").style.top = posh+"px";
    document.getElementById("fullimage").style.left = posl+"px";
    document.getElementById("fullimage").innerHTML = "<div class=\"dropshadow2\"><div class=\"dropshadow2\"><a href=\"javascript:FullImage('"+image.src+"')\"><img title=\"Fermer\" alt=\"Fermer\" src=\""+image.src+"\" width="+image.width+" height="+image.height+" border=\"0\" /></a>"+img1+"</div>"+img2+""+img3+"</div>";
    document.getElementById("fullimage").style.display = "block";
    document.getElementById("fullimage").style.zIndex = 500000;
		if(document.getElementById("pubPave")){
			tmp_pubPave = document.getElementById("pubPave").innerHTML;
			document.getElementById("pubPave").innerHTML = '<img src="/images/calage.gif" width="300" height="250" alt="pub" border="0">';
		}
		if(document.getElementById("pubTop")){
			tmp_pubTop = document.getElementById("pubTop").innerHTML;
			document.getElementById("pubTop").innerHTML = '<img src="/images/calage.gif" width="728" height="90" alt="pub" border="0">';
		}
  }else{
    document.getElementById("fullimage").innerHTML = "";
    document.getElementById("fullimage").style.display = "none";
		if(document.getElementById("pubPave")){
			document.getElementById("pubPave").innerHTML = tmp_pubPave;
		}
		if(document.getElementById("pubTop")){
			document.getElementById("pubTop").innerHTML = tmp_pubTop;
		}
  }
  image_curr=image.src;
}

function FullImage(arg){
	var wintop=10;
	if (navigator.appName=='Opera') { //IE5
		var wintop=parseInt(document.body.scrollTop);
		var hauteur=document.body.clientHeight;
		var largeur=document.body.clientWidth;
	}
	else if ((document.getElementById) && (!document.all)) { //NS6
		var wintop=parseInt(window.pageYOffset);
		var hauteur=window.innerHeight;
		var largeur=window.innerWidth;
	}
	else if ((document.getElementById) && (document.all)) { //IE6
		var wintop=parseInt(document.documentElement.scrollTop);
		var hauteur=document.documentElement.clientHeight;
		var largeur=document.documentElement.clientWidth;
	}
	else if (document.getElementById) { //IE5
		var wintop=parseInt(document.body.scrollTop);
		var hauteur=document.body.clientHeight;
		var largeur=document.body.clientWidth;
	}
	var image=new Image;
	image.src=arg;
	if(!image.complete) image.onload = function(){hasloaded(this,wintop,largeur,hauteur)};
	else hasloaded(image,wintop,largeur,hauteur);
}

function popUp(url,largeur,hauteur,scrolling)
{
  window.open(url,'popup','width=' + largeur + ',height=' + hauteur + ',left='+(Math.round((screen.width-largeur)/2))+',top='+(Math.round((screen.height-hauteur)/2))+',scrollbars='+scrolling+',location=no,menubar=no,toolbar=no');	
}

function showDiv(name, count)
{
	var div=document.getElementById(name);
	var tmp=name.split('_');
	if(div.style.display=='none'){
		div.style.display='block';
	}
	else{
		div.style.display='none';
	}
	for(i=1; document.getElementById(tmp[0]+'_'+i) && i<=count; i++)
	{
		if(i!=tmp[1]){
			document.getElementById(tmp[0]+'_'+i).style.display='none';
		}
	}
}

function switchContact() {
	document.forms.contact.destinataire.value = document.getElementById('contact').value;
  document.forms.contact.url.value = window.location.href;
}

function displaydisconnect()
{
	var ident=GetCookie('my_identifiant');
	if (ident!=null && ident!='') document.write('<div style="position:absolute;top:229px;left:720px">'+ident+', <a href="/dynamic/profil.php?q=logout">clique-ici<br>pour te déconnecter</a></div>');
}

function printpage(url) {
	url=url.split('#');
	var w=window.open(url[0].replace('.html', 'p.html'), '_blank');
}

function musicsearch()
{
	var search=document.getElementById('search').value;
	var id_arbo=document.getElementById('id_arbo').value;
	search=replaceAll(search, ' ', '-');
	if (search!='') location.href='/music/search/'+encodeURIComponent(id_arbo)+'/'+encodeURIComponent(search);
	return;
}

function musicthemes()
{
	var theme_name=document.getElementById('theme_name').value;
	theme_name=replaceAll(theme_name, ' ', '-');
	if (theme_name!='') location.href='/music/theme/'+encodeURIComponent(theme_name);
	else location.href='/music/news';
	return;
}

function sallesearch()
{
	var search=document.getElementById('keyword').value;
	if (search!='') location.href='/loisirs/cine/salles?keyword='+encodeURIComponent(search)+'#result_recherche';
	return;
}

function jeusearch()
{
	var search=document.getElementById('tag').value;
	if (search!='') location.href='/loisirs/jeux-videos/fiches/search/'+encodeURIComponent(search);
	return;
}

var radioListeBegin = 0;
function radiosListe(modif, maxElem)
{
  var newStart = radioListeBegin+modif;
  var newEnd = newStart+maxElem;
  if(newStart>=0 && (newStart==0 || newEnd<=liste_radios.length)) {
    var listeRadios = '';
    for(i=newStart; i<newEnd; i++) {
      listeRadios += '<a href="'+liste_radios[i][0]+'"><img src="/commun/n80x60/'+liste_radios[i][1]+'" width="80" height="60" alt="'+liste_radios[i][2]+'" /></a>';
    }
    document.getElementById('radios_scroll').innerHTML = listeRadios;
    radioListeBegin = newStart;
  }
}

function getMachinePicto(comment){
	 if(comment!=''){
		var tmp=comment.split(',');
		for(var i=0;i<tmp.length;i++){
			//document.write( '<'+'img src="/images/jeux_videos/'+tmp[i].toLowerCase()+'.gif" width="42" height="15" border="0" '+'/>');
			document.write( '<'+'strong class="nib_jv_'+tmp[i].toLowerCase()+'"><\/'+'strong>');
		}
	 }
}

function searchByConsole(rubrique)
{
	var console=document.getElementById('console').value;
	location.href=mainsite+'loisirs/jeux-videos/'+rubrique+'/search/'+console+'/a';
	return;
}

var likedilikes = new Array();
function writeLikeDislike(label,letter)
{
  if(likedilikes.length>0) {
    if(!req) loadXMLDocGeneric('/dynamic/web.php?q=show_likedislike&ref='+likedilikes.join(","), 'show_likedislike', 'text/html', '', label);
  //disco=d, articles=a, euro hot 30=e, hits nrj=h
  }
}

function voteLikeDislike(choice,ref)
{
  if(!req) loadXMLDocGeneric('/dynamic/web.php?q=choose_likedislike&ref='+ref+'&choice='+choice, 'choose_likedislike', 'text/html', ref, '');
  else setTimeout("loadXMLDocGeneric('/dynamic/web.php?q=choose_likedislike&ref="+ref+"&choice="+choice+"', 'choose_likedislike', 'text/html', '"+ref+"', '');", 800);
}

function noSpecialChars(mypage) {
 mypage = mypage.toLowerCase();
 mypage = mypage.replace(/[àâä]|(\&agrave\;)|(\&acirc\;)|(\&auml\;)/g, "a");
 mypage = mypage.replace(/[éèêë]|(\&eacute\;)|(\&egrave\;)|(\&ecirc\;)|(\&euml\;)/g, "e");
 mypage = mypage.replace(/[îï]|(\&icirc\;)|(\&iuml\;)/g, "i");
 mypage = mypage.replace(/[ôö]|(\&ocirc\;)|(\&ouml\;)/g, "o");
 mypage = mypage.replace(/[ùûü]|(\&agrave\;)|(\&acirc\;)|(\&auml\;)/g, "u");
 mypage = mypage.replace(/[\s\W]/g, "_");
 return mypage
}

function rating(id_content, val) {
	if(GetCookie('my_vote')!=null){
		var tableau = GetCookie('my_vote').split(';');
		var trouve=false;
		for(var i=0;(!trouve)&&(i<tableau.length);i++){
			if(tableau[i]==id_content)	trouve=true;
		}
		if(trouve)	document.getElementById('content_rating').innerHTML='d&eacute;j&agrave; not&eacute;';
		else loadXMLDocGeneric('/dynamic/web.php?q=rating&id_contenu='+escape(id_content)+'&type=1&rank='+escape(val), 'Rating', 'text/html', 'content_rating', 'content_avg_rating');
	}
	else loadXMLDocGeneric('/dynamic/web.php?q=rating&id_contenu='+escape(id_content)+'&type=1&rank='+escape(val), 'Rating', 'text/html', 'content_rating', 'content_avg_rating');
}

function loadMyPlaylist(){
	if(GetCookie('my_playlist')!=null){
		loadXMLDocGeneric('/dynamic/web.php?q=myplaylist&contenu_ids='+GetCookie('my_playlist'), 'innerHTML', 'text/html', 'my_playlist', '');	
	}
	else loadXMLDocGeneric('/dynamic/web.php?q=myplaylist', 'innerHTML', 'text/html', 'my_playlist', '');	
}

function addMyPlaylist(id){
	date=new Date;
	date.setTime(date.getTime()+(60*60*24*2*1000));
	if(GetCookie('my_playlist')!=null){
		var tab=GetCookie('my_playlist').split(';')
		var trouve=false;
		for(var i=0;(!trouve)&&(i<tab.length);i++){
			if(tab[i]==id)	trouve=true;
		}
		if(trouve==false){
			if(GetCookie('my_playlist')!=''){
				SetCookie('my_playlist', GetCookie('my_playlist')+';'+id, date, "/");
			}
			else{
				SetCookie('my_playlist', id, date, "/");
			}
		}
	}
	else{
		SetCookie('my_playlist', id, date, "/");
	}
	loadXMLDocGeneric('/dynamic/web.php?q=myplaylist&contenu_ids='+GetCookie('my_playlist'), 'innerHTML', 'text/html', 'my_playlist', '');
}

function rmMyPlaylist(id){
	date=new Date;
	date.setTime(date.getTime()+(60*60*24*2*1000));
	if(GetCookie('my_playlist')!=null){
		var tableau = GetCookie('my_playlist').split(';');
		var new_playlist='';
		for(var i=0;i<tableau.length;i++){
			if(tableau[i]!=id){
				if(new_playlist!=''){
					new_playlist+=';'+tableau[i];
				}
				else{
					new_playlist=tableau[i];
				}
			}
		}
		SetCookie('my_playlist', new_playlist, date, "/");
		loadXMLDocGeneric('/dynamic/web.php?q=myplaylist&contenu_ids='+GetCookie('my_playlist'), 'innerHTML', 'text/html', 'my_playlist', '');
	}
}

function base64_encode( data ) {
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i=0, enc='';
 
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);
 
        bits = o1<<16 | o2<<8 | o3;
 
        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;
 
        // use hexets to index into b64, and append result to encoded string
        enc += b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
 
    switch( data.length % 3 ){
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }
 
    return enc;
}

function saveMyPlaylist(){
	if(GetCookie('my_identifiant')!=null){
		if(GetCookie('my_playlist')!=null){
			loadXMLDocGeneric('/dynamic/profil.php?q=saveplaylist&contenu_ids='+GetCookie('my_playlist'), 'innerHTML', 'text/html', 'playlist_msg', '');
		}
	}
	else{
		location.href="/dynamic/profil.php?q=login&destination="+base64_encode(location.href);
	}
}

function loginMyPlaylist(identifiant, password){
	loadXMLDocGeneric('/dynamic/profil.php?q=loginplaylist&identifiant='+escape(identifiant)+'&password='+escape(password), 'login', 'text/html', 'playlist_msg', '');
}

function emissionssearch()
{
	var search=document.getElementById('search').value;
	search=replaceAll(search, ' ', '-');
	if (search!='') location.href='/nrj-tv-on-demand/emissions/search/'+encodeURIComponent(search);
	return;
}

function videoWmp(url,width,height,cible,auto,uimode)
{
	if(!auto || auto=='') var auto=true;
	if(!uimode || uimode=='') var uimode='mini';
	var gNavigator;
	if(-1 != navigator.userAgent.indexOf("MSIE")) {
		gNavigator = "explorer";
	} else if(-1 != navigator.userAgent.indexOf("Firefox")) {
		gNavigator = "firefox";
	} else if(-1 != navigator.userAgent.indexOf("Opera")) {
		gNavigator = "opera";
	} else {
		gNavigator = "other";
	}
	var gSystem;
	if(-1 != navigator.userAgent.indexOf("Windows NT 5.1")) {
		gSystem = "xp";
	} else if(-1 != navigator.userAgent.indexOf("Windows NT 6.0")) {
		gSystem = "vista";
	} else {
		gSystem = "other";
	}

	if (gNavigator == "opera") {
		content='<object id="MediaPlayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="'+width+'" height="'+height+'">';
		content+='<param name="URL" value="'+url+'">';
		content+='<param name="autoStart" value="'+auto+'">';
		content+='<param name="uiMode" value="'+uimode+'">';
		content+='<param name="stretchToFit" value="false">';
		content+='<param name="enableContextMenu" value="true">';
		content+='<embed type="application/x-mplayer2" src="'+url+'" AnimationAtStart="0" enableContextMenu="1" pluginspage="http://www.windowsmedia.com/download/" name="MediaPlayer6" width="'+width+'" height="'+height+'" ShowControls="1" ShowDisplay="0" ShowStatusBar="0" AutoStart="'+auto+'"></embed>';
		content+='</object>';
	} else if(gNavigator == "explorer") {
		content='<OBJECT id="wmp" ';
		content+=' classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"';
		content+=' width="'+width+'" height="'+height+'">';
		content+='<PARAM name="uimode" value="'+uimode+'"/>';
		content+='<PARAM name="url" value="'+url+'" />';
		content+='<PARAM name="autostart" value="'+auto+'" />';
		content+='<param name="stretchToFit" value="true" />';
		content+='</OBJECT>';
	} else if (gSystem == "vista" || gSystem == "xp") {
		content='<OBJECT id="wmp" ';
		content+=' type="application/x-ms-wmp"';
		content+=' width="'+width+'" height="'+height+'">';
		content+='<PARAM name="uimode" value="'+uimode+'"/>';
		content+='<PARAM name="url" value="'+url+'" />';
		content+='<param name="stretchToFit" value="true" />';
		content+='<PARAM name="autostart" value="'+auto+'" />';
		content+='</OBJECT>';
	} else {
		content='<object type="video/x-ms-wmv" data="'+url+'" width="'+width+'" height="'+height+'">';
		content+='<param name="src" value="'+url+'">';
		content+='<param name="uimode" value="'+uimode+'">';
		content+='<param name="autoStart" value="'+auto+'">';
		content+='</object>';
	}
	document.getElementById(cible).innerHTML=content;
}

var promo_date_start;
var promo_date_teasing;
var promo_date_end;
var promo_titre;
var promo_url;
function display_promo(titre, url, date_start, date_end, date_teasing){
	promo_titre=titre;
	promo_url=url;
	var tmp=date_start.split(' ');
	var date=tmp[0].split('-');
	var heure=tmp[1].split(':');
	promo_date_start=new Date(date[0], date[1]-1, date[2], heure[0], heure[1]);

	tmp=date_teasing.split(' ');
	date=tmp[0].split('-');
	heure=tmp[1].split(':');	
	promo_date_teasing=new Date(date[0], date[1]-1, date[2], heure[0], heure[1]);
	
	tmp=date_end.split(' ');
	date=tmp[0].split('-');
	heure=tmp[1].split(':');	
	promo_date_end=new Date(date[0], date[1]-1, date[2], heure[0], heure[1]);
	
	var now=new Date();
	if( promo_date_teasing.getTime()<=now.getTime() && now.getTime()<=(promo_date_end.getTime()+15*60*1000)){
		document.getElementById('nrj_promo_jeux').style.display='block';
		delai();
	}
}

function delai(){
	var now=new Date();	
	var message='';
	if( promo_date_teasing.getTime()<=now.getTime() && now.getTime()<=promo_date_start.getTime() ){	
		var date_jour=new Date();
		var tps=(promo_date_start.getTime()-now.getTime())/1000;
		var j=Math.floor(tps/3600/24); // récupere le nb de jour
		tps=tps % (3600*24);
		var h=Math.floor(tps / 3600); // recupère le nb d'heure
		tps=tps % 3600;
		var m=Math.floor(tps/60); // récupère le nb minute
		tps=tps % 60
		var s=Math.floor(tps);	
		
		var time='';
		if(j>0){
			time+=j+" j ";
		}
		if(h>0){
			time+=h+" h ";
		}
		if(m>0){
			time+=m+" min ";
		}
		if(s>=0 && s<10){
			time+="0"+s+" sec ";
		}
		else{
			time+=s+" sec ";
		}
		message='Il ne reste plus que '+time+' avant que le jeu '+promo_titre+' ne commence.';
	}
	else if( promo_date_start.getTime()<=now.getTime() && now.getTime()<=promo_date_end.getTime() ){
		message='<a href="'+promo_url+'">clique ici pour participer au jeu '+promo_titre+' dépêche-toi il ne reste que peu de temps</a>';
	}	
	else if( promo_date_end.getTime()<=now.getTime() && now.getTime()<=(promo_date_end.getTime()+15*60*1000)){
		message='Le jeu '+promo_titre+' vient de finir';
	}
	else{
		document.getElementById('nrj_promo_jeux').style.display='none';
	}
	document.getElementById('nrj_promo_jeux').innerHTML=message;
	setTimeout("delai()",1000);
}

function refreshPromoJeu(){
	document.getElementById('flashhomepj_main').style.display='none';
}

function cleanCharsXiti(keyword){
  var keyword = keyword;
  keyword = keyword.toLowerCase();
  keyword = keyword.replace(/[àâä]/g, "a");
  keyword = keyword.replace(/[éèêë]/g, "e");
  keyword = keyword.replace(/[îï]/g, "i");
  keyword = keyword.replace(/[ôö]/g, "o");
  keyword = keyword.replace(/[ùûü]/g, "u");
  keyword = keyword.replace(/[\s\W]/g, "_");
  return keyword;
}

/* renvoie un nom de page pour xiti a partir de l'adresse de la page courante */
function pagePartenaire(myHostname, myPathname){
  var page = "";
  myHostname = myHostname.replace(/www\./i, "");
  myHostname = myHostname.replace(/nrj\./i, "");
  myHostname = myHostname.replace(/\.[a-z]+\.[a-z]+/i, "");
  myHostname = myHostname.replace(/\.[a-z]+/i, "");
  myHostname = cleanCharsXiti(myHostname.replace(/\/$/i, ""));
  if(myPathname && myPathname!="" && myPathname!="/"){
    myPathname = myPathname.replace(/\.html/i, "");
    myPathname = myPathname.replace(/\.php/i, "");
    myPathname = cleanCharsXiti(myPathname.replace(/^\//i, ""));
    myPathname = "::"+myPathname.substr(0,40);
  }
  else if(myPathname && myPathname=="/") myPathname="";
  page=myHostname+myPathname;
  return page;
}

function mnauteursearch()
{
	var search=document.getElementById('search').value;
	search=replaceAll(search, ' ', '-');
	if (search!='') location.href='/loisirs/mangas/auteurs/search/'+encodeURIComponent(search);
	return;
}
function load_BySameAuthor(authors, type, exclude_content)
{
	var tmp=authors.split(',');
	if(tmp[0]!=''){
	    search=replaceAll(tmp[0], ' ', '-');
		loadXMLDocGeneric('/dynamic/web.php?q=mn_bysameauthor&type='+type+'&search='+encodeURIComponent(search)+'&exclude_content='+exclude_content, 'innerHTML', 'text/html', 'by_same_author', '');
	}
}
function mnlivressearch(type)
{
	var search=document.getElementById('search').value;
	search=replaceAll(search, ' ', '-');
	if (search!='' && (type=='mangas-bd' || type=='artbooks')) location.href='/loisirs/mangas/livres/'+type+'/search/'+encodeURIComponent(search);
	return;
}

function showMangaPic(obj) {
	if(obj.parentNode.parentNode) obj.parentNode.parentNode.style.backgroundColor = '#efefef';
	if(obj.parentNode.getElementsByTagName('div')[1]) obj.parentNode.getElementsByTagName('div')[1].style.display = 'block';
}
function hideMangaPic(obj) {
	if(obj.parentNode.parentNode) obj.parentNode.parentNode.style.backgroundColor = '#ffffff';
	if(obj.parentNode.getElementsByTagName('div')[1]) obj.parentNode.getElementsByTagName('div')[1].style.display = 'none';
}

function google_ad_request_done(google_ads) {
	/*
	* Cette fonction est requise et est utilisée pour afficher les annonces qui sont renvoyées à partir de la requête
	* JavaScript. Vous devez modifier les commandes document.write en veillant à ce que le code HTML qu'elles copient 
	* soit adapté au format d'annonce de votre choix.
	*/
	var s = '';
	var i;
	
	// Vérifie qu'il existe bien des annonces à afficher.
	if (google_ads.length == 0) {
		return;
	}
	if (google_ads[0].type == "flash") {
		s += '<div><a href=\"' +
		google_info.feedback_url + '\" class="sp_titre6" target="_blank">Annonces Google</a></div>' +
		'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
		' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="' +
		google_ad.image_width + '" HEIGHT="' +
		google_ad.image_height + '"> <PARAM NAME="movie" VALUE="' +
		google_ad.image_url + '">' + '<PARAM NAME="quality" VALUE="high">' +
		'<PARAM NAME="AllowScriptAccess" VALUE="never">' +
		'<EMBED src="' + google_ad.image_url + '" WIDTH="' + google_ad.image_width + '" HEIGHT="' +
		google_ad.image_height + '" TYPE="application/x-shockwave-flash"' +
		' AllowScriptAccess="never" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
	}
	else if (google_ads[0].type == "image") {
		s += '<div><a href=\"' +
		google_info.feedback_url + '\" class="sp_titre6" target="_blank">Annonces Google</a></div><a href="' +
		google_ads[0].url + '" target="_top" title="afficher la page ' +
		google_ads[0].visible_url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'afficher la page ' +
		google_ads[0].visible_url + '\';return true"><img border="0" src="' +
		google_ads[0].image_url + '"width="' +
		google_ads[0].image_width + '"height="' +
		google_ads[0].image_height + '"></a>';
	}
	else if (google_ads[0].type == "html") {
		s += google_ads[0].snippet;
	}
	else {
		if (google_ads.length == 1) {
			s += '<div><a href=\"' +
			google_info.feedback_url + '\" class="sp_titre6" target="_blank">Annonces Google</a></div><div class="sp_googleAd">' +
			'<a style="text-decoration:none" href="' +
			google_ads[0].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'afficher la page ' +
			google_ads[0].visible_url + '\';return true" target="_blank"> <span class="sp_linkGoogle">' +
			google_ads[0].line1 + '<br></span></a> <span style="color:#000000;">' +
			google_ads[0].line2 + '&nbsp;' +
			google_ads[0].line3 + '<br></span> <span><a class="sp_linkno" href="' +
			google_ads[0].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'afficher la page ' +
			google_ads[0].visible_url + '\';return true" target="_blank">' +
			google_ads[0].visible_url + '</span></a><br>';
		}
		else if (google_ads.length > 1) {
			s += '<div><a href=\"' + google_info.feedback_url + '\" class="sp_titre6" target="_blank">Annonces Google</a></div>';

			for(i = 0; i < google_ads.length; ++i) {
				s += '<div class="sp_googleAd"><a style="text-decoration:none" href="' +
				google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'afficher la page ' +
				google_ads[i].visible_url + '\';return true" target="_blank"> <span class="sp_linkGoogle">' +
				google_ads[i].line1 + '<br></span></a> <span style="color:#000000">' +
				google_ads[i].line2 + '<br>' +
				google_ads[i].line3 + '<br></span> <span><a class="sp_linkno" href="' +
				google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'afficher la page ' +
				google_ads[i].visible_url + '\';return true" target="_blank">' +
				google_ads[i].visible_url + '</span></a></div>';
			}
		}
	}
	
	document.getElementById('googleAdsPlace').innerHTML = s;
	return;
}

function hits40_vote(id_titre){
	loadXMLDocGeneric('/dynamic/web.php?q=hits40_vote&id_titre='+id_titre, 'Hits40Vote', 'text/html', '', '');
	/*
	date=new Date;
	date.setTime(date.getTime()+(60*60*12));
	if(GetCookie('my_hits40')!=null){
		var tableau = GetCookie('my_hits40').split(';');
		if(tableau.length>=5){
			alert('Vous ne pouvez plus voter aujourd\'hui.');
		}
		else{
			var trouve=false;
			for(var i=0;i<tableau.length && !trouve;i++){
				if(tableau[i]==id_titre){
					trouve=true;
					alert('Vous avez déjà voté pour ce titre.');
				}
			}
			if(!trouve){
				loadXMLDocGeneric('/dynamic/web.php?q=hits40_vote&id_titre='+id_titre, 'Hits40Vote', 'text/html', '', '');
				SetCookie('my_hits40', GetCookie('my_hits40')+';'+id_titre, date, "/");
			}
		}
	}
	else{
		loadXMLDocGeneric('/dynamic/web.php?q=hits40_vote&id_titre='+id_titre, 'Hits40Vote', 'text/html', '', '');
		SetCookie('my_hits40', id_titre, date, "/");
	}
	*/
}