// VARIABLES GLOBALES
//detection IE6
var IE6 = false;
var strChUserAgent = navigator.userAgent;
var intSplitStart = strChUserAgent.indexOf("(",0);
var intSplitEnd = strChUserAgent.indexOf(")",0);
var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
//var PopUp = null;
if(strChMid.indexOf("MSIE 6") != -1) IE6 = true;

//Timers
var NouveauteTimerID=0;
var ModuleLudiqueTimerID=0;
var ModuleVoteAlbumTimerID=0;



//tableau Module Ludique pour les titres/liens
var TabModuleLudiqueTitre = new Array();
var TabModuleLudiqueLien = new Array();


//tableau Bio Artiste
var TableauTextePage = new Array();
var IndiceTableauTextePage= 0;




function cache_roll_over(div) {	
	window.document.getElementById(div).style.visibility='hidden';
}


function montre_roll_over(div,num,X,Y) {
	SetLeftTop(div,(window.document.getElementById(num).offsetLeft-X),(window.document.getElementById(num).offsetTop+Y));
	window.document.getElementById(div).style.visibility='visible';
}


function cache_roll_over_skins(div) {	
	window.document.getElementById(div).style.display='none';
}

function montre_roll_over_skins(div,num,X,Y) {
	SetLeftTop(div,(window.document.getElementById(num).offsetLeft-X),(window.document.getElementById(num).offsetTop+Y));
	window.document.getElementById(div).style.display='block';
}



function SetLeftTop(DivId,x,y) {
	try {
	document.getElementById(DivId).style.left = x +"px";
	document.getElementById(DivId).style.top = y +"px";
	}
	catch(e) {}
}

function TimerNouveaute(NomRand,Indice,NbMax,URLSkin) {	
	timespeed=3000;
	for(compteur=1;compteur<=NbMax;compteur++){
		if (Indice==compteur) {
			window.document.getElementById(NomRand+'_contenu_'+compteur).style.visibility='visible';
			if (IE6==true) {				
				PNGswapON(NomRand+'_bouton_'+compteur);
			} else {
				window.document.getElementById(NomRand+'_bouton_'+compteur).src='jazz-en-ligne-interface/'+URLSkin+'images/bouton-rond-jazz-en-ligne-on.png';
			}
			
		} else {
			window.document.getElementById(NomRand+'_contenu_'+compteur).style.visibility='hidden';
			if (IE6==true) {				
				PNGswapOFF(NomRand+'_bouton_'+compteur);
			} else {
				window.document.getElementById(NomRand+'_bouton_'+compteur).src='jazz-en-ligne-interface/'+URLSkin+'images/bouton-rond-jazz-en-ligne-off.png';
			}
		}
	}
	if (Indice==NbMax) { Indice=0}
	NouveauteTimerID=setTimeout("TimerNouveaute("+NomRand+","+(Indice+1)+","+NbMax+",'"+URLSkin+"')",timespeed)	
}



function MontreNouveaute(NomRand,Indice,NbMax,URLSkin) {
	for(compteur=1;compteur<=NbMax;compteur++){
		if (Indice==compteur) {
			window.document.getElementById(NomRand+'_contenu_'+compteur).style.visibility='visible';
			if (IE6==true) {
				PNGswapON(NomRand+'_bouton_'+compteur);
			} else {
				window.document.getElementById(NomRand+'_bouton_'+compteur).src='jazz-en-ligne-interface/'+URLSkin+'images/bouton-rond-jazz-en-ligne-on.png';
			}
			
		} else {
			window.document.getElementById(NomRand+'_contenu_'+compteur).style.visibility='hidden';
			if (IE6==true) {				
				PNGswapOFF(NomRand+'_bouton_'+compteur);
			} else {
				window.document.getElementById(NomRand+'_bouton_'+compteur).src='jazz-en-ligne-interface/'+URLSkin+'images/bouton-rond-jazz-en-ligne-off.png';
			}
		}
	}
	window.clearTimeout(NouveauteTimerID);
}

function AfficheTitrePremierModuleLudique(randomdiv) {
	lien=TabModuleLudiqueLien[0];
	titre=TabModuleLudiqueTitre[0];
	window.document.getElementById("ModuleLudique_"+randomdiv).innerHTML='<span class="titre-chapeau" name="'+titre+'" alt="'+titre+'" title="'+titre+'">'+titre+'</span>';
}



function TimerModuleLudique(NomRand,Indice,NbMax,URLSkin) {	
	timespeed=10000;
	for(compteur=1;compteur<=NbMax;compteur++){
		if (Indice==compteur) {
			window.document.getElementById(NomRand+'_contenu_'+compteur).style.visibility='visible';
			window.document.getElementById('ModuleLudique_'+NomRand).innerHTML='<span class="titre-chapeau" name="'+TabModuleLudiqueTitre[(Indice-1)]+'" alt="'+TabModuleLudiqueTitre[(Indice-1)]+'" title="'+TabModuleLudiqueTitre[(Indice-1)]+'">'+TabModuleLudiqueTitre[(Indice-1)]+'</span>';
			if (IE6==true) {				
				PNGswapON(NomRand+'_bouton_'+compteur);
			} else {
				window.document.getElementById(NomRand+'_bouton_'+compteur).src='jazz-en-ligne-interface/'+URLSkin+'images/bouton-rond-jazz-en-ligne-on.png';
			}
			
		} else {
			window.document.getElementById(NomRand+'_contenu_'+compteur).style.visibility='hidden';
			if (IE6==true) {				
				PNGswapOFF(NomRand+'_bouton_'+compteur);
			} else {
				window.document.getElementById(NomRand+'_bouton_'+compteur).src='jazz-en-ligne-interface/'+URLSkin+'images/bouton-rond-jazz-en-ligne-off.png';
			}
		}
	}
	if (Indice==NbMax) { Indice=0}
	ModuleLudiqueTimerID=setTimeout("TimerModuleLudique("+NomRand+","+(Indice+1)+","+NbMax+",'"+URLSkin+"')",timespeed)	
}



function MontreModuleLudique(NomRand,Indice,NbMax,URLSkin) {
	for(compteur=1;compteur<=NbMax;compteur++){
		if (Indice==compteur) {
			window.document.getElementById(NomRand+'_contenu_'+compteur).style.visibility='visible';
			window.document.getElementById('ModuleLudique_'+NomRand).innerHTML='<span class="titre-chapeau" name="'+TabModuleLudiqueTitre[(Indice-1)]+'" alt="'+TabModuleLudiqueTitre[(Indice-1)]+'" title="'+TabModuleLudiqueTitre[(Indice-1)]+'">'+TabModuleLudiqueTitre[(Indice-1)]+'</span>';
			if (IE6==true) {
				PNGswapON(NomRand+'_bouton_'+compteur);
			} else {
				window.document.getElementById(NomRand+'_bouton_'+compteur).src='jazz-en-ligne-interface/'+URLSkin+'images/bouton-rond-jazz-en-ligne-on.png';
			}			
		} else {
			window.document.getElementById(NomRand+'_contenu_'+compteur).style.visibility='hidden';
			if (IE6==true) {				
				PNGswapOFF(NomRand+'_bouton_'+compteur);
			} else {
				window.document.getElementById(NomRand+'_bouton_'+compteur).src='jazz-en-ligne-interface/'+URLSkin+'images/bouton-rond-jazz-en-ligne-off.png';
			}
		}
	}
	window.clearTimeout(ModuleLudiqueTimerID);
}

function CacherVoteTimer(div) {		
	window.document.getElementById(div).style.display='none';
	ArreterTimerNote()
}


function ArreterTimerNote() {
	try {
		window.clearTimeout(ModuleVoteAlbumTimerID);
	}
	catch (e) {}
}


function CacherVote(div) {
	ModuleVoteAlbumTimerID=setTimeout("CacherVoteTimer('"+div+"')",5000);
}


function MontrerVote(div) {
	window.document.getElementById(div).style.display='block';
}

function OuvertureFermeture(div) {
	MontrerVote(div);
	CacherVote(div);
}

function MontreDiv(div) {
	window.document.getElementById(div).style.display='block';
}

function CacherDiv(div) {
	window.document.getElementById(div).style.display='none';
}

function OuvertureFermeture(div) {
	MontrerVote(div);
	CacherVote(div);
}


function AfficheTableauTextePage (div,sens) {
	var MoinsVisible = false;
	var PlusVisible = false;
	var NbTexte = TableauTextePage.length;
	NbTexte--;
	
	switch (sens) {
		case '+':
			
			if (IndiceTableauTextePage< (NbTexte)){
				window.document.getElementById(div).innerHTML="<span class='textelire'>"+TableauTextePage[++IndiceTableauTextePage]+"</span>";
			}
	
			break;
		case '-':			
			if (IndiceTableauTextePage>0){
				window.document.getElementById(div).innerHTML="<span class='textelire'>"+TableauTextePage[--IndiceTableauTextePage]+"</span>";
			}
			break;
		default: 
			break;
	}

	if (IndiceTableauTextePage==0) {		
		window.document.getElementById("texte-moins-"+div).style.display='none';
	} else {
		window.document.getElementById("texte-moins-"+div).style.display="block";
		MoinsVisible = true;
	}
	if (IndiceTableauTextePage==NbTexte) {
		window.document.getElementById("texte-plus-"+div).style.display='none';
	} else {
		window.document.getElementById("texte-plus-"+div).style.display="block";
		PlusVisible = true;
		
	}
	
	if ((PlusVisible==true) && (MoinsVisible==true)) {
		window.document.getElementById("texte-moins-plus-"+div).style.display="block";
	} else {
		window.document.getElementById("texte-moins-plus-"+div).style.display="none";
	}
	
}


function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }	
	 if (str.indexOf(" ")!=-1){
		return false
	 }
	 return true					
}

function ConfirmEmailOffrirCadeau() {
	if (document.layers){ formulaire = document.forms.offrir;}
	else{formulaire = document.offrir;}
	if (formulaire.EMAIL_CADEAU.value=='' || !echeck(formulaire.EMAIL_CADEAU.value)) {
		alert("L'Email renseigné est invalide");
	} else {
		if (formulaire.EMAIL_CADEAU.value==formulaire.emailvalid.value ) {
			formulaire.submit();
		} else {
			alert('Les emails sont différents');
		}
	}
}

function TestCGV() {
	if (document.layers){ formulaire = document.forms.CGV;}
	else{formulaire = document.CGV;}
	
	if (formulaire.cgv.checked==true) {
		window.location.href = 'panier-paiement-jazz-en-ligne.php?panier=1';
	} else {
		alert('Veuillez accepter les conditions générales de vente avant de valider votre commande');
	}
}




function AffichageRelative(div) {
	etat=window.document.getElementById(div).style.display;
	if (etat=='none') {
		window.document.getElementById(div).style.display="block";
		try {
			eval ('	if (isArray(div)) {	for (i=0;i<'+div+'.length;i++) { MontreRelative('+div+'[i])	} }');
		}
		catch (e) {}
		
	} else {
		window.document.getElementById(div).style.display="none";
		try {
			eval ('	if (isArray(div)) {	for (i=0;i<'+div+'.length;i++) { CacheRelative('+div+'[i])	} }');
		}
		catch (e) {}
	}	
}

function CacheRelative(div) {
	window.document.getElementById(div).style.display="none";
}


function MontreRelative(div) {	
	window.document.getElementById(div).style.display="block";
}

function getSelectedRadio(buttonGroup) {
	for (var i=0; i<buttonGroup.length; i++) {
		if (buttonGroup[i].checked) {
			return i
		}
	}
	return -1;
}


function TestCGV_PM(prix) {
	if (document.layers){ formulaire = document.forms.porte_monnaie;}
	else{formulaire = document.porte_monnaie;}
	if (getSelectedRadio(formulaire.PRIX)==-1) {
		alert('Selectionnez un montant');
		return false;
	} else {
		if (formulaire.cgv.checked==true) {
			return true;
		} else {
			alert('Veuillez accepter les conditions générales de vente avant de valider votre commande');
			return false;
		}
	}
}


function open_PM_popup() {
	if (document.layers){ formulaire = document.forms.porte_monnaie;}
	else{formulaire = document.porte_monnaie;}
	$code_promo='';
	try {
		$code_promo=formulaire.CODE_PROMO.value;
	}
	catch(e) {}	
	$page= 'porte-monnaie-paiement-pop-up-jazz-en-ligne.php?CODE_PROMO='+$code_promo+'&PRIX='+formulaire.PRIX[getSelectedRadio(formulaire.PRIX)].value;
	pmpopup = window.open($page,'PorteMonnaie', 'menubar=no, status=no, scrollbars=no, menubar=no, width=800, height=520');	
}

function SelectRadioPM(Indice) {
	if (document.layers){ formulaire = document.forms.porte_monnaie;}
	else{formulaire = document.porte_monnaie;}	
	
	for (var i=0; i<formulaire.PRIX.length; i++) {
		if (i==Indice) {
		 formulaire.PRIX[i].checked=true;
		} else {
		 formulaire.PRIX[i].checked=false;
		}
	}
}




//var PopUp = null;
var PopUp = null;
var $previousurlpage;
var TimerPassageInfo;
var NbLancement;
NbLancement=0;

function ouvre_player($id,$type,$urlpage) {	
		if(PopUp == null || PopUp.closed) {
			PopUp=open('player-jazz-en-ligne/player-jazz-en-ligne.php','Player', 'menubar=no, status=no, scrollbars=no, menubar=no, width=346, height=340');
			window.PopUp.focus();
		}  else if($previousurlpage != $urlpage) {
			PopUp=open('player-jazz-en-ligne/player-jazz-en-ligne.php','Player', 'menubar=no, status=no, scrollbars=no, menubar=no, width=346, height=340');
			window.PopUp.focus();//
		} else {
			window.PopUp.focus();
		}
		TimerPassageInfo=setTimeout('BalanceInfo("'+$id+'","'+$type+'")',100);
}

function BalanceInfo(ID,TYPE) {
		try {
			PopUp.document.getElementById('player').addSongOrAlbum(ID,TYPE);
		}
		catch(e) {
			TimerPassageInfo=setTimeout('BalanceInfo("'+ID+'","'+TYPE+'")',1000);
		};
}

function BalanceInfoRapide(ID,TYPE) {
		try {
			PopUp.document.getElementById('player').addSongOrAlbum(ID,TYPE);
		}
		catch(e) {
			TimerPassageInfo=setTimeout('BalanceInfoRapide("'+ID+'","'+TYPE+'")',100);
		};
}




function StopTimer() {	
	try {
		window.clearTimeout(TimerPassageInfo);
	}
	catch(e) {};
}


function MetAjourWindow (value) {
	PopUp = value;
}


function sendByMail(id,type) {
	window.blur();
	Modalbox.show('envoie-ami-jazz-en-ligne.php?id_album'+id, {title: '', width: 239});
}



function ouvre_podcast(id) {
	
	open('player-jazz-en-ligne/player-podcast-jazz-en-ligne.php?id='+id,'Player', 'menubar=no, status=no, scrollbars=no, menubar=no, width=346, height=50');
	
}




function Telechargement($ID_Commande,$ID,$Type,$MD5IP,$MD5User,$Cadeaux) {
	var haut=(screen.height-200)/2;
	var Gauche=(screen.width-346)/2;
	try {
		window.open('telechargement-jazz-en-ligne.php?comm='+$ID_Commande+'&id='+$ID+'&type='+$Type+'&param1='+$MD5User+'&param2='+$MD5IP+'&param3='+$Cadeaux,'DL'+99*Math.random(),'top='+haut+',left='+Gauche+'menubar=no,status=no,scrollbars=no,menubar=no,width=340,height=150'); }
	catch (e) {
		window.open('telechargement-jazz-en-ligne.php?comm='+$ID_Commande+'&id='+$ID+'&type='+$Type+'&param1='+$MD5User+'&param2='+$MD5IP+'&param3='+$Cadeaux,'','top='+haut+',left='+Gauche+'menubar=no,status=no,scrollbars=no,menubar=no,width=340,height=150'); }
	
}

//similaire mais ouvre la fenetre pour les DRM
function TelechargementDRM($ID_Commande,$ID,$Type,$MD5IP,$MD5User,$Cadeaux) {
	var haut=(screen.height-200)/2;
	var Gauche=(screen.width-346)/2;
	try {
		window.open('telechargement-drm-jazz-en-ligne.php?comm='+$ID_Commande+'&id='+$ID+'&type='+$Type+'&param1='+$MD5User+'&param2='+$MD5IP+'&param3='+$Cadeaux,'DL'+99*Math.random(),'top='+haut+',left='+Gauche+'menubar=no,status=no,scrollbars=no,menubar=no,width=340,height=150'); }
	catch (e) {
		window.open('telechargement-drm-jazz-en-ligne.php?comm='+$ID_Commande+'&id='+$ID+'&type='+$Type+'&param1='+$MD5User+'&param2='+$MD5IP+'&param3='+$Cadeaux,'','top='+haut+',left='+Gauche+'menubar=no,status=no,scrollbars=no,menubar=no,width=340,height=150'); }
	
}



function authorize(productId) { 
	var url = '/bundle/pos_init?action=authorize&pid=' + productId ;
	window.open(url, 'valista_PaymentPanel');
}


function Incremente(Div) {
	$Nb = parseInt(window.document.getElementById(Div).innerHTML);
	if ($Nb<5) {
		window.document.getElementById(Div).innerHTML=$Nb+1;
		return true;
	} else {
		alert('Nombre de téléchargement maximum autorisé atteint.');
		return false;	
	}
}





function Download($Lien) {
	window.location.replace($Lien);
	setTimeout('Close()',100);	
}

function Close() {
	window.close();	
}


function copy_clip(meintext) {
	if (window.clipboardData) {
		// the IE-manier
		window.clipboardData.setData("Text", meintext);
	}else if (window.netscape) { 
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		var clip = Components.classes['@mozilla.org/widget/clipboard;1']
		.createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1']
		.createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"]
		.createInstance(Components.interfaces.nsISupportsString);
		var copytext=meintext;
		str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid=Components.interfaces.nsIClipboard;
		if (!clip) return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
	return false;
}



function getXMLHTTP(){
	var xhr=null;//firefox
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
		
		// Handling Safari/firefox bug :
		if (xhr.overrideMimeType) {
			xhr.overrideMimeType("text/html");
		//xhr.overrideMimeType("text/xml");
		}
	
	} else {
	
		if (window.ActiveXObject) {
		
			try { // IE IE
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try { // Others IE
					xhr = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					window.alert("Your navigator doesn't handle AJAX, please use Internet explorer, Safari or firefox");
				} // try-catch
			} // try-catch
		
		}
	
	} // if-else
	
	return xhr;
}


function ExecuteAjax(param,page) {
	
	XhrObj = getXMLHTTP();
	
	
	XhrObj.open("POST", page);
	
	
	//Ok pour la page cible
	XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	XhrObj.send(param);
	
	
}



function TagSuggest(param,page,div,Rand) {
	XhrObj = getXMLHTTP();
	
	//définition de l'endroit d'affichage:
	var content = document.getElementById(div);
	
	XhrObj.open("POST", page);
	//Ok pour la page cible
	XhrObj.onreadystatechange = function() {
		if (XhrObj.readyState == 4 && XhrObj.status == 200) {			
			var str = XhrObj.responseText;
			if (str!='') {
				content.style.display='block';
				var chaine=str;
				content.innerHTML=chaine;
				setTimeout("CacheRelative('"+div+"')",10000);
			} else {
				content.style.display='none';
			}
		}
	}
	XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	XhrObj.send(param);
}//fin fonction SendData


function suggestOver(div_value) {
	div_value.className = 'suggest_link_over text-fond-blanc';
}
//Mouse out function
function suggestOut(div_value) {
	div_value.className = 'suggest_link text-fond-blanc';
}

//Click function
function setSearch(value,value2,Rand) {
	eval('document.getElementById(\'ID'+Rand+'\').value = value');
	eval('document.getElementById(\'txtSearch'+Rand+'\').value = value2');
	eval('document.getElementById(\'search_suggest'+Rand+'\').style.display = \'none\'');
	eval('document.getElementById(\'search_suggest'+Rand+'\').innerHTML = \'\'');
}
 
 
 
function sendData(param, page, div) {
	if(document.all) {
		//Internet Explorer
		var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
	} else {
		//Mozilla
		var XhrObj = new XMLHttpRequest();
	}//fin else
	//définition de l'endroit d'affichage:
	var content = document.getElementById(div);
	
	XhrObj.open("POST", page);
	//Ok pour la page cible
	XhrObj.onreadystatechange = function() {
		if (XhrObj.readyState == 4 && XhrObj.status == 200) {
			var Response = XhrObj.responseText ;
			content.innerHTML = Response;
			//execution des scripts de la page appellée
			//permet de refaire de l'Ajax dans la page appellée
			var AllScripts=content.getElementsByTagName("script")
			for (var i=0; i<AllScripts.length; i++) {
				var s=AllScripts[i];
				if (s.src && s.src!="") {
				// Précédement asynchrone, mis en synchrone pour éviter des problèmes de dépendances de scripts
					eval(getFileContent(s.src))
				} else {
					eval(s.innerHTML)
				}
			}
		}
	}
	XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	XhrObj.send(param);
}//fin fonction SendData


function LanceDownload(param, page, div, next) {
	if(document.all) {
		//Internet Explorer
		var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
	} else {
		//Mozilla
		var XhrObj = new XMLHttpRequest();
	}//fin else
	//définition de l'endroit d'affichage:
	var content = document.getElementById(div);
	
	XhrObj.open("POST", page);
	//Ok pour la page cible
	XhrObj.onreadystatechange = function() {
		if (XhrObj.readyState == 4 && XhrObj.status == 200) {
			var Response = XhrObj.responseText ;
			content.innerHTML = Response;
			
			document.location=next;
		}
	}
	XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	XhrObj.send(param);
}