// JavaScript Document

function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

// Fonction d'affichage du div Article ajouté
function afficherConfirmationPanier(calque)
	{
	if(document.getElementById(calque) != undefined) {
		var sfEls = document.getElementById(calque);
		sfEls.style.display='block';
	}
	}
function masquerConfirmationPanier(calque)
	{
	var sfEls = document.getElementById(calque);
	sfEls.style.display='none';
	}


function cacherDiv(div)
	{
	obj = document.getElementById(div);
	obj.style.display='none'; 
	}
	
function afficherDiv(div)
	{
	obj = document.getElementById(div);
	obj.style.display='block'; 
	}

function ajouterQuantite(ID_article)
	{
	q = findObj("article[" + ID_article + "][quantite]");
	q.value++;
	}

function retirerQuantite(ID_article)
	{
	q = findObj("article[" + ID_article + "][quantite]");
	if (q.value>0)
		{ q.value--; }
	}

function ajouterPanier(ID_article)
	{
	window.document.forms['commander'].ID_article.value = ID_article; 
	window.document.forms['commander'].submit();
	}

/****************************************************************************/
/* FONCTIONS RELATIVES A LA PAGE ADRESSE DE LA BOUTIQUE 					*/
/****************************************************************************/

function dupliquerCoordonnees()
	{
	// Duplication des infos Facturation vers infos Livraison
	document.formulaireCommander.nomLivraison.value=document.formulaireCommander.nomFacturation.value;
	document.formulaireCommander.prenomLivraison.value=document.formulaireCommander.prenomFacturation.value;
	document.formulaireCommander.adresseLivraison.value=document.formulaireCommander.adresseFacturation.value;
	document.formulaireCommander.adresseLivraison2.value=document.formulaireCommander.adresseFacturation2.value;
	document.formulaireCommander.codePostalLivraison.value=document.formulaireCommander.codePostalFacturation.value;
	document.formulaireCommander.villeLivraison.value=document.formulaireCommander.villeFacturation.value;
	document.formulaireCommander.telLivraison.value=document.formulaireCommander.telFacturation.value;
	}

function affecterDonneesLivraison(ID_clientLivraison)
	{
	if (ID_clientLivraison!=0)
		{		
		document.formulaireCommander.nomLivraison.value=eval('document.formulaireCommander.nomLivraisonClient_'+ID_clientLivraison+'.value');
		document.formulaireCommander.prenomLivraison.value=eval('document.formulaireCommander.prenomLivraisonClient_'+ID_clientLivraison+'.value');
		document.formulaireCommander.adresseLivraison.value=eval('document.formulaireCommander.adresseLivraisonClient_'+ID_clientLivraison+'.value');
		document.formulaireCommander.adresseLivraison2.value=eval('document.formulaireCommander.adresseLivraison2Client_'+ID_clientLivraison+'.value');
		document.formulaireCommander.codePostalLivraison.value=eval('document.formulaireCommander.codePostalLivraisonClient_'+ID_clientLivraison+'.value');
		document.formulaireCommander.villeLivraison.value=eval('document.formulaireCommander.villeLivraisonClient_'+ID_clientLivraison+'.value');
		document.formulaireCommander.telLivraison.value=eval('document.formulaireCommander.telLivraisonClient_'+ID_clientLivraison+'.value');
		
		for (var i=0; i<document.formulaireCommander.ID_pays.length; i++) 
			{ 
			if (document.formulaireCommander.ID_pays.options[i].value == eval('document.formulaireCommander.ID_paysClient_'+ID_clientLivraison+'.value'))
					{ document.formulaireCommander.ID_pays.options.selectedIndex=i }   
			} // FIN for (var i=0; i<document.formulaireCommander.ID_pays.length; i++) 
		} // FIN if (ID_clientLivraison!=0)
	else
		{
		document.formulaireCommander.nomLivraison.value='';
		document.formulaireCommander.prenomLivraison.value='';
		document.formulaireCommander.adresseLivraison.value='';
		document.formulaireCommander.adresseLivraison2.value='';
		document.formulaireCommander.codePostalLivraison.value='';
		document.formulaireCommander.villeLivraison.value='';
		document.formulaireCommander.telLivraison.value='';
		document.formulaireCommander.messageLivraison.value='';
		document.formulaireCommander.message.value='';
		}
	} // FIN function affecterDonneesLivraison(ID_clientLivraison)

function supprimerAdresseCarnet()
	{
	if (window.confirm("Etes-vous sûr de vouloir supprimer cette adresse de votre carnet d'adresse ?"))
		{
		window.location.href="scripts/supprimer_adresse.php?ID_clientAdresse="+document.formulaireCommander.choixLivraison.options[document.formulaireCommander.choixLivraison.selectedIndex].value;
		}
	} // FIN function supprimerAdresseLivraison()

function demanderCodes(langue)
	{
	window.open('/boutique/'+langue+'/popup/demander-codes.php','demandeCode','height=415,width=570,toolbar=no,resizable=yes,menubar=yes,scrollbars=yes,Status=yes'); 
	}

function demanderCodesListeNaissance(langue)
	{
	window.open('/boutique/'+langue+'/popup/demander-codes-listeNaissance.php','demandeCodeLN','height=415,width=570,toolbar=no,resizable=yes,menubar=yes,scrollbars=yes,Status=yes'); 
	}


/****************************************************************************/
/* FIN FONCTIONS RELATIVES A LA PAGE ADRESSE DE LA BOUTIQUE 								*/
/****************************************************************************/

/****************************************************************************/
/* FONCTIONS RELATIVES A LA PAGE ADRESSE DE LA BOUTIQUE 										*/
/****************************************************************************/

function validerPromotion()
	{
	// Si code promo renseigné alors on l'enregistre
	if (document.forms[0].offreSpeciale.value!='')
		{
		window.self.location.href='scripts/ajout_promo.php?codePromo='+document.forms[0].offreSpeciale.value;
		}
	// Sinon message
	else
		{
		alert("Merci d'indiquer votre offre speciale.");
		} // FIN else
	} // FIN function validerPromotion()

	
function validerChequeCadeau()
	{
	if (verifierFormulaire(document.formReduction))
		{	document.formReduction.submit(); }	
	} // FIN function validerChequeCadeau()
	

function passerCommande()
	{
	if (document.forms['commander'].typePaiement[0].checked==true)
		{
		document.forms['commander'].action='/includes/paiement/call_request.php';
		document.forms['commander'].method='POST';
		document.forms['commander'].submit();
		}
	if (document.forms['commander'].typePaiement[1].checked==true)
		{
		document.forms['commander'].action='/includes/paiement/call_request_paypal.php';
		document.forms['commander'].method='POST';
		document.forms['commander'].submit();
		}
	if (document.forms['commander'].typePaiement[2].checked==true)
		{
		window.self.location.href='paiement-cheque.php';
		}
	if (document.forms['commander'].typePaiement[3].checked==true)
		{
		window.self.location.href='paiement-virement.php';
		}
	if (document.forms['commander'].typePaiement[4].checked==true)
		{
		document.forms['commander'].action='/includes/paiement/call_request-2fois.php';
		document.forms['commander'].method='POST';
		document.forms['commander'].submit();
		}
	if (document.forms['commander'].typePaiement[5].checked==true)
		{
		document.forms['commander'].action='/includes/paiement/call_request-3fois.php';
		document.forms['commander'].method='POST';
		document.forms['commander'].submit();
		}
	}


function viderPanier()
	{
	if (window.confirm("Etes-vous sûr de vouloir vider votre panier ? Tous vos produits seront retirés."))
		{
		window.location.href="scripts/vider_panier.php";
		}
	}

/****************************************************************************/
/* FONCTIONS RELATIVES AU DIAPORAMA PRODUITS    							*/
/* DEVENU INUTILE A VERIFIER - DEVENU INUTILE A VERIFIER - DEVENU INUTILE	*/
/****************************************************************************/

function bq_creeDivDiapo(contenuHtml)
	{
		var posx = 30;
		var posy = 150;
		posy =  window.top.document.documentElement.scrollTop+window.top.document.body.scrollTop+50;
		creatediv("bqDiapoFlash", contenuHtml, 600, 450, posx, posy);
	}
	
function bq_creeDivVideo(contenuHtml)
	{
		var posx = 450;
		var posy = 150;
		posy =  window.top.document.documentElement.scrollTop+window.top.document.body.scrollTop+120;
		creatediv("bqVideoFlash", contenuHtml, 660, 450, posx, posy);
	}

function bq_openDiaporama(urlDiaporama)
	{
		urlBqSansGet=urlDiaporama.substring(0,urlDiaporama.indexOf('/diaporama/index.php'))+'/diaporama/diaporama.php';	
		urlBqGet=urlDiaporama.substring(urlDiaporama.indexOf('?'),urlDiaporama.length);
		urlDiapoIframe=urlBqSansGet+urlBqGet+"&urlBqSansGet="+urlBqSansGet;
		//alert(urlDiapoIframe);
		ajax(urlDiapoIframe, '', bq_creeDivDiapo);
	}

function bq_quitterDiaporama()
	{
	var objMasque = document.getElementById('bqMasque');
	objMasque.style.display='none';
	}

function bq_openVideo(urlVideo)
	{
	urlBqSansGet=urlVideo.substring(0,urlVideo.indexOf('/player-youtube/index.php'))+'/player-youtube/player.php';
	urlBqGet=urlVideo.substring(urlVideo.indexOf('?'),urlVideo.length);
	urlVideoIframe=urlBqSansGet+urlBqGet+"&urlBqSansGet="+urlBqSansGet;
	ajax(urlVideoIframe, '', bq_creeDivVideo);
	}

function bq_quitterVideo()
	{
	var objMasque = document.getElementById('bqMasque');
	objMasque.style.display='none';
	}

function creatediv(id, html, width, height, left, top) {

   DIVtoRemove = window.top.document.getElementById(id);
   //alert(DIVtoRemove);
   if(DIVtoRemove!=null)
   {
  	 window.top.document.body.removeChild(DIVtoRemove);
   }
   var newdiv = window.top.document.createElement('div');
   newdiv.setAttribute('id', id);
   
   if (width) {
       newdiv.style.width = width+'px';
   }
   
   if (height) {
       newdiv.style.height = height+'px';
   }
   
   if ((left || top) || (left && top)) {
       newdiv.style.position = "absolute";
       
       if (left) {
           newdiv.style.left = left + 'px';
       }
       
       if (top) {
           newdiv.style.top = top + 'px';
       }
   }
   
   newdiv.style.background = "#333333";
   newdiv.style.border = "1px solid #000";

   if (html) {
       newdiv.innerHTML = html;
   } else {
       newdiv.innerHTML = "nothing";
   }
  
  window.top.document.body.appendChild(newdiv);
} 

function ajax(url, vars, callbackFunction)
{
  var request =  new XMLHttpRequest();
  request.open("POST", url, true);
  request.setRequestHeader("Content-Type",
                           "application/x-www-form-urlencoded");
 
  request.onreadystatechange = function()
  {
	 
    if (request.readyState == 4 && request.status == 200)
    {
      if (request.responseText)
      {
          callbackFunction(request.responseText);
      }
    }
  };
  request.send(vars);
}


/***********************************/
/* FONCTIONS D'ENVOI AMI
/***********************************/

var popAmiOuvert=false;
var popAmiAnimEnCours=false;

function lsjs_envoyerAmiBoutique(idGamme,idFamille,idArticle)
{
	if(!popAmiOuvert && !popAmiAnimEnCours)
	{
	popAmiOuvert=true;
	/*var tempFamille=listFamilleProduitsAffiches["famille"+idFamille];*/
	var urlPage = 'http://' + window.location.hostname + '/boutique/fr/article.php?ID_gamme=' + idGamme + '&ID_famille='+idFamille + '&ID_article='+idArticle;
	var titrePage = unescape(window.document.title);
	popAmiAnimEnCours=true;	
	new Ajax.Request('/boutique/fr/popup/envoyer-page-ami.php', {
	method: 'get',
	parameters: {titrePageAmi:titrePage, UrlPageAmi:urlPage},
	requestHeaders:{Accept:'text/html'},
	onSuccess: function(transport){
	  //alert("Success! \n\n" + transport.responseText);
	   affichePopAmi(transport.responseText);}
	  });
	}
}

function affichePopAmi(contenuHtml)
{
	 Element.update($('pageAmi'),contenuHtml);
	 $('pageAmi').style.display = 'block';
	 $('pageAmi').style.top='20px';
	 Effect.MoveBy('pageAmi', 810, 0, {duration:1, fps:25, from:0.0, to:1.0, afterFinish : function () {reactiveAnimationPopAmi();}});
}

function envoiPageAmiOk(title, formulaire)
{
	$('formulaireEnvoiAmi').request({
		method: 'post',
		onComplete: function()
		{
			Element.update($('pageAmi'),htmlPopAmiOk());
		}
		})
}

function htmlPopAmiOk()
{
	var outPutHtml='';
	outPutHtml+='<div id="pagePopAmiContent">';
	outPutHtml+='<div id="enTeteClose">';
	outPutHtml+='<div id="closeFenetre">';
	outPutHtml+='<a href="javascript:effacePopAmi();">x fermer</a>';
	outPutHtml+='</div>';
	outPutHtml+='</div>';
	outPutHtml+='<div id="contenuPop">';
	outPutHtml+='<h2>Envoyer la page &agrave; un ami</h2>';
	outPutHtml+='<p><strong>Votre message a bien &eacute;t&eacute; envoy&eacute;</strong></p>';
	outPutHtml+='</div>';
	outPutHtml+='</div>' ;
	return outPutHtml;
}

function effacePopAmi()
{
	if(popAmiOuvert && !popAmiAnimEnCours)
	{
		popAmiOuvert=false;
		$('pageAmi').style.top='820px';
		popAmiAnimEnCours=true;	
		Effect.MoveBy('pageAmi', -810, 0, {duration:1, fps:25, from:0.0, to:1.0, afterFinish : function () {reactiveAnimationPopAmi();}});
	}
}

function reactiveAnimationPopAmi()
{
	popAmiAnimEnCours=false;	
}

/********************************************************/

function ajouterListeNaissance(ID_article)
{

	data = "ID_article=" + ID_article;

	if (document.getElementById("ID_coloris")) {
		data += "&" +
				"ID_coloris=" + document.getElementById("ID_coloris").value;
	}
	
	if (document.getElementById("ID_taille")) {
		data += "&" +
				"ID_taille=" + document.getElementById("ID_taille").value;
	}
	if (document.getElementById("ID_debit")) {
		data += "&" +
				"ID_debit=" + document.getElementById("ID_debit").value;
	}
	
	data += "&" +
			"article[" + ID_article + "][quantite]=" + document.getElementById("quantiteArticle").value;


		requeteXMLHttpRequest("POST", "/boutique/fr/scripts/ajouter_liste_naissance.php",
		data,
		"validationListeNaissance");

} // FIN function ajouterListeNaissance()



function accepterCGV()
	{
	if(document.forms['formulaireCGV'].accepterCGV.checked)
		{ document.forms['formulaireCGV'].submit(); }
	else
		{ alert('Vous devez accepter les conditions générales de vente pour poursuivre votre commande.'); }
	}
	
function changerDisponibilite(code)
{
	document.forms['formRqtArticle'].elements['sessionDisponibilite'].value = code;
	document.forms['formRqtArticle'].submit();
}
