////////////////////les javascript pour tapis sur mesure//////////

////////////////////pour controller la composition//////////
function control_elementtapis(){
var tapis=	document.getElementById('tapis');
if(tapis.value==0){
alert("Merci de renseigner la composition de tapis de votre véhicule");

}
}
////////////////////pour le button valider//////////
function tester(id)
{
if(id==0)
{
document.getElementById('button_valider').style.display = 'none';
}
}

////////////////////pour le button valider si le dernier combo non renseigner//////////
function tester_element_tapis(id)
{
var tapis=	document.getElementById('tapis');
if(tapis.value==0){
document.getElementById('button_valider').style.display = 'none';

}
}

function tapiser(id)
{
	var Marque_id=document.getElementsByName('Marque_'+id+'[]');
	
	
	if(id==0){
		alert('Choisissez une Marque');
		var gamme = document.getElementById('gamme');
		gamme.options.length=null;
		gamme.options.add(new Option);
		
		 gamme.options[0].text='choissisez';
		
	}
	else if(Marque_id.length > 0){
	 var gamme = document.getElementById('gamme');
	 
	 
	 gamme.options.length=null;
	 var Gamme_id=document.getElementsByName('Gamme_'+id+'[]');
	  for(i=0;i<Marque_id.length;i++){
		      
		      gamme.options.add(new Option);
		      gamme.options[i].value=i+1;
		      gamme.options[i].text=Gamme_id[i].value;
		   }	
	}
}



////////////////////pour afficher le premier article sur la fiche produit/////////
function article(id)
{
	var prix=document.getElementsByName('art_'+id+'[]');
	var image_zoom=document.getElementById('media_produit_zoom');
	var image_zoom_modi=document.getElementById('image_zoom').value;
    document.getElementById('media_produit_zoom').src =image_zoom_modi; 
	
	if(prix.length > 0){
		
		var Aulieude =document.getElementById('Aulieude'); 
		var desc = document.getElementById('desc'); 
		var prix_normal = document.getElementById('prix_normal'); 
		var prix_promo = document.getElementById('prix_promo'); 
		var prix_pourcent = document.getElementById('prix_pourcent'); 
		var quantity=document.getElementById('quantity_art');
		document.getElementById('quantity_art').value=prix[5].value;
		var monselect = document.getElementById('input_quantite');
		
		var max_quantite = document.getElementById('max_quantite');
		if(!max_quantite.value) {
			max_q = 10;
		} else {
			max_q = max_quantite.value;
		}
		
		monselect.options.length=null;
		if(quantity.value<10){
		   for(i=0;i<quantity.value;i++){
		     
		      monselect.options.add(new Option);
		      monselect.options[i].value=i+1;
		      monselect.options[i].text=i+1;
		   }
		}
		
		else{
		  var i=0;
		  
		  for(i=0;i < max_q;i++){
		      
		      monselect.options.add(new Option);
		      monselect.options[i].value=i+1;
		      monselect.options[i].text=i+1;
		 }	
		}
			
		
		
	    document.getElementById('articlecourant').value=prix[4].value;
	
		           if(parseInt(prix[2].value)=='' || parseInt(prix[2].value)=='0' ) {
		           Aulieude.innerHTML="";
		           prix_normal.innerHTML="";
		           prix_promo.innerHTML=prix[1].value /*+" TTC+ "*/;
		           
		           }
				  else{
					  
					  /*
					   
					   */
					  prix_str1 = prix[1].value;
					  prix_str1 = prix_str1.replace("€", "");
					  prix_str1 = prix_str1.replace(",", ".");
					  prix_str2 = prix[2].value;
					  prix_str2 = prix_str2.replace("€", "");
					  prix_str2 = prix_str2.replace(",", ".");
					  prix1 = parseFloat(prix_str1);
					  prix2 = parseFloat(prix_str2);
					  val_pourcent =  (prix1 - prix2) * 100 / prix1;
					  prix_pourcent.innerHTML = "<div class=\"mosaic_discount_amount\"><div class=\"discount_text\">remise</div>-" + roundNumber(val_pourcent,0) + "%</div>";
					  
					  Aulieude.innerHTML="Au lieu de ";
					  prix_normal.innerHTML=prix[1].value/*+" TTC+ "*/;
					  prix_promo.innerHTML=prix[2].value/* +" TTC+ "*/;	
				  }
	}

	if(document.getElementById('quantity_art').value==0){
	
	 document.getElementById('add_if_artstock').style.display='none';
	 document.getElementById('add_if_NOartstock').style.display='block';
	
	}else{
	 document.getElementById('add_if_artstock').style.display='block';
	 document.getElementById('add_if_NOartstock').style.display='none';
	}
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}




