<!--

function MakepopWidthMenu(url,my_l,my_h,my_s){
    /* Version 1.0 */
    /* Creation Marc alias DMC */
    var Ypos=(screen.availHeight-my_h)/2 ;
    var Xpos=(screen.availWidth-my_l)/2;
    addPop=window.open(url,'_blank',"width="+my_l+",height="+my_h+",scrollbars=1,toolbar=0,location=0,status=1,menubar=yes,resizable=1");
    if(addPop){
        addPop.moveTo(Xpos, Ypos);
        addPop.focus();
    }
}

function renewSession() {
	document.images["renewSession"].src = "RenewSession.do?par=" + Math.random();
}

// Affichage du formulaire d'envoi d"un e-mail à un ami
function popupEnvoyerMailUnAmiGeneric(height, width) {
	Makepop("EnvoyerPage.do?url="+top.location.href+"&mailHTML=true&site=true",height,width,'1',false,false,'envoyer_ami_popup');
}

// Affichage du statut inscription newsletter
function newsletterGeneric(msg,height,width) {
   var form = document.getElementById("mailingForm");
   if( validateEmailNewsletter(form, msg) ){
	   Makepop("NewsLetter.do?popup=true&method=subscribe&email=" + form.email.value +"&nom=" + form.nom.value,height,width,'1',false,false,'newsletter_popup');
   }	
}

function validateEmailNewsletter(form, msg) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)){
		return (true)
	}
	alert(msg)
	form.email.focus();
	return (false)
}

// Ajouter aux favoris
function favoris() {
	  bookmarkurl= top.location.href
	  bookmarktitle= top.document.title 
      if ( navigator.appName != 'Microsoft Internet Explorer' ){ 
          window.sidebar.addPanel(bookmarktitle,bookmarkurl,""); 
      } 
      else { 
          window.external.AddFavorite(bookmarkurl,bookmarktitle); 
      } 
}

/*
   Cette fonction permet d'ajouter au caddie les articles
   type : type de nuancier 
            - 0 : bloc corner
            - 1 : simple
            - 2 : pinceau
            - 3 : nuancierXL
            - 4 : nuancier S
            - 5 : nuancier M
            - 6 : listeCouleurs (non utilisé)
    idBlocProduit : identifiant de l'article dans la page
    index : index de l'article dans la page
      
*/
function acheterArticle(type, idBlocProduit, index) {
	
	if (type==1 || type ==2) {
		myForm = document.getElementsByName("blocproduit" + idBlocProduit)[0];
	} else if (type==0){
		myForm = document.getElementsByName("bloccorner" + idBlocProduit)[0];	
	} else{
		myForm = document.getElementsByName("article" + idBlocProduit)[0];	
	}
	
	destForm = document.getElementsByName("commande" + idBlocProduit)[0];
	
	destForm["idBlocProduit"].value = idBlocProduit;
	destForm["id[0]"].value = myForm["id" + index].value;
	destForm["ref[0]"].value = myForm["ref" + index].value;
	destForm["qte[0]"].value = myForm["qte" + index].value;
		
	if (type == 3) {
		blocForm = document.getElementsByName("blocproduit" + idBlocProduit)[0];
		destForm = document.getElementsByName("commande" + idBlocProduit)[0];
		if (blocForm.show_all.checked) destForm.show_all.value='on';
		if (blocForm.show_1.checked) destForm.show_1.value='on';
		if (blocForm.show_2.checked) destForm.show_2.value='on';
		if (blocForm.show_3.checked) destForm.show_3.value='on';
		if (blocForm.show_4.checked) destForm.show_4.value='on';
		if (blocForm.show_5.checked) destForm.show_5.value='on';
		if (blocForm.show_6.checked) destForm.show_6.value='on';
		if (blocForm.show_7.checked) destForm.show_7.value='on';
		if (blocForm.show_8.checked) destForm.show_8.value='on';
	}
	
	destForm.submit();	
}

function changeQteArticle (type, idBlocProduit, index, qteMin, listePrixHt, listePrixTtc) {
	if (type==1 || type ==2) {
		myForm = document.getElementsByName("blocproduit" + idBlocProduit)[0];
	} else if (type==0){
		myForm = document.getElementsByName("bloccorner" + idBlocProduit)[0];	
	} else {
		myForm = document.getElementsByName("article" + idBlocProduit)[0];	
	}

	qtevalue = myForm["qte"+index].value;
	
	if (qtevalue<=0 || isNaN(qtevalue)) {
		qtevalue = 1;
		myForm["qte"+index].value = 1.
	}

	if (type!=1 && type !=2 && type !=3) {
		var i = 0;
		for(i=0;i<qteMin[index].length-1;i++) {
			if (qteMin[index][i+1]>qtevalue) break;
		}
	
		myForm["prixht"+index].value = listePrixHt[index][i];
		if (myForm["prixttc"+index] != null) {
			myForm["prixttc"+index].value = listePrixTtc[index][i];	
		}
	}
}
	

function acheterMultiRefs () {
	var items = acheterMultiRefs.arguments.length;
	var re = new RegExp('^[0-9]+$');
	if ((items%2) != 0) {
		alert('Le nombre des arguments doit être paire');
		return;
	}
	
	// Validation des valeurs des arguments
	for (i = 0;i < items;i++) {
      	if (!(re.test(acheterMultiRefs.arguments[i]))) {
			alert('Error with ' + acheterMultiRefs.arguments[i]);
			return ;
		}
	}

	articleForm = document.createElement('form');
	articleForm.id='addCartForm';
	articleForm.action='AddCart.do';
	articleForm.method ='POST';
	input = document.createElement('input');
	input.type='hidden';
	input.name='ajoutMultiple';
	input.value='true'; //on met 1 pour que dans l'action on ne soit pas redirigé vers la page "batch" 
	articleForm.appendChild(input);		
	var j=0;
	for (i = 0;i < items;i=i+2) {
		j++;		
		input = document.createElement('input');
		input.type='hidden';
		input.name='qtesArray[' + (i/2) + ']';
		input.value=acheterMultiRefs.arguments[i];
		articleForm.appendChild(input);
		input = document.createElement('input');
		input.type='hidden';		
		input.name='refsArray[' + (i/2) + ']';
		input.value=acheterMultiRefs.arguments[i+1];
		articleForm.appendChild(input);
		
	}

	input = document.createElement('input');
	input.type='hidden';
	input.name='nbRef';
	input.value=j;
	articleForm.appendChild(input);
	input = document.createElement('input');
	input.type='hidden';
	input.name='date';
	//dateAjoutArticle est initialisé via une scriptlet java dans charteSite.jsp pour éviter une différence de dates dans l'action AddCart
	input.value=dateAjoutArticle;
	articleForm.appendChild(input);

	document.body.appendChild(articleForm);
	articleForm.submit();
	/*	
	var req = "AddCart.do?" + $('addCartForm').serialize()
	new Ajax.Request(req,{
  		method:'get',
  		onSuccess: function(transport){
  			var response = transport.responseText || "no response text";
 			// Affichage du resume du caddie
			Makepop("ResumeCart.do",450,265,'1',false,true, "caddieresume");
			//on recharge la page pour changer le nbre d'articles
			//TODO, ne renvoyer que le contenu de la partie "mon panier" et faire un update
			document.location.href=document.location.href;
    		response.evalScripts();
  		},
  		onFailure: function(){ alert("Problème technique") }
		});
		*/
		
	
}

//-->
