var it				= new Array();	// Contient les éléments du menu bandeau
var ft				= new Array();	// Contient les images en rot. du bandeau
var ft2				= new Array();	// Contient les url des images en rot. du bandeau
var rotation_time	= 12000;		// Temps entre chaque rotation (en ms)
var fade_time		= 3500;			// Durée de l'assombrissement (en ms)
var interval		= 55;			// Interval entre chaque assombrissement
var apercu_rot_time	= 2500;			// Temps de rotation des img des apercu
var apercu_timeout;					// Le nom du timeout de repetition d'apercu
var perso_timer;		// Le timer de la rotation d'une perso
var perso_timer2;		// Pour le timeout de n sec apres une demande de perso

var w3c = (document.getElementById)	? true : false;
var ie5 = (w3c && document.all)		? true : false;
var ns4 = (document.layers)			? true : false;
var ns6 = (w3c && !document.all)	? true : false;

var mar, mod; // La liste des marques/modèles dans les .js externes

// Renvoie un tableau contenant tous les élements dont la class a été passée
// en paramètre

function getElementbyClass(classname){
	var class_tab = new Array();
	var inc=0;
	var alltags=document.all? document.all : document.getElementsByTagName("*");
	for (i=0; i<alltags.length; i++){
		if (alltags[i].className==classname)
			class_tab[inc++] = alltags[i];
	}
	return( class_tab );
}

function insertAfter(parent, node, referenceNode) {
	if(referenceNode.nextSibling) {
		parent.insertBefore(node, referenceNode.nextSibling);
	} 
	else {
		parent.appendChild(node);
	}
}


// Fonction à appeler une fois seulement, pour commencer la rotation des images
// du menu déroulant
function rotate_ico(){

	var i;
	var et_nb;
	
	if( it.length == 0 )
		it = getElementbyClass("ico");

	// Nombre total d'étapes
	et_nb = fade_time / interval;
	
	setTimeout( 'fade( -1, '+et_nb+' )',0);

	setTimeout( rotate_ico, rotation_time);

}

// S'occupe de la rotation et de la transparence des images des menu déroulants
function fade( et, et_nb ){
	
	var trans_tot, trans_tem;
	var i, j;
	var path, id;

	// De combien la transparence doit être augmentée/diminuée à cette étape
	trans_tem = 2*(Math.round( 100/et_nb*10)/10);
	
	if( et == -1 )
		et = 0;
	et++;
	
	// Changement de source des images, si on en est à la moitié du chemin
	if( et == Math.round(et_nb/2) ){
		for( i = 0; i < it.length; i++ ){
			if( ft[i].length == 0 )
				continue;
			for( j = 0; j < ft[i].length; j++ ){
				if( it[i].src == getpath(ft[i][j]) ){
					if( j+1 == ft[i].length ){
						it[i].src = getpath(ft[i][0]);
						it[i].parentNode.href=ft2[i][0];
					}
					else{
						it[i].src = getpath(ft[i][j+1]);
						it[i].parentNode.href=ft2[i][j+1];
					}
					break;
				}
			}
			if( j == ft[i].length ){
				it[i].src = getpath(ft[i][0]);
				it[i].parentNode.href=ft2[i][0];
			}
		}
	}
	
	// Calcul de la transparence à appliquer
	// On diminue la trans
	if( et < et_nb/ 2 )
		trans_tot = Math.round(100-et*trans_tem);
	// On augmente la trans */
	else
		trans_tot = Math.round((et-et_nb/2)*trans_tem);
	
	if( trans_tot > 100 )
		trans_tot = 100;
	else if( trans_tot < 10 )
		trans_tot = '0'+trans_tot;


	// On applique la transparence		
	for( i = 0; i < it.length; i++ ){
		it[i].style.MozOpacity	= (trans_tot<100)?"."+trans_tot:"1";
		it[i].style.opacity		= (trans_tot<100)?"."+trans_tot:"1";
		it[i].style.filter		= "alpha(opacity="+(trans_tot)+")";
	}
	
	// Si il reste encore des étapes, on recomence
	if( et < et_nb )
		setTimeout( 'fade('+et+', '+et_nb+')', interval );
}

function getpath( id )
{
	if( id > 99999 )
		return( "http://p.ld"+(id%10)+".fr/t/lst/cmb_"+parseInt(id/10)+".png" );
	else
		return( "http://"+window.location.host+"/temp/lst/cmb_"+id+".png" );
}

// Fonctions de manipulation de cookies
function getCookieVal(offset)
{
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1)
      		endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
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 delCookie( nom )
{
	date=new Date;
	date.setFullYear(date.getFullYear()-10);
	setCookie(nom,null,date);

}

// Vérifie si les cookies sont activés
function CheckCookie() {
	if ( document.cookie ){
		return( true );
	}
	else {
		var cook_temp = document.cookie;
		document.cookie = "essai=cookie";
		if (document.cookie){
			document.cookie = cook_temp;
			return( true );
		}
	}
	return( false );
}


// Récupération du tiket de session, en rajoutant 0 devant pour spécifier
// son non-encodage
var TK = "0"+GetCookie("tk");
var MM = GetCookie("mm");

// Objet HTTPXMLREQUEST. S'utilise comme ceci :
// Création de l'objet :
//		var xmlhttp = getHTTPObject();
// Préparation d'une requête asynchrone de type GET : */
//		xmlhttp.open("GET", "/disp.cgi?param1=abc&param2=def&etc=blabla", true);
//		xmlhttp.send(null);

// On a les propriétés suivantes :
// onreadystatechange	Gestionnaire d'événements pour les changements d'état.
//						Il faut assigner une fonction à cette propriété pour
//						effectuer des traitements sur les données renvoyées
//						après la requête.
// readyState			statut de l'objet.
// responseText			Réponse sous forme de chaîne de caractères.
// responseXML			Réponse sous forme d'objet DOM.
// status				code numérique de réponse du serveur HTTP
// statusText			message accompagnant le code de réponse.

function getHTTPObject()
{
	var xmlhttp = false;
	// Compilation conditionnelle d'IE 
  
	/*@cc_on
	@if (@_jscript_version >= 5)
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try	{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (E){
				xmlhttp = false;
			}
		}
	@else
		xmlhttp = false;
	@end@*/

	/* on essaie de créer l'objet si ce n'est pas déjà fait */
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    	try {
			xmlhttp = new XMLHttpRequest();
		}
		catch (e){
			xmlhttp = false;
		}
	}
	
	return xmlhttp;
}

/* Renvoie un élément objet noeud correspondant à l'événement passé */
function get_element( evt )
{
	var targ;
	if (!evt) var evt = window.event;
	if (evt.target) targ = evt.target;
	else if (evt.srcElement) targ = evt.srcElement;
	if (targ.nodeType == 3) // Safari bug
		targ = targ.parentNode;
	return( targ );
}

function reload_compat( )
{
	var marques, modeles;
	var mar_id, mod_id;
	var url_new;	

	// Le select des modeles n'existe pas ?
	if( !(modeles = document.getElementById("modeles_liste") ) )
		return;
	mod_id = modeles.options[modeles.selectedIndex].value;
	

	// Le select des marques n'existe pas ?
	if( !(marques = document.getElementById("marques_liste") ) )
		return;
	mar_id = marques.options[marques.selectedIndex].value;

	// On définit la bonne url à recharger		
	var url_new;

	if( mot_ori != 0 && document.location.href.indexOf("&rch") <= 0){
		if( CheckCookie() )
			url_new = document.location.href+"&rch="+mot_ori;
		else
			url_new = add_tk(document.location.href+"&rch="+mot_ori);
	}
	else{
		if( CheckCookie() )
			url_new = document.location.href;
		else
			url_new= add_tk(document.location.href);
	}

	url_new = url_new.replace(/&mmc=-?[0-9]+/, "" );

	// Si un modèle correct est sélectionné
	if( parseInt(mod_id) > 0 && parseInt(mar_id) > 0 ){
		// On plante le cookie du modèle
		var date = new Date;
		date.setFullYear(date.getFullYear()+10);
		setCookie("mm", mod_id, date, "/");
		url_new += "&mmc="+mod_id;
	}
	// Si aucune marque sélectionnée
	//else if( parseInt(mod_id) > 0 && parseInt(mar_id) == 0 ){
	else if( parseInt(mar_id) == 0 ){
		// On efface le cookie
		delCookie( "mm" );
		url_new += "&mmc=-1";
	}
	else{
		var msg_comp, msg_conseil;
		// On demande la sélection d'un modèle
		if( (msg_comp = document.getElementById("msg_compat")) )
			msg_comp.innerHTML = "<strong>&gt; Choisissez</strong> le <strong>modèle</strong> de votre mobile.";
		// On enlève le conseil "Utilisez nos suggestions"
		if( (msg_conseil = document.getElementById("conseil")) )
			msg_conseil.innerHTML = "";


		// On plante le cookie de la marque
		var date = new Date;
		date.setFullYear(date.getFullYear()+10);
		setCookie("mm", mar_id, date, "/");
		return;
	}
	

	document.location = url_new;

	return;
}

// Un lien de sonnerie est cliqué
function play_ref( ref )
{
	
	var versions = document.getElementById( "liens_versions" );
	var lien = versions.firstChild;
	while( lien ){
		if( lien.href){
			if( lien.href.indexOf(ref) >= 0 )
				lien.style.fontWeight="bold";
			else
				lien.style.fontWeight="normal";
		}
		lien = lien.nextSibling
	}

	var lecteur_old = document.getElementById("lecteur");
	var lecteur_new = lecteur_old;
	var agt=navigator.userAgent.toLowerCase();
	var is_safari = ((agt.indexOf('safari')!=-1)
		&&(agt.indexOf('mac')!=-1))?true:false;
		
	var source = "/play.cgi?r="+ref;
		//alert( "safari" );

	var w3c = (document.getElementById)	? true : false;
	var ie5 = (w3c && document.all)		? true : false;
	var ns4 = (document.layers)			? true : false;
	var ns6 = (w3c && !document.all)	? true : false;

	if( is_safari ){
		lecteur_old.Stop();
		lecteur_old.SetURL(source);
		lecteur_old.Play();
		//lecteur_old.parentNode.replaceChild(lecteur_new, lecteur_old);
	}
	else if( ie5 ){
		lecteur_old.Stop();
		//alert( lecteur_old.src );
		var phtml = lecteur_old.parentNode.innerHTML;
		var temp = phtml.substring( 0, phtml.indexOf("<EMB") );
		temp += "<EMBED id=lecteur src="+source+" autoplay=true autostart=true type=audio/mpeg enablejavascript=true></EMBED>";
		temp += phtml.substr( phtml.indexOf("</EMBED>")+8 );
		//alert( temp );
		lecteur_old = document.getElementById("lecteur");
		lecteur_old.parentNode.innerHTML =  temp;
		lecteur_old.Play();
	}
	else{
		lecteur_new.src = source;
		lecteur_old.parentNode.replaceChild(lecteur_new, lecteur_old);
		lecteur_old.SetURL(source);
		//lecteur_new.SetURL(source);
		//alert( lecteur_old.length );
	}
	
	// On réécrit la bonne version de la référence pour le SMS
	/*
	var smsref1 = document.getElementById("smsref");
	var a = "a";
	var version = ref.charCodeAt(5) - a.charCodeAt(0);
	var smsref2 = smsref1.innerHTML.substr( 0, 2 ) + parseInt( ref ) + ((version>0)?version:'');
	smsref1.innerHTML = smsref2;
	*/
	
}

function clear_rch( obj ){
	if( obj.value.indexOf("Tapez votre recherche") >= 0 ){
		obj.value = "";
	}
	else if( obj.value.indexOf("uméro") >= 0 ){
		obj.value = "";
	}
}

function check_rch( obj ){
	var rch_txt = document.getElementById( "rch_txt" );
	var rch = document.getElementById( "rch" );
	if( rch_txt.value.indexOf("Tapez votre recherche") == -1 ){
		rch.submit();
	}
	

}
function highlight( id, id_long ){
	var home_bloc;
	
	if( document.getElementById(id) ){
		home_bloc = document.getElementById(id);
		home_bloc.setAttribute("class","home_bloc_selected");
	}
}

function home_clear( id, id_long ){
	var home_bloc;
	if( document.getElementById(id) ){
		home_bloc = document.getElementById(id);
		home_bloc.setAttribute("class","home_bloc");
	}
}

// Rotation des apercu des jeux 
var ap_maxh  = 0;
function rotate_apercu(){

	var img_small	= getElementbyClass( "img_small" );
	var img_big		= getElementbyClass ("img_big");
	var i, j, old, nouv, temp_h;

	// Trouver la plus grande image
	if( ap_maxh == 0 ){
		for( i = 0; i < img_small.length; i++ ){
			// Verif de chargement pour IE
			if ( typeof img_small[i].complete != "undefined" && !img_small[i].complete){
				ap_maxh  = 0;
				return;
			}
			// Verif de chargement dd'image pour Firefox/Safari
			else if (typeof img_small[i].naturalWidth != "undefined" && img_small[i].naturalWidth == 0){
				ap_maxh  = 0;
				return;
			}

			nouv = new Image();
			nouv.src = img_small[i].src;
			if( nouv.height != 0 ){
				if( nouv.height > ap_maxh )
					ap_maxh = nouv.height;
			}
			else{
				if( img_small[i].naturalHeight > ap_maxh )
					ap_maxh = img_small[i].naturalHeight;
			}
			
		}
	}
	
	// Si pas de hauteur maximum, on prend celle de la 1ere image
	if( ap_maxh == 0 ){
		if( img_big[0] && ( img_big[0].height != 0 || img_big[0].naturalHeight != 0 )){
			if( img_big[0].height != 0 ){
				img_big[0].style.height = img_big[0].height+"px";
				img_big[0].style.width = img_big[0].width+"px";
			}
			else if( img_big[0].naturalHeight != 0 ){
				img_big[0].style.height = img_big[0].naturalHeight+"px";
				img_big[0].style.width = img_big[0].naturalWidth+"px";
			}
		}
		else
			return;
	}

	for( i = 0; i < img_small.length; i++ ){
		if( img_big[0] && img_big[0].src == img_small[i].src ){
			nouv = new Image();

			if( i+1 < img_small.length )
				j = i + 1;
			else
				j = 0;

			//img_small[i].style.border = "4px solid #FFFAEB";
			//img_small[j].style.border = "4px solid #00508C";
			img_small[i].id = "";
			img_small[j].id = "selected";

			nouv.src = img_small[j].src;
			if( nouv.height != 0 ){
				// Reglage de la marge sous l'image pour bien mettre à niveau
				if( img_big[0].style.marginBottom == 0 )
					img_big[0].style.marginBottom = "0px";
				temp_h = parseInt(img_big[0].style.marginBottom) + nouv.height;
				if( temp_h < ap_maxh  || temp_h > ap_maxh ){
					img_big[0].style.marginBottom = (ap_maxh-nouv.height+5) + "px";
				}
				else if( parseInt(img_big[0].style.marginBottom) != 5 )
					img_big[0].style.marginBottom = "5px";

			}
			else if( nouv.naturalHeight != 0 ){
				// Reglage de la marge sous l'image pour bien mettre à niveau
				if( img_big[0].style.marginBottom == 0 )
					img_big[0].style.marginBottom = "0px";
				temp_h = parseInt(img_big[0].style.marginBottom) + nouv.naturalHeight;
				if( temp_h < ap_maxh  || temp_h > ap_maxh ){
					img_big[0].style.marginBottom = (ap_maxh-nouv.naturalHeight+5) + "px";
				}
				else if( parseInt(img_big[0].style.marginBottom) != 5 )
					img_big[0].style.marginBottom = "5px";

			}
			img_big[0].src = nouv.src;

			break;
		}
	}
}


function swich( obj )
{
	clearInterval(apercu_timeout);
	apercu_timeout = 0;
	var img_big = getElementbyClass ("img_big");
	var img_small = getElementbyClass ("img_small");
	var i, nouv;
	
	// Trouver la plus grande image
	if( ap_maxh == 0 ){
		for( i = 0; i < img_small.length; i++ ){
			// Verif de chargement pour IE
			if ( typeof img_small[i].complete != "undefined" && !img_small[i].complete){
				ap_maxh  = 0;
				return;
			}
			// Verif de chargement dd'image pour Firefox/Safari
			else if (typeof img_small[i].naturalWidth != "undefined" && img_small[i].naturalWidth == 0){
				ap_maxh  = 0;
				return;
			}
		
			nouv = new Image();
			nouv.src = img_small[i].src;
			if( nouv.height != 0 ){
				if( nouv.height > ap_maxh )
					ap_maxh = nouv.height;
			}
			else{
				if( img_small[i].naturalHeight > ap_maxh )
					ap_maxh = img_small[i].naturalHeight;
			}
		}
	}

	for( i = 0; i < img_small.length; i++ ){
		if( img_small[i] == obj ){
		
			nouv = new Image();
			nouv.src = img_small[i].src;

			// Si pas de hauteur maximum, on prend celle de la 1ere image
			if( ap_maxh == 0 ){
				if( img_big[0] && (img_big[0].height != 0 || img_big[0].naturalHeight != 0) ){
					if( img_big[0].height != 0 ){
						img_big[0].style.height = img_big[0].height+"px";
						img_big[0].style.width = img_big[0].width+"px";
					}
					else if( img_big[0].naturalHeight != 0 ){
						img_big[0].style.height = img_big[0].naturalHeight+"px";
						img_big[0].style.width = img_big[0].naturalWidth+"px";
					}
				}
				else
					return;
			}

			//img_small[i].style.border = "4px solid #00508C";
			img_small[i].id = "selected";

			if( img_big[0] && nouv.height != 0 ){
				// Reglage de la marge sous l'image pour bien mettre à niveau
				if( img_big[0].style.marginBottom == 0 )
					img_big[0].style.marginBottom = "0px";
				temp_h = parseInt(img_big[0].style.marginBottom) + nouv.height;
				if( temp_h < ap_maxh  || temp_h > ap_maxh ){
					img_big[0].style.marginBottom = (ap_maxh-nouv.height+5) + "px";
				}
				else if( parseInt(img_big[0].style.marginBottom) != 5 )
					img_big[0].style.marginBottom = "5px";
			}
			else if( img_big[0] && nouv.naturalHeight != 0 ){
				// Reglage de la marge sous l'image pour bien mettre à niveau
				if( img_big[0].style.marginBottom == 0 )
					img_big[0].style.marginBottom = "0px";
				temp_h = parseInt(img_big[0].style.marginBottom) + nouv.naturalHeight;
				if( temp_h < ap_maxh  || temp_h > ap_maxh ){
					img_big[0].style.marginBottom = (ap_maxh-nouv.naturalHeight+5) + "px";
				}
				else if( parseInt(img_big[0].style.marginBottom) != 5 )
					img_big[0].style.marginBottom = "5px";
			}
		}
		else{
			//img_small[i].style.border = "4px solid #FFFAEB";
			img_small[i].id = "";
		}
	}

	img_big[0].src= obj.src;

}


/***** Fonction d'attente de génération de logo perso *****/
var perso_new;
var perso_encours = -1;
var perso_img_ori = -1;

function get_imgperso( requete, err_vide ){
	var img_big;
	var txt_perso;
	var img_wait = "/img/plzw8.gif";

	perso_new = -1;

	/*** image deja en génération ou pas encore prete ? ***/
	if( perso_encours == 1 ){
		return;
	}

	perso_encours = 1;

	/*** On recup de l'image d'apercu ***/
	if( !(img_big=document.getElementById("img_big")) ){
		return;
	}

	/*** On recup le texte de perso demandé ***/
	if( !(txt_perso=document.getElementById("txt_perso")) ){
		return;
	}	
	if( txt_perso.value.length <= 0 ){
		alert( err_vide );
		return;
	}

	if( perso_img_ori == -1 ){
		perso_img_ori = img_big.src;
	}

	requete += "&txt_perso="+encodeURIComponent(txt_perso.value)+"&TK="+TK;

	/*** Création de la requete : ***/
	var xmlhttp = getHTTPObject();

	//alert( requete );

	/*** Préparation d'une requête asynchrone de type GET : ***/
	xmlhttp.open("GET", requete, true);

	if (xmlhttp){
	
		/* on définit ce qui doit se passer quand le soft répondra */
		xmlhttp.onreadystatechange=function(){
		/* 200 : code HTTP pour OK4 : état "complete" */
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			var reponse;

			reponse = xmlhttp.responseText;

			/* Cas : une url (celle de l'image est renvoyée */
			if( reponse.indexOf("http") == 0 ){
				perso_new = reponse;
			}
			/* Cas : un message d'erreur est renvoyé */
			else{
				alert( "Erreur : '"+reponse+"'" );
				img_big.src = perso_img_ori;
				setTimeout( "perso_timerok()", 1000 );
				clearInterval( perso_timer );
				clearTimeout( perso_timer2 );
			}
		}
		}
	}

	/* Effectue la requête : */
	xmlhttp.send(null);
	
	/* Changement immédiat d'image */
	perso_rotate( perso_img_ori, img_wait, false );
	/* Changement d'image toutes les 1sec */
	perso_timer = setInterval( "perso_rotate('"+perso_img_ori+"', '"+img_wait+"', false )", 800 );

	/* Timeout final, si on a rien reçu au bout de X secondes */
	perso_timer2 = setTimeout( "perso_rotate('"+perso_img_ori+"', '', true )", 30000 );
	
}

function perso_timerok(){
	perso_encours = -1;
	//alert( 'ok');
}

function perso_rotate( img_ori, img_wait, erreur ){
	var img_big;

	/*** On recup de l'image d'apercu ***/
	if( !(img_big=document.getElementById("img_big")) ){
		return;
	}

	if( erreur == true ){
		img_big.src = img_ori;
		clearInterval( perso_timer );
		setTimeout( "perso_timerok()", 1000 );
		alert( 'Une erreur s\'est produite.' );
		return;
	}

	if( perso_new != -1 ){
		img_big.src = perso_new;
		clearInterval( perso_timer );
		clearTimeout( perso_timer2 );
		setTimeout( "perso_timerok()", 1000 );
	}
	else{
		if( img_big.src.indexOf(img_ori) >= 0 ){
			img_big.src = img_wait;
		}
		else{
			img_big.src = img_ori;
		}
	}
}

/*** Affiche les messages d'erreur passés si la marque ou/et modele pas
	selectionnés ***/
function verif_compat(msg_marque, msg_modele, msg_erreur, mm, url){
	var marques, modeles, marque, modele, msg, txt_perso;

	if( marques = document.getElementById("marques_liste") )
		marque = marques.value;
	else
		marque = 0;

	if( modeles = document.getElementById("modeles_liste") )
		modele = modeles.value;
	else
		modele = 0;	

	if( parseInt(marque) == 0 )
		alert( msg_marque );
	else if(parseInt(marque) > 0 && parseInt(modele) == 0 ){
		msg = msg_modele.replace(/{MARQUE}/, marques.options[marques.selectedIndex].text);	
		alert( msg );
	}
	else if(parseInt(marque) > 0 && parseInt(modele) > 0 && url.length <= 0)
		//alert( msg_erreur +'('+parseInt(marque)+'-'+parseInt(modele)+'-'+url.length+')');
		alert( msg_erreur );
	else{
		popup(url);
	}
}


/*** A chaque clic
	- vérifie si les cookies sont activés
	- Si, non, vérifie si c'est un lien qui est cliqué
	- Si oui, ajoute le TK à l'url demandée
***/
// on ajoute le listener à la page
document.onclick = check_cookie_tk;

function check_cookie_tk( evt )
{
	// Les cookies sont activés ?
	if( CheckCookie() )
		return;

	// Ce n'est pas un lien qui est cliqué ?
	var lien;
	var targ = get_element( evt );
	if( targ.tagName.toLowerCase() != "a" ){
		// C'est une image dans un lien ?
		if( targ.parentNode.tagName.toLowerCase() != "a" )
			return;
		lien = targ.parentNode;
	}
	else
		lien = targ;

	// Ca ne pointe pas vers un service exterieur ?
	var ext = new Array(
		"astuces.net",
		"goodgame.fr",
		"gameone.net",
		"goodgame.net" );
	var i;
	for( i = 0; i< ext.length; i++ ){
		if( lien.href.indexOf(ext[i]) >= 0 )
			return;
	}

	// url du lien
	var loc = lien.href;

	//C'est du javascript qui est appelé ? on abandonne
	if( loc.indexOf("javascript") == 0 )
		return;
	
	// Si c'est un lien normal on rajoute juste le TK
	document.location = add_tk( loc );
	
	return false;

}


function add_tk( lien )
{
	if( lien.indexOf("TK=") >= 0 )
		return( lien );

	// le lien n'est pas un .htm ?
	if( lien.indexOf(".htm") == -1 ){
		if( lien.charAt(lien.length-1) == "/" ){
			return( lien+"menu.html&TK="+tk_page );
		}
		else{
			return( lien+"/menu.html&TK="+tk_page );
		}
	}
	// Si c'est un lien normal on rajoute juste le TK
	return( lien+"&TK="+tk_page );

}




// Affiche les marques
function disp_marques( selected, disabled )
{
	var marques, marque, compat_content, lb_mar;
	var i, mar_nb;

	// Nombre de modèles
	if( mar )
		mar_nb = mar.length;
	else{
		setTimeout( disp_marques, 150 );
		return;
	}

	marques = document.createElement("select");
	marques.name = "marque";
	marques.id = "marques_liste";
	marques.onchange = get_modeles;

	// Le premier option vide "MODELE?"
	marque = document.createElement("option");
	marque.innerHTML = "MARQUE?";
	marque.value = "0";
	marques.appendChild(marque);

	for( i = 0; i < mar_nb; i++ ){
		if( parseInt(mar[i][0]) == 0 ){
			marque = document.createElement("option");
			marque.value= "";
			marque.innerHTML = "--------";
			marque.disabled = true;
			marques.appendChild(marque);
		}
		else {
			marque = document.createElement("option");
			temp = mar[i][0]+"0000000";
			marque.value=temp;
			if( parseInt(mar[i][0]) == selected )
				marque.selected = true;
			
			marque.innerHTML = mar[i][1];
			marques.appendChild(marque);
		}
	}

	if( px_srv == "tgv" ){
		if( (lb_mar = document.getElementById("marques_label") ) )
			insertAfter( lb_mar.parentNode, marques, lb_mar );
	}
	else{
		if( (compat = document.getElementById("compat_content") ) ){
			compat.appendChild(marques);
		}
	}

	return true;
}


// Récupère la liste des modèles, la mets dans le tableau mod, puis affichage
function get_modeles()
{
	var marques, i, temp, modeles;
	
	// Le select des marques existe-t-il ?
	if( !(marques = document.getElementById("marques_liste") ) ){
		return;
	}

	// Quelle est la marque utilisée ?
	mar_id = marques.options[marques.selectedIndex].value;

	// Si la marque est nulle, on reset tout
	if( mar_id == 0 ){
		reload_compat();
	}

	// On réinitialise la liste des modèles
	mod = new Array();

	// On récupère la liste des modèles	
	var xmlhttp = getHTTPObject();
	var url = "/js/marques/"+(mar_id/10000000)+".js";
		
	xmlhttp.open("GET", url, true);
	if (xmlhttp){
		xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){ 
			var txt = xmlhttp.responseText;
			var res = txt.match(/\d+,"[^"]+/g);
			if( res ){
				for( i = 0; i < res.length; i++ )
					mod[i] = res[i].split(",\"");
			}
			disp_modeles(0);
		}
		}
	}
	// Effectue la requête :
	xmlhttp.send(null);

	return;
	
}

// Affichage des modèles en fonction de la marque sélectionnée
function disp_modeles( selected )
{
	var marques, marque, modeles, modele, lb_mod;
	var i, temp, mod_nb, mar_id, mar_id2;

	// Nombre de modèles
	if( mod )
		mod_nb = mod.length;
	else{
		setTimeout( disp_modeles, 150 );
		return;
	}

	// Le select des marques existe-il ?
	if( !(marques = document.getElementById("marques_liste") ) )
		return;

	// Quelle est l'ID de la marque sélectionnée ?
	mar_id = marques.options[marques.selectedIndex].value;
	mar_id2 = mar_id/10000000;
	

	// Si le select des modèles existe déjà, on l'enlève
	if( (modeles = document.getElementById("modeles_liste") ) )
		modeles.parentNode.removeChild(modeles);


	// On enlève le conseil "Utilisez nos suggestions"
	if( (msg_conseil = document.getElementById("conseil")) )
		msg_conseil.parentNode.removeChild(msg_conseil );

	// On cree le select qui contiendra les modeles
	modeles = document.createElement("select");
	modeles.setAttribute( "id", "modeles_liste" );
	modeles.setAttribute( "name", "modeles_liste" );
	modeles.onchange = reload_compat;

	// Le premier option vide "MODELE?"
	modele = document.createElement("option");
	modele.innerHTML = "MODÈLE?";
	modele.value = "0";
	modeles.appendChild(modele);

	// Cas particulier TGV
	// On recup le label des modèles pour insérer la liste apres
	if( px_srv == "tgv" ){
		if( (lb_mod = document.getElementById("modele_label")) ){
			lb_mod.style.display="block";
		}
		else{
			alert( lb_mod.id );
			//alert( "Probleme sur la page. Contactez le webmaster." );
			return;
		}
	}

	var is_found = false;

	// On ajoute les options de william
	for( i = 0; i < mod_nb; i++ ){
//		document.body.innerHTML += "val ='"+mod[i][0]+"' et label='"+mod[i][1]+"' et parse ='"+parseInt(mod[i][0])+"'<br/>";
		if( parseInt(mod[i][0]) == 0 ){
			modele = document.createElement("option");
			modele.value= "";
			modele.innerHTML = "----------";
			modele.disabled = true;
			modeles.appendChild(modele);
		}
		else{
			modele = document.createElement("option");
			if( parseInt(mod[i][0]) < 10 )
				temp = mar_id2+"000000"+mod[i][0];
			else if( parseInt(mod[i][0]) < 100 )
				temp = mar_id2+"00000"+mod[i][0];
			else if( parseInt(mod[i][0]) < 1000 )
				temp = mar_id2+"0000"+mod[i][0];
			else if( parseInt(mod[i][0]) < 10000 )
				temp = mar_id2+"000"+mod[i][0];
			else if( parseInt(mod[i][0]) < 100000 )
				temp = mar_id2+"00"+mod[i][0];
			else if( parseInt(mod[i][0]) < 1000000 )
				temp = mar_id2+"0"+mod[i][0];
			else if( parseInt(mod[i][0]) < 10000000 )
				temp = mar_id2+""+mod[i][0];
			else
				temp = mod[i][0];
			modele.value=temp;
			// Ce modele est sélectionné ?
			if( parseInt(temp) == selected && !is_found ){
				modele.selected = true;
				is_found = true;
			}
			modele.innerHTML = mod[i][1];
			modeles.appendChild(modele);
		}
	}

	if( px_srv == "tgv" ){
		insertAfter( lb_mod.parentNode, modeles, lb_mod );
	}
	else
		insertAfter( marques.parentNode, modeles, marques );

	// On demande la sélection d'un modèle s'il faut
	if( (msg_erreur = document.getElementById("msg_compat")) && selected == 0 )
		msg_erreur.innerHTML = msg_mod_err;

	mod = new Array();

	return;

}

var o_s, o_ms;
o_s = 0;
o_ms= 0;
function GetNavProps ( session, s, ms, end ) {
	var i;
	var endpar
	/***** restaurer teps de ref ? *****/
	if( o_s != 0 ) {
		s = o_s;
		ms= o_ms;
	}
	o_s = s;
	o_ms= ms;
	
	if( end )
		endpar = '&end=';
	else
		endpar = '';
	/* Création de la requete : */
	var query = "/nav/nav.cgi?PG_JSCRNAV"+"&TK=0"+session+endpar+"&sec="+s+"&ms="+ms+"&props=";

	if( end ) {
		query += 'ECH:'+screen.height+'|ECW:'+screen.width; 
		query += '|WDH:'+document.documentElement.clientHeight+'|WDW:'+document.documentElement.clientWidth; 
		query += '|WDS:'+document.documentElement.clientHeight*document.documentElement.clientWidth; 
		query += '|RTH:'+parseInt(document.documentElement.clientHeight/document.body.offsetHeight*100+0.5)+'|RTW:'+parseInt(document.documentElement.clientWidth/document.body.offsetWidth*100+0.5); 
		query += '|COK:'+navigator.cookieEnabled;
		query += '|PLG:'
		var l = navigator.plugins.length;
		for( i=0; i < l; i++ ) {
			query += navigator.plugins[i].name;
			if( i != l-1 )
				query +=',';
		}
		query += '|NAV:'+navigator.appName
		query += '|PLT:'+navigator.platform
	}
	var xmlhttp = getHTTPObject();
	if( xmlhttp ) {
		/* true: requete non bloquante asynchrone */
		xmlhttp.open("GET", query, true );
		/* ne pas cacher la requete !!!!!! */
		xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 1980 00:00:00 GMT" );
		/* Effectue la requête : */
		xmlhttp.send(null);
	}
}


function cf_montre(text, mouse_event)
{
	var ie, scroll_x, scroll_y, mouse_x, mouse_y;

	if ( !window.Event ){
		scroll_x = document.documentElement.scrollLeft;
		scroll_y = document.documentElement.scrollTop;
		mouse_x = event.clientX;
		mouse_y = event.clientY;
			}	
	else {
		scroll_x = document.documentElement.scrollLeft;
		scroll_y = document.documentElement.scrollTop;
		mouse_x = mouse_event.clientX;
		mouse_y = mouse_event.clientY;
	}

	document.getElementById( "bulle" ).style.left = mouse_x - 80 + scroll_x + "px";
	document.getElementById( "bulle" ).style.top = mouse_y + 10 + scroll_y + "px";

	document.getElementById( "bulle" ).style.visibility = "visible"; 
	document.getElementById( "bulle" ).innerHTML = text; 

}
 
function cf_cache() {
	document.getElementById( "bulle" ).style.visibility = "hidden"; 
}

function cf_selected_dt( elem, f_lst ){
	pere = elem.parentNode;
	pere.id = 'hm_dt';
}

function cf_unselected_dt( elem ) {
	pere = elem.parentNode;
	pere.id = '';
}

function payment_wait_clean( f_paypal ) {
	var tel, sms, a_vider;
	var pere, wait, courant, p, span, link, br, internet, paypal;
	
	// Init
	tel			= document.getElementById( "moyen_tel" );
	sms			= document.getElementById( "moyen_sms" );
	internet	= document.getElementById( "moyen_internet" );
	paypal		= document.getElementById( "moyen_paypal" );
	
	// On crée le bloc wait...
	if( tel )
		courant	= tel;
	else if( sms )
		courant	= sms;
	pere = courant.parentNode;
	
	// Le wait
	wait = document.createElement( "div" );
	wait.setAttribute( "id", "grand_wait" );
	wait.setAttribute( "class", "moyen" );

	p = document.createElement( "p" );
	p.setAttribute( "id", "wait" );
	wait.appendChild( p );

	span = document.createElement( "span" );
	span.setAttribute( "class", "mode" );
	span.innerHTML = "Veuillez patienter...";
	p.appendChild( span );

	span = document.createElement( "span" );
	if( f_paypal )	
		span.innerHTML = "Votre redirection vers Paypal est en cours";
	else
		span.innerHTML = "Votre redirection vers Internet+ est en cours";
	p.appendChild( span );

	br = document.createElement( "br" );
	p.appendChild( br );
	br = document.createElement( "br" );
	p.appendChild( br );
		
	link = document.createElement( "a" );
	link.setAttribute( "style", "text-decoration: underline" );
	link.setAttribute( "href", "javascript:history.go(0);" );
	link.innerHTML = "Pour annuler et choisir un autre moyen de paiement, cliquez ici";
	p.appendChild( link );

	pere.insertBefore( wait, courant );

	// On retire les blocs SMS, Audiotel, Internet + et Paypal...
	if( tel )
		tel.parentNode.removeChild(tel);
	if( sms )
		sms.parentNode.removeChild(sms);
	if( internet )
		internet.parentNode.removeChild(internet);
	if( paypal )
		paypal.parentNode.removeChild(paypal);	
		

	/*
	pere.appendChild( wait );
	if( f_paypal )
		a_vider	= document.getElementById( "internet" );
	else
		a_vider	= document.getElementById( "paypal" );
	if( a_vider )
		a_vider.parentNode.removeChild(a_vider);

	if( f_paypal )
		a_vider	= document.getElementById( "internet_prix" );
	else
		a_vider	= document.getElementById( "paypal_prix" );
	if( a_vider )
		a_vider.innerHTML="&nbsp;";
	*/

}

function paypal_checkout( ref, ref_pub, ref_volatile, tk ) {
	payment_wait_clean( 1 );

	// On récupère l'url
	var xmlhttp = getHTTPObject();
    var url = "/disp.cgi?PG_JSCRIPT&act=paypal&ref="+ref+"&ref_pub="+ref_pub+"&ref_volatile="+ref_volatile;
    xmlhttp.open("GET", url, true );

	// Callback
    if (xmlhttp){
        xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200 ){
				var urlw = xmlhttp.responseText;
				document.location = urlw;
			}
		}
	}

	// Effectue la requête :
	xmlhttp.send(null);

	return;
}
