// 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)
	{
	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();
	}

function afficherDetailMouture(calque)
	{
	sfEls=document.getElementsByTagName("div");
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].className=='detailMouture')
			{
			sfEls[i].style.display='none';
			}
		}
    document.getElementById(calque).style.display='block';
	}

function changerMouture (valeurMouture,idMouture)
	{
	window.document.forms['commander'].mouture.value=valeurMouture;
	window.document.forms['commander'].ID_mouture.value=idMouture;
	document.getElementById("detailMouture").style.display='none';
	} // FIN function changerMouture (valeurMouture,idMouture)
	
/****************************************************************************/
/* 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 supprimerAdresseLivraison()
	{
	if (window.confirm("Etes-vous sûr de vouloir supprimer cette adresse de livraison ?"))
		{
		window.location.href="scripts/supprimer_adresse.php?ID_clientAdresse="+document.formulaireCommander.choixLivraison.options[document.formulaireCommander.choixLivraison.selectedIndex].value;
		}
	} // FIN function supprimerAdresseLivraison()
	
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=335,width=560,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)
		{
		window.self.location.href='paiement-cheque.php';
		}
	if (document.forms['commander'].typePaiement[2].checked==true)
		{
		window.self.location.href='paiement-virement.php';
		}
	if (document.forms['commander'].typePaiement[3].checked==true)
		{
		window.self.location.href='paiement-fax.php';
		}
	}
function Ouvrir_Spplus()
 {
		// Largeur et hauteur préconisées de la fenêtre SPPLUS
	var PopupSpplus_largeur	= 750;
	var PopupSpplus_hauteur	= 560;

		// Position haut et gauche de la fenêtre SPPLUS pour affichage centré dans l'écran
	var PopupSpplus_top	=((screen.height-PopupSpplus_hauteur)/2);
	var PopupSpplus_left	=((screen.width-PopupSpplus_largeur)/2);

	// Ouverture du popup SPLUS avec barre état uniquement et focus sur la fenêtre
	var win = window.open('', "SPPLUS","status=yes,top="+PopupSpplus_top+",left="+PopupSpplus_left+",width="+PopupSpplus_largeur+",height="+PopupSpplus_hauteur);
	win.focus();
 }
 
function masquerAvecEffets(calque)
	{
	obj = document.getElementById(calque);
	if (obj.style.display=='none')
		{ new Effect.BlindDown(calque); } 
	else
		{ new Effect.Fade(calque); } 
	} // FIN function masquerBloc(calque)
	

/****************************************************************************/
/* FONCTIONS RELATIVES AU DIAPORAMA PRODUITS    							*/
/****************************************************************************/

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_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 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);
}
