function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
/*
	Moteur d'affichage du menu ASKIT
*/
function show_hide_menu(obj_, ch_img_) {
	
	obj = document.getElementById("menu_"+obj_);
	arrow = document.getElementById("arrow_"+obj_);
	
	if(obj.style.display == '') {
		obj.style.display = 'none';
		//arrow.className='arrow_off';
		if(ch_img_) arrow.src='../img/arrow.gif';
		
	} else {
		obj.style.display = '';
		//arrow.className='arrow_on';
		if(ch_img_) arrow.src='../img/arrow_on.gif';
		
	}
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Detection du navigateur
nc4 = (document.layers)? true:false;
ie4 = (document.all)? true:false;
nc6 = (typeof(window.controllers) != 'undefined' && typeof(window.locationbar) != 'undefined')? true:false;

// Distance de deplacement a chaque mouvement
var decallage = 3;

// Delai entre chaque mouvement (en millisecondes)
var vitesse = 50;

// Position du defilement :
var posX = 250;
var posY = 50;

// Dimensions du defilement :
var zoneX = 200;
var zoneY = 100;

// Variable qui recevra la continuite du mouvement
var mouvement;

// Variable qui recevra la position la plus haute du calque
var hauteur = 0;

// Fonction generant le mouvement
function defile(sens) {

// Instructions pour Netscape 4.x
	if (nc4) {

// Variable pour manipuler le calque defilant
		calque = 'document.conteneur.document.defilant';

// Calcul de la position la plus haute
		hauteur = -eval(calque + '.document').height + zoneY;
		}

// Instructions equivalentes pour Internet Explorer et Netscape 6 et superieur
	if (ie4) {
		calque = 'defilant.style';
		hauteur = -defilant.offsetHeight + zoneY;
		}
	if (nc6) {
		calque = 'document.getElementById("defilant").style';
		hauteur = -document.getElementById("defilant").offsetHeight + zoneY;
		}

// Si on veut aller vers le haut du contenu
	if ( sens == '+' ) {

// Tant qu'on est pas arrive en haut
		if ( parseInt(eval(calque).top) < 0 ) {

// Deplacement du calque selon le 'pas' specifie
			eval(calque).top = eval(parseInt(eval(calque).top) + sens + decallage);

// Relance selon la vitesse prevue pour creer le defilement
			mouvement = setTimeout("defile('" + sens + "')",vitesse);
			}

// Si on est arrive en haut
		else {

// Arret de la boucle de defilement
			clearTimeout(mouvement);

// Repositionnement precis du calque
			eval(calque).top = 0;
			}
		}

// Instructions equivalentes pour aller vers le bas
	if ( sens == '-' ) {
		if ( parseInt(eval(calque).top) > hauteur ) {
			eval(calque).top = eval(parseInt(eval(calque).top) + sens + decallage);
			mouvement = setTimeout("defile('" + sens + "')",vitesse);
			}
		else {
			clearTimeout(mouvement);
			eval(calque).top = hauteur;
			}
		}

// Si on veut aller tout en haut du contenu
	if ( sens == '++' ) {

// Arret de tout defilement en cours
		clearTimeout(mouvement);

// Positionnement du calque tout en haut
		eval(calque).top = 0;
		}

// Instructions equivalentes pour aller tout en bas
	if ( sens == '--' ) {
		clearTimeout(mouvement);
		eval(calque).top = hauteur;
		}
	}





function my_confirm(text_, url_) {
	rep=confirm(text_);
	if(rep) document.location=url_;
}

/*
	fonction qui permet de gérer l'affichage d'un bloc et sa fermeture
*/

function show_hide(obj_) {
	obj = document.getElementById(obj_);
	
	if(obj.style.display == '') {
		obj.style.display = 'none';
	}
	else {
		obj.style.display = '';
	}
}


/*
	fonction qui permet de fait comme ci-dessus, mais qui ferme l'ancien bloc
*/
var old_open=null;
function show_hide2(obj_) {
	obj = document.getElementById(obj_);
	
	//on ferme l'ancien bloc
	if(old_open) {
		old_open.style.display='none';
	}
	if(document.getElementById('tasse_fumante'))
	{
		document.getElementById('tasse_fumante').style.display='none';
	}
	//on sauvegarde l'objet courant et on affiche
	obj.style.display = '';
	old_open=obj;
	//alert(obj_);
}

// JavaScript Document
function run_flash(url,width,height, wmode)
{
	/*
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="home" align="middle">\n');
	document.write('<param name="movie" value="'+url+'">\n');
	document.write('<embed src="'+url+'" width="'+width+'" height="'+height+'" type="application/x-shockwave-flash">\n');
	document.write('</embed>\n');
	document.write('</object>\n');
*/
	document.write('<object type=\"application/x-shockwave-flash\" data=\"'+url+'" width="'+width+'" height="'+height+'">');
	document.write('<param name="movie" value="'+url+'" />');
	document.write('<param name="wmode" value="'+wmode+'" />');
	document.write('</object>');

}
function run_Videoflash(streamname,width,height) {
	document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"'+width+'\" height=\"'+height+'\" id=\"FLVPlayer\">');
	document.write('  <param name=\"movie\" value=\"FLVPlayer_Progressive.swf\" />');
	document.write('  <param name=\"salign\" value=\"lt\" />');
	document.write('  <param name=\"quality\" value=\"high\" />');
	document.write('  <param name=\"scale\" value=\"noscale\" />');
	document.write('  <param name=\"FlashVars\" value=\"&MM_ComponentVersion=1&skinName=Clear_Skin_3&streamName='+streamname+'&autoPlay=true&autoRewind=false\" />');
	document.write('  <embed src=\"FLVPlayer_Progressive.swf\" flashvars=\"&MM_ComponentVersion=1&skinName=Clear_Skin_3&streamName='+streamname+'&autoPlay=true&autoRewind=false\" quality=\"high\" scale=\"noscale\" width=\"'+width+'\" height=\"'+height+'\" salign=\"LT\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />');
	document.write('</object>');
	
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' doit contenir une adresse email\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' doit contenir un nombre.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' doit contenir un nombre entre '+min+' et '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' est obligatoire.\n'; }
  } if (errors) alert('Les champs suivants sont manquants ou incorrects :\n'+errors);
  document.MM_returnValue = (errors == '');
}

function menu_show(obj_) {
	obj_.style.visibility='visible';
}

function menu_hide(obj_) {
	obj_.style.visibility='hidden';
	window.status="cache";
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


//Anti clic droit
function ejs_nodroit() {
	return(false);
}
document.oncontextmenu = ejs_nodroit;

// JavaScript pris sur le site: "http://www.java.scripts-fr.com"
function thisisbad(e) {
	return false;
}

function bien() {
	return true;
}

//interdiction de la selection
//document.onselectstart=new Function ("return false");

//if (window.sidebar) {
 // document.onmousedown=thisisbad;
 // document.onclick=bien;
//}

function ajout_panier(ref_aticle,qte) {

// Création de l'objet
    XHR = new XHRConnection(ref_aticle);
	XHR.appendData("d_id_produit", ref_aticle);
	XHR.appendData("d_qte", qte);
	XHR.sendAndLoad("../boutique/add_panier.php", "POST", afficherResultats);

}

function control_login() {

// Création de l'objet
    XHR = new XHRConnection("control");
	XHR.sendAndLoad("../boutique/controle_login.php", "GET", afficherResultatsformtotal);

}
function afficherResultatsformtotal(obj) {

	tabResult = obj.responseXML.getElementsByTagName('resultat');	//var
	tabResulttext = obj.responseText;
	
	if (tabResult.length > 0) {
          for (var i = 0; i < tabResult.length; i++) {
               resultat = tabResult.item(i); 
               var texte_titre = resultat.getAttribute('titre');
			}
      } 

	  	  if(texte_titre == "non_enregistre")
	  {
		  document.getElementById('fond_grise_action').style.display='';
		
	  }
	  if(texte_titre == "enregistre")
	  {
			//document.location.href="../boutique/panier.php";
			document.form_commander.submit();
	  }
}


function afficherResultats(obj) {

// Construction des noeuds
tabResult = obj.responseXML.getElementsByTagName('resultat');	//var
tabResulttext = obj.responseText;

	 
//	 document.getElementById('zoneResultats').innerHTML = '';
     if (tabResult.length > 0) {
          for (var i = 0; i < tabResult.length; i++) {
               resultat = tabResult.item(i); 
               var texte_titre = resultat.getAttribute('titre');
			}
      } 

	  if(texte_titre == "non_enregistre")
	  {
		  document.getElementById('fond_grise_action').style.display='';
	  }
	  if(texte_titre == "enregistre")
	  {
			document.location.href="../boutique/panier.php";
	  }
}

function continuer_achat(){

//on regarde si on est dans le grand formulaire
if(document.form_commander)
{
	document.form_commander.submit();
}else
{
	document.location.href="../boutique/panier.php";
}
document.getElementById('fond_grise_action').style.display='none';

}

function ajout_parrainage(from_, to_) {
	// Création de l'objet
    XHR = new XHRConnection(from_);
	XHR.appendData("email_from", from_);
	XHR.appendData("email_to", to_);
	XHR.sendAndLoad("../pages/envoi_parrainage.php", "POST", afficherResultatsparrainage);


}

function afficherResultatsparrainage(obj) {

	// Construction des noeuds
	tabResult = obj.responseXML.getElementsByTagName('resultat');	//var
	//tabResulttext = obj.responseText;
	
		 
	//	 document.getElementById('zoneResultats').innerHTML = '';
     if (tabResult.length > 0) {
          for (var i = 0; i < tabResult.length; i++) {
               resultat = tabResult.item(i); 
               var texte_titre = resultat.getAttribute('titre');
               //debug Cedric
			   //alert(resultat.getAttribute('texte'));
			}
      }
	  
	  if(texte_titre == "probleme_info")
	  {
		  document.getElementById('fond_grise_parrainage').style.display='';
		  document.getElementById('cible_box_parrainage').innerHTML = 'Les informations saisies semblent inexactes.<br>Merci de recommencer votre saisie.';
	  }
	  if(texte_titre == "ok")
	  {
			document.getElementById('fond_grise_parrainage').style.display='';
			document.getElementById('cible_box_parrainage').innerHTML = 'Votre invitation a bien été envoyée à votre "filleul".';
	  }
	  if(texte_titre == "client_inconnu")
	  {
			document.getElementById('fond_grise_parrainage').style.display='';
			document.getElementById('cible_box_parrainage').innerHTML = 'Votre adresse e-mail n\'est pas reconnue.<br>Merci de recommencer votre saisie.<br><br>Si vous n\'êtes encore client, vous pouvez passer votre première commande<br>en <a href=\"../pages/commander-en-ligne.html\">cliquant ici</a>.';
	  }
	  
	  if(texte_titre == "filleul_client")
	  {
			document.getElementById('fond_grise_parrainage').style.display='';
			document.getElementById('cible_box_parrainage').innerHTML = 'Le filleul est déjà client, vous ne pouvez pas le parrainer.';
	  }
	  
	  if(texte_titre == "parrainage_encours")
	  {
			document.getElementById('fond_grise_parrainage').style.display='';
			document.getElementById('cible_box_parrainage').innerHTML = 'Le parrainage avec votre filleul est déjà en cours, celui-ci n\'a pas encore passé sa commande.';
	  }
	  
}

function fermer_box_parrainage() {
	document.getElementById('fond_grise_parrainage').style.display='none';
//document.location.href="../boutique/panier.php";
}

function paiement()
{
	if(document.paiement.cgv.checked  == true)
	{ 	document.paiement.submit(document.paiement.submit); }
	else
	{	msg = "Vous devez accepter les conditions générales de vente."; 
	alert(msg);
	}
}

function check_parrainage() {
	if(document.form_parrainage.condition_parrainage.checked  == true)
	{
		
		if(document.form_parrainage.email_from.value != document.form_parrainage.email_to.value) {
			ajout_parrainage(document.form_parrainage.email_from.value, document.form_parrainage.email_to.value);
		} else {
			msg = "Vous ne pouvez pas vous parrainer vous-même !";
			alert(msg);
		} 
		
	}
	else
	{
		msg = "Vous devez accepter les conditions de parrainage."; 
		alert(msg);
	}
}


function login_box_traitement(email,password) {

// Création de l'objet
    XHR = new XHRConnection(email);
	XHR.appendData("email", email);
	XHR.appendData("password", password);
	XHR.sendAndLoad("../boutique/login_box_traitement.php", "POST", afficherResultatsBoxTraitement);

}

function afficherResultatsBoxTraitement(obj) {
	// Construction des noeuds
	tabResult = obj.responseXML.getElementsByTagName('resultat');

	 if (tabResult.length > 0) {
          for (var i = 0; i < tabResult.length; i++) {
               resultat = tabResult.item(i); 
               var texte_titre = resultat.getAttribute('titre');
			    var texte = resultat.getAttribute('texte');
			}
      }

if(texte_titre == "erreur")
	{
		document.getElementById('tr_box').style.display='';
		document.getElementById('cible_box_login_traitement').innerHTML = 'Les informations que vous avez saisies semblent inexactes ou votre email n\'est pas référencée dans notre base de données.<br>Si vous n\'êtes pas encore client, vous pouvez poursuivre votre commande et vous inscrire en <a href=\'javascript:continuer_achat();\'>cliquant ici</a>.';
	}
	
	if(texte_titre == "OK")
	{
		if(document.form_commander)
		{
			document.getElementById('fond_grise_action').style.display='none';
			document.form_commander.submit();
		}
		else
		{
			document.getElementById('fond_grise_action').style.display='none';
			document.location.href="../boutique/panier.php";
			
		}
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}