//window.onload=montre;
id_menu=0;
id_smenu=0;
function montre(id) {
	
	if( document.getElementById(id_menu) )
		document.getElementById(id_menu).style.display='none';
	if( id == "" ){
		return;
	}
	var d = document.getElementById(id);
	if (d) {
	d.style.display='block';
	id_menu=id;
	}
	
	/*
	var d = document.getElementById(id);
	
	////on cache tout les sousmenu:
		for (var i = 1; i<=100; i++) {
			if (document.getElementById('smenu'+i)) {
				
				document.getElementById('smenu'+i).style.display='none';}

		}
	///on affiche le sousmenu demandé:
	if (d) {d.style.display='block';}
	*/
}
function montressmenu2(id) {
	if( document.getElementById(id_smenu) )
		document.getElementById(id_smenu).style.display='none';
	if( id == "" ){
		return;
	}
	var d = document.getElementById(id);
	if (d) {
	d.style.display='block';
	id_smenu=id;
	}
	/*
	var d = document.getElementById(id);
	
	////on cache tout les sousmenu2:
		for (var i = 1; i<=100; i++) {
			if (document.getElementById('ssmenu'+i)) {
				
				document.getElementById('ssmenu'+i).style.display='none';}

		}
	///on affiche le sousmenu demandé:
	if (d) {d.style.display='block';}
	*/
}



function ChangeDep(formulaire){
	if (formulaire.ListeUrl.selectedIndex != 0){
		location.href = formulaire.ListeUrl.options[formulaire.ListeUrl.selectedIndex].value;
	}
}


function compteur(annee,mois,jour, heure, minutes){
	Maintenant = new Date;
	TempMaintenant = Maintenant.getTime();
	Future = new Date(annee, mois, jour, heure, minutes);
	/*ordre du mois=0 pour janvier, 1 pour février etc etc*/
	TempFuture = Future.getTime();
	DiffSec = Math.floor((TempFuture-TempMaintenant)/1000);
	DiffMin = Math.floor(DiffSec/60);
	Diffheure = Math.floor(DiffMin/60);
	DiffJour = Math.floor(Diffheure/24);
	while (DiffMin>=60) { DiffMin = DiffMin-60; }
	while (Diffheure>=24) { Diffheure = Diffheure-24; }
	while (DiffSec>=60) { DiffSec = DiffSec-60; }
	if(DiffMin<0){
		document.write('<p style="color:#EB82E0;font-size:15px;font-weight:bold;">0 jour 0 heure 0 min  </p>');		
	}else{
		document.write('<p style="color:#EB82E0;font-size:15px;font-weight:bold;">' +  DiffJour + ' jour<span style="font-size:11px">(</span>s<span style="font-size:11px">)</span> ' + Diffheure + ' heure<span style="font-size:11px">(</span>s<span style="font-size:11px">)</span> ' + DiffMin + ' min  </p>');
	}
}

/* galerie */

//fonction pour changer les photos
function ChargeImage(image,prec,suiv){
	if(document.getElementById)
		document.getElementById("image").innerHTML = '<img src="'+image+'" style="border:0" alt="">';
	else
		window.open(image,"_blank")
}


function clients(adresse){
	var hauteur_popup=500;
	var H = (screen.height - hauteur_popup) / 2;
	var largeur_popup=420;
	var L = (screen.width - largeur_popup) / 2;
	pop_up = window.open(adresse,"Popup","status=no,scrollbars=no,resizable=no,height="+hauteur_popup+",width="+largeur_popup+",top="+H+",left="+L);
}


function conditions(adresse){
	var hauteur_popup=500;
	var H = (screen.height - hauteur_popup) / 2;
	var largeur_popup=500;
	var L = (screen.width - largeur_popup) / 2;
	pop_up = window.open(adresse,"Popup","status=no,scrollbars=yes,resizable=no,height="+hauteur_popup+",width="+largeur_popup+",top="+H+",left="+L);
}

function calculDevis(taux,num_option,prix_vente_option){
		nomFichier=document.getElementById("nom_fichier").value;
		var total_remise=0;
		if(document.getElementById("nb_copies") && !isNaN(document.getElementById("nb_copies").value)){
			if(document.getElementById("nb_copies").value=="1")
				nbCopies = " en "+document.getElementById("nb_copies").value+" exemplaire";
			else if(document.getElementById("nb_copies").value!="" && document.getElementById("nb_copies").value!="0" && parseInt(document.getElementById("nb_copies").value)>0)
				nbCopies = " en "+document.getElementById("nb_copies").value+" exemplaires";
				else nbCopies="";
		}
		else nbCopies="";
		if(!isNaN(parseInt(nbCopies))) nbCopies="";
		
		if(document.getElementById("nb_copies") && !isNaN(document.getElementById("nb_copies").value)){
			if(parseInt(document.getElementById("nb_copies").value)>0)
				quantite=parseInt(document.getElementById("nb_copies").value);
		}
		else quantite=0;
		if(document.getElementById("largeur").value!="" && parseInt(document.getElementById("largeur").value)>0){
			if(document.getElementById("hauteur").value!="" && parseInt(document.getElementById("hauteur").value)>0){
				larg2=parseInt(document.getElementById("largeur").value)/5;
				larg=" "+document.getElementById("largeur").value+"x";
				haut2=parseInt(document.getElementById("hauteur").value)/5;
				haut=document.getElementById("hauteur").value;
				afficherCacher("echelle",1);
				document.getElementById("echelle").value="Veuillez nous faire parvenir un fichier vectoriel ou un fichier image à l'échelle 1/5 300dpi, soit l="+larg2+" et h="+haut2+"";
			}
			else{
				larg="";
				haut="";
				document.getElementById("echelle").value="";
				afficherCacher("echelle",0);
			}
		}
		else{
			larg="";
			haut="";
			document.getElementById("echelle").value="";
			afficherCacher("echelle",0);
		}
		var temp=document.getElementById("id_support").value;
		if(document.getElementById("id_support")){
			
			if(document.getElementById("id_support").value !=""){
				var temp2=document.getElementById("id_support").value;
				idSupport=" sur "+cutStringBeforeChar(cutStringAfterChar(temp2,'|'),'>');
			}
			else idSupport="";
		}
		
		if(larg!="0" && haut!="0" && larg!="" && haut!="" && idSupport!=""){
			var prix_support=parseFloat(cutStringBeforeChar(cutStringAfterChar(temp,'>')),'%');
			var infos_remise_support=document.getElementById("id_support").value.split("#");
			infos_remise_support=infos_remise_support[1].split("|");
			var palier_remise_support=infos_remise_support[0];
			var taux_remise_support=infos_remise_support[1];
			if(parseFloat(palier_remise_support)>0){	//si palier est à 0, pas de remise
				for(var k=1;k<=1;k++){
					if((parseInt(larg)*parseInt(haut)/10000*quantite)/parseFloat(palier_remise_support)>=k){
						total_remise+=prix_support*(1-parseFloat(taux_remise_support));
						prix_support*=parseFloat(taux_remise_support);
					}
				}
			}
			impressionPapier=Math.round(parseInt(larg,10)*parseInt(haut,10)/10000*prix_support*100)/100;
		}
		else impressionPapier=0;
		if(!isNaN(impressionPapier)){
			document.getElementById("impression_papier").value=impressionPapier+" €";
		}
		else document.getElementById("impression_papier").value="0 €";

		
		if(!isNaN(impressionPapier)){
			prix1=parseFloat(impressionPapier);//+parseFloat(prixPlastification)+parseFloat(prixContrecollage)+parseFloat(prix_total_option);
		}
		else {
			prix1=0;
		}
		
		if(document.getElementById("plastification_brillante_matte")){
			plastificationBrillanteMatte=document.getElementById("plastification_brillante_matte").value;
		}else{
			plastificationBrillanteMatte="";
		}
		
		if(document.getElementById("id_plastification")){
			typePlastification=document.getElementById("id_plastification").value;
			if(typePlastification!=""){
				afficherCacher("plastification1",1); afficherCacher("plastification2",1); afficherCacher("plastification3",1); afficherCacher("plastification4",1);
				nomPlastification=". Plastifié en : "+cutStringBeforeChar(cutStringAfterChar(typePlastification,'|'),'>')+" ("+plastificationBrillanteMatte+")";
				prixPlastification=parseFloat(cutStringBeforeChar(cutStringAfterChar(typePlastification,'>'),'%'));
				var infos_remise_plastification=document.getElementById("id_plastification").value.split("#");
				infos_remise_plastification=infos_remise_plastification[1].split("|");
				var palier_remise_plastification=infos_remise_plastification[0];
				var taux_remise_plastification=infos_remise_plastification[1];
				if(parseFloat(palier_remise_plastification)>0){	//si palier est à 0, pas de remise
					for(var k=1;k<=1;k++){
						if((parseInt(larg)*parseInt(haut)/10000*quantite)/parseFloat(palier_remise_plastification)>=k){
							total_remise+=prixPlastification*(1-parseFloat(taux_remise_plastification));
							prixPlastification*=parseFloat(taux_remise_plastification);
						}
					}
				}
				prixPlastification=prixPlastification*parseInt(larg)*parseInt(haut)/10000;
				if(!isNaN(prixPlastification)){
					prix1+=prixPlastification;
					prixPlastification=Math.round(prixPlastification*100)/100;
					document.getElementById("prix_plastification").value=prixPlastification+" €";
				}
				else document.getElementById("prix_plastification").value="0 €";
			}
			else{
				afficherCacher("plastification1",0); afficherCacher("plastification2",0); afficherCacher("plastification3",0); afficherCacher("plastification4",0);
				nomPlastification="";
				prixPlastification=0;
				document.getElementById("prix_plastification").value="0 €";
			}
		}
		else{
			afficherCacher("plastification1",0); afficherCacher("plastification2",0); afficherCacher("plastification3",0); afficherCacher("plastification4",0);
			nomPlastification="";
			prixPlastification=0;
			document.getElementById("prix_plastification").value="0 €";
		}
		
		if(document.getElementById("id_contrecollage")){
			typeContrecollage=document.getElementById("id_contrecollage").value;
			if(typeContrecollage!=""){
				afficherCacher("contrecollage1",1); afficherCacher("contrecollage2",1); afficherCacher("contrecollage3",1); afficherCacher("contrecollage4",1);
				nomContrecollage=". Avec un contrecollage : "+cutStringBeforeChar(cutStringAfterChar(typeContrecollage,'|'),'>');
				prixContrecollage=parseFloat(cutStringBeforeChar(cutStringAfterChar(typeContrecollage,'>'),'%'));
				var infos_remise_contrecollage=document.getElementById("id_contrecollage").value.split("#");
				infos_remise_contrecollage=infos_remise_contrecollage[1].split("|");
				var palier_remise_contrecollage=infos_remise_contrecollage[0];
				var taux_remise_contrecollage=infos_remise_contrecollage[1];
				if(parseFloat(palier_remise_contrecollage)>0){	//si palier est à 0, pas de remise
					for(var k=1;k<=1;k++){
						if((parseInt(larg)*parseInt(haut)/10000*quantite)/parseFloat(palier_remise_contrecollage)>=k){
							total_remise+=prixContrecollage*(1-parseFloat(taux_remise_contrecollage));
							prixContrecollage*=parseFloat(taux_remise_contrecollage);
						}
					}
				}
				prixContrecollage=prixContrecollage*parseInt(larg)*parseInt(haut)/10000;
				if(!isNaN(prixContrecollage)){
					prix1+=prixContrecollage;
					prixContrecollage=Math.round(prixContrecollage*100)/100;
					document.getElementById("prix_contrecollage").value=prixContrecollage+" €";
				}
				else document.getElementById("prix_contrecollage").value="0 €";
			}
			else{
				afficherCacher("contrecollage1",0); afficherCacher("contrecollage2",0); afficherCacher("contrecollage3",0); afficherCacher("contrecollage4",0);
				nomContrecollage="";
				prixContrecollage=0;
				document.getElementById("prix_contrecollage").value="0 €";
			}
		}
		else{
			afficherCacher("contrecollage1",0); afficherCacher("contrecollage2",0); afficherCacher("contrecollage3",0); afficherCacher("contrecollage4",0);
			nomContrecollage="";
			prixContrecollage=0;
			document.getElementById("prix_contrecollage").value="0 €";
		}
		
		var nombre=new Array();
		var position=new Array();
		var check=new Array();
		var prix_option=new Array();
		var prix_total_option=0;
		var i = 0;
		var recap_option="";
		
			for(i=0;i<100;i++){
				if(i!=parseInt(num_option)){	//quand i n'est pas -1 ou un numéro d'option
					if(document.getElementById("prix_option_"+i)){
						if(document.getElementById("prix_option_"+i).value!=""){
							prix_option[i]=document.getElementById("prix_option_"+i).value;
							prix_total_option+=Math.round(cutStringBeforeChar(document.getElementById("prix_option_"+i).value," ")*100)/100;
							if(prix_option[i]!=0&&prix_option[i]!="0 ?"&&!isNaN(prix_option[i])){
								afficherCacher("prix_option_"+num_option+"_1",1); afficherCacher("prix_option_"+num_option+"_2",1); afficherCacher("prix_option_"+num_option+"_3",1); afficherCacher("prix_option_"+num_option+"_4",1);
							}
							else{
									if(parseInt(num_option)!=-1){
										afficherCacher("prix_option_"+num_option+"_1",0);
										afficherCacher("prix_option_"+num_option+"_2",0);
										afficherCacher("prix_option_"+num_option+"_3",0);
										afficherCacher("prix_option_"+num_option+"_4",0);
									}
							}
						}
					}
				}
			}
		if(parseInt(num_option)!=-1){
			i=parseInt(num_option);
			var coeff=0;
			
			if(document.getElementById("nombre_"+i)){
				if(parseInt(document.getElementById("nombre_"+i).value)>-1)
					nombre[i]=parseInt(document.getElementById("nombre_"+i).value);
			}
			else nombre[i]=-1;
			if(document.getElementById("position_"+i)){
				position[i]=document.getElementById("position_"+i).value;
			}
			else position[i]=-1;
			if(document.getElementById("check_"+i)){
				check[i]=document.getElementById("check_"+i).value;
			}
			else {
				check[i]=0;
				prix_option[i]=0;
			}
			if(check[i]!=0){
				if(check[i]!=0)	prix_option[i]=Math.round(parseFloat(prix_vente_option)*100*parseInt(check[i]))/100;
				else prix_option[i]=0;
			}
			else if(nombre[i]==-1){
				coeff= contient(position[i]);
				prix_option[i]=Math.round(parseFloat(prix_vente_option)*parseInt(coeff)*100)/100;
				}
			else if(position[i]==-1){
				coeff=parseInt(nombre[i]);
				prix_option[i]=Math.round(parseFloat(prix_vente_option)*parseInt(nombre[i])*100)/100;
				}
			else {
				coeff=contient(position[i])*parseInt(nombre[i]);
				prix_option[i]=Math.round(parseFloat(prix_vente_option)*parseInt(coeff)*100)/100;
			}
			if(prix_option[i]!=0&&prix_option[i]!="0 ?"&&!isNaN(prix_option[i])){
				afficherCacher("prix_option_"+num_option+"_1",1); afficherCacher("prix_option_"+num_option+"_2",1); afficherCacher("prix_option_"+num_option+"_3",1); afficherCacher("prix_option_"+num_option+"_4",1);
				}
			else{
				afficherCacher("prix_option_"+num_option+"_1",0); afficherCacher("prix_option_"+num_option+"_2",0); afficherCacher("prix_option_"+num_option+"_3",0); afficherCacher("prix_option_"+num_option+"_4",0);
			}
		}
			
 		if(document.getElementById("prix_option_"+i)){
			if(!isNaN(prix_option[i]) && prix_option[i]!=0){
				document.getElementById("prix_option_"+i).value=prix_option[i]+" €";
				prix_total_option+=parseFloat(prix_option[i]);
			}
			else document.getElementById("prix_option_"+i).value="0 €";	
		} 
		
		for(i=0;i<100;i++){
			if(document.getElementById("prix_option_"+i)){
				if(document.getElementById("prix_option_"+i).value!="0 ?" && document.getElementById("prix_option_"+i).value!=""){
					recap_option+=". "+document.getElementById("nom_option_"+i).value;
					if(document.getElementById("nombre_"+i)&&document.getElementById("position_"+i)){ recap_option+=" ("+document.getElementById("nombre_"+i).value+" par côté)";
					}
					else if(document.getElementById("nombre_"+i)){
						recap_option+=" ("+document.getElementById("nombre_"+i).value+")";
						}
					if(document.getElementById("position_"+i)){ recap_option+=" "+document.getElementById("position_"+i).value; }
				}
			}
		}
		
		if(!isNaN(prix_total_option)) prix1+=prix_total_option;
		
		if(!isNaN(prix1)){
			prix1=Math.round(prix1*100)/100;
			document.getElementById("prix_1").value=prix1+" €";
		}
		else document.getElementById("prix_1").value="0 €";
		
		if(!isNaN(quantite)){
			document.getElementById("quantite").value=quantite;
		}
		else document.getElementById("quantite").value="0";
		
		//calcul avec ou sans frais_port
		if(document.getElementById("check_frais_port")){
			if((document.getElementById("check_frais_port").checked==true) && haut!="" && larg!="" && idSupport!=""){
				//alert( "fdp_support:"+document.getElementById("id_support").value );
				//alert( "fdp_contrcollge:"+document.getElementById("id_contrecollage").value );
				
				/////// calcul fdp suppôrt
				var carac_frais_port=document.getElementById("id_support").value.split("£");
				carac_frais_port=carac_frais_port[1].split("#");
				carac_frais_port=carac_frais_port[0].split("|");
			
				
				
				/////// carac_frais_port[0] : prix minimun du port (ex: 16€)
				/////// carac_frais_port[1] : prix ajouté par m² (ex: 1€)
				/////// carac_frais_port[0] : prix max du port (ex: 70€)
				
				
				/////// calcul brut des frais de port: en fonction du support:
				
				
				var fdppm2 =parseInt( carac_frais_port[0] );//onaffecte le prix min
				fdppm2 +=  parseInt(larg)*parseInt(haut)*quantite/10000 * carac_frais_port[2];// on ajpoute le port au m&
				
				fdppm2 = Math.min( fdppm2 , carac_frais_port[1] );///// on majot par le prix max.
				//alert( carac_frais_port + " :: " + fdppm2 );
				
				////// calcul fdp contrecollage:( en sus )
				var fdppm2cclg = 0;
				if( nomContrecollage!="" ){
					var carac_frais_port2=document.getElementById("id_contrecollage").value.split("£");
					carac_frais_port2=carac_frais_port2[1].split("#");
					carac_frais_port2=carac_frais_port2[0].split("|");
					fdppm2cclg = parseInt( carac_frais_port2[0] );//onaffecte le prix min
					fdppm2cclg +=  parseInt(larg)*parseInt(haut)* quantite / 10000 * carac_frais_port2[2];// on ajpoute le port au m&
					fdppm2cclg = Math.min( fdppm2cclg , carac_frais_port2[1] );///// on majot par le prix max.
					//alert( carac_frais_port2 + " :: " + fdppm2cclg );
				}
				frais_port = fdppm2 + fdppm2cclg;
				//alert( "FDP:"+frais_port );
				
							
			}
			else frais_port=0;
		}
		
		//affichage frais_port
		if(!isNaN(frais_port)&&parseFloat(frais_port)>0){
			frais_port=Math.round(frais_port*100)/100;
			document.getElementById("frais_port").value=frais_port+" €";
			afficherCacher("frais_port_1",1); afficherCacher("frais_port_2",1); afficherCacher("frais_port_3",1); afficherCacher("frais_port_4",1);
		}
		else{
			document.getElementById("frais_port").value="0 €";
			afficherCacher("frais_port_1",0); afficherCacher("frais_port_2",0); afficherCacher("frais_port_3",0); afficherCacher("frais_port_4",0);
		}
		
		if(!isNaN(total_remise)&&total_remise>0){
			total_remise*=parseFloat(larg)*parseFloat(haut)/10000*parseInt(quantite);
			document.getElementById("total_remise").value="Remise de "+Math.round(total_remise*100)/100+" € sur votre commande";
		}
		else document.getElementById("total_remise").value=""; 
		
		if(!isNaN(quantite) && !isNaN(prix1) && !isNaN(frais_port) && quantite!=0 && prix1!=0){
			prixHT=Math.round(parseFloat(prix1)*parseInt(quantite)*100+parseFloat(frais_port)*100)/100;
			prixTTC=Math.round(parseFloat(prixHT)*(1+parseFloat(taux)/100)*100)/100;
		}
		else{
			prixHT=0;
			prixTTC=0;
		}
		
		if(!isNaN(prixHT) && !isNaN(prixTTC)){
			document.getElementById("prix_ht").value=prixHT+" €";
			document.getElementById("prix_ttc").value=prixTTC+" €";
		}
		else{
			document.getElementById("prix_ht").value="0 €";
			document.getElementById("prix_ttc").value="0 €";
		}
		
		document.getElementById("recapitulatif_devis").value=nomFichier+nbCopies+larg+haut+idSupport+nomPlastification+nomContrecollage+recap_option+".";
}

function afficherCacher(idDiv,i) {
	var div = document.getElementById(idDiv);
	if(div){
		if (i==1 && div.style.display=="none")
			div.style.display = "";
		else if(i==0 && div.style.display=="")
			div.style.display = "none";
	}
}

function cutStringBeforeChar(str,chara){
	var chaine = "";
	for(var i=0;i<str.length;i++){
		if(str.charAt(i)!=chara) chaine+=str.charAt(i);
		else return chaine;
	}
	return chaine;
}

function cutStringAfterChar(str,chara){
	var chaine = "";
	var i=0
	for(i;i<str.length;i++){
		if(str.charAt(i)==chara) break;
	}
	if(i==str.length-1) return chaine;
	i++;
	for(i;i<str.length;i++){
		chaine+=str.charAt(i);
	}
	return chaine;
}

function contient(str){
	var res=0;
	if(str.length>1) res=1;
	for(var i=3;i<str.length;i++){
		if(str.charAt(i)=='t'&&str.charAt(i-1)=='e')
			res= 2;
		if(str.charAt(i)=='t'&&str.charAt(i-1)=='u'&&str.charAt(i-2)=='o'&&str.charAt(i-3)=='t')
			res= 4;
	}
	return res;
}

function changeClicOption(num_option){
	var val=document.getElementById("check_"+num_option);
	if(val.value=="clic_option"){
		afficherCacher("check_"+num_option+"_init",0); afficherCacher("check_"+num_option+"_normal",1);
		val.value="1";
	}
	else if(val.value=="0"){
		val.value="1";
	}
	else val.value="0";
}

function changeClic(){
	var val=document.getElementById("check_frais_port");
	if(val.value=="-1"){
		val.value='1';
	}
	else if(val.value=="0") val.value='1';
	else val.value='0';
}

function afficherDescription(num_option){
	if(document.getElementById("id_support")){
		if(document.getElementById("id_support").value!=""){
			var i=cutStringBeforeChar(cutStringAfterChar(document.getElementById("id_support").value,'%'),'£');
			for(var j=0;j<100;j++){
				if(document.getElementById("desc_support_"+j)){
					afficherCacher("desc_support_"+j,0);
					afficherCacher("remise_support_"+j,0);
					
				}
			}
			afficherCacher("desc_support_"+i,1);
			afficherCacher("remise_support_"+i,1);
		}
		else{
			for(var j=0;j<100;j++){
				if(document.getElementById("desc_support_"+j)){
					afficherCacher("desc_support_"+j,0);
					afficherCacher("remise_support_"+j,0);
				 }
			 }
		}
	}
	if(document.getElementById("id_plastification")){
		if(document.getElementById("id_plastification").value!=""){
			var i=cutStringBeforeChar(cutStringAfterChar(document.getElementById("id_plastification").value,'%'),'#');
			for(var j=0;j<100;j++){
				if(document.getElementById("desc_plastification_"+j)){
					afficherCacher("desc_plastification_"+j,0);
					afficherCacher("remise_plastification_"+j,0);
				}
			}
			afficherCacher("desc_plastification_"+i,1);
			afficherCacher("remise_plastification_"+i,1);
		}
		else{
			for(var j=0;j<100;j++){
				if(document.getElementById("desc_plastification_"+j)){
					afficherCacher("desc_plastification_"+j,0);
					afficherCacher("remise_plastification_"+j,0);
				 }
			 }
		}
	}
	if(document.getElementById("id_contrecollage")){
		if(document.getElementById("id_contrecollage").value!=""){
			var i=cutStringBeforeChar(cutStringAfterChar(document.getElementById("id_contrecollage").value,'%'),'£');
			for(var j=0;j<100;j++){
				if(document.getElementById("desc_contrecollage_"+j)){
					afficherCacher("desc_contrecollage_"+j,0);
					afficherCacher("remise_contrecollage_"+j,0);
				}
			}
			afficherCacher("desc_contrecollage_"+i,1);
			afficherCacher("remise_contrecollage_"+i,1);
		}
		else{
			for(var j=0;j<100;j++){
				if(document.getElementById("desc_contrecollage_"+j)){
					afficherCacher("desc_contrecollage_"+j,0);
					afficherCacher("remise_contrecollage_"+j,0);
				 }
			 }
		}
	}
	if(parseInt(num_option)!=-1){
		for(var k=0;k<100;k++){
			if(document.getElementById("nombre_"+k)){
				if(document.getElementById("nombre_"+k).value!=""){
					afficherCacher("desc_nombre_option_"+k,1);
				}
				else{
					if(document.getElementById("desc_nombre_option_"+k)){
						afficherCacher("desc_nombre_option_"+k,0);
					}
				}
			}
			else if(document.getElementById("position_"+k)){
				if(document.getElementById("position_"+k).value!=""){
					afficherCacher("desc_position_option_"+k,1);
				}
				else{
					if(document.getElementById("desc_position_option_"+k)){
						afficherCacher("desc_position_option_"+k,0);
					}
				}
			}
			else if(document.getElementById("check_"+k)){
				if(document.getElementById("check_"+k).value!="1"&&document.getElementById("check_"+k).value!="clic_option"){
					afficherCacher("desc_check_option_"+k,1);
				}
				else{
					if(document.getElementById("desc_check_option_"+k)){
						afficherCacher("desc_check_option_"+k,0);
					}
				}
			}
		}
	}
}

function validerFormulaire(){
	var contenu="";
	var larg=document.getElementById("largeur").value;
	var haut=document.getElementById("hauteur").value;
	var qte=parseInt(document.getElementById("nb_copies").value);
	if(document.getElementById("nom_fichier")){
		nom_fichier=document.getElementById("nom_fichier").value;
	}
	else nom_fichier="";
	if(document.getElementById("id_support")){
		id_support=document.getElementById("id_support").value;
	}
	else id_support="";
	if(document.getElementById("prix_ttc")){
		prix_ttc=document.getElementById("prix_ttc").value;
	}
	else prix_ttc="";
	if(document.getElementById("id_plastification")&&document.getElementById("plastification_brillante_matte")){
		if(document.getElementById("id_plastification").value!="" && document.getElementById("plastification_brillante_matte").value==""){
			contenu="Vous n'avez pas choisi si la plastification est brillante ou matte";
			alert(contenu);
			return false;
		}
		if(document.getElementById("id_plastification").value=="" && document.getElementById("plastification_brillante_matte").value!=""){
			contenu="Vous n'avez pas choisi de type de plastification "+document.getElementById("plastification_brillante_matte").value;
			alert(contenu);
			return false;
		}
	}
	for(var i=0;i<100;i++){
		if(document.getElementById("nombre_"+i)&&document.getElementById("position_"+i)){
			if(!isNaN(parseInt(document.getElementById("nombre_"+i).value)) && parseInt(document.getElementById("nombre_"+i).value)>0 && document.getElementById("position_"+i).value==""){
				contenu="Vous n'avez pas donné de position à une option";
				alert(contenu);
				return false;
			}
			if((isNaN(parseInt(document.getElementById("nombre_"+i).value)) || parseInt(document.getElementById("nombre_"+i).value)<1) && document.getElementById("position_"+i).value!=""){
				contenu="Il manque la quantité d'une option";
				alert(contenu);
				return false;
			}
		}
	}
	if(prix_ttc==""||prix_ttc=="0 ?"){
			contenu="Vous n'avez pas saisi assez d'informations.";
		}
	else if(id_support==""){
		contenu="Vous n'avez pas choisi de support.";
	}
	else if(larg=="" || haut=="" || isNaN(larg) || isNaN(haut)){
			contenu="Vous avez oublié les dimensions.";
		}
	else if(parseInt(larg)*parseInt(haut)/10000*qte < 0.5){
			contenu="Votre commande ne dépasse pas 0.5 m².";
		}
	else if(nom_fichier==""){
			contenu="Vous avez oublié le nom du fichier.";
		}
	else {
		contenu="Voulez-vous ajouter ce produit au panier ?";
		return confirm(contenu);
	}
	alert(contenu);
	return false;
}

function calculCommande(taux){
	var sous_total_commande = parseFloat(document.getElementById("val_sous_total_commande").value);
	var frais_port = document.getElementById("val_frais_port").value;
	var check_frais_port = document.getElementById("check_frais_port").checked;
	var check_forfait_verification= document.getElementById("check_forfait_verification").checked;
	var tmp_total = document.getElementById("val_tmp_total").value;
	var total_commande = parseFloat(document.getElementById("val_total_commande").value);
	var total_tva = document.getElementById("val_total_tva").value;
	if(check_frais_port){
		afficherCacher("fdp_1",1);afficherCacher("frais_port",1);
		afficherCacher("fdp_2",1);afficherCacher("tmp_total",1);
		afficherCacher("total_commande_fdp",0);afficherCacher("total_commande",1);
		document.getElementById("sous_total_commande").value=(Math.round(sous_total_commande*100)/100)+" €";
		document.getElementById("frais_port").value=frais_port+" €";
		if(check_forfait_verification){
			afficherCacher("fdv_1",1); afficherCacher("forfait_verification",1);
			tmp_total=parseFloat(tmp_total)+parseFloat(document.getElementById("val_forfait_verification").value);
			total_commande = tmp_total*(parseFloat(taux)/100+1);
		}
		else {
			afficherCacher("fdv_1",0); afficherCacher("forfait_verification",0);
		}
		document.getElementById("tmp_total").value=tmp_total+" €";
		total_commande=Math.round(total_commande*100)/100;
		total_tva=Math.round(total_commande*100-tmp_total*100)/100;
		document.getElementById("total_commande").value=total_commande+" €";
		document.getElementById("total_tva").value=total_tva+" €";
	}
	else{
		afficherCacher("fdp_1",0);afficherCacher("frais_port",0);
		afficherCacher("fdp_2",0);afficherCacher("tmp_total",0);
		afficherCacher("total_commande_fdp",1);afficherCacher("total_commande",0);
		document.getElementById("sous_total_commande").value=(Math.round(sous_total_commande*100)/100)+" €";
		total_commande=sous_total_commande*(parseFloat(taux)/100+1);
		if(check_forfait_verification){
			afficherCacher("fdv_1",1); afficherCacher("forfait_verification",1);
			afficherCacher("fdp_2",1);afficherCacher("tmp_total",1);
			tmp_total=parseFloat(tmp_total)+parseFloat(document.getElementById("val_forfait_verification").value)-parseFloat(frais_port);
			total_commande = tmp_total*(parseFloat(taux)/100+1);
			total_tva=Math.round(total_commande*100-tmp_total*100)/100;
		}
		else {
			afficherCacher("fdv_1",0); afficherCacher("forfait_verification",0);
			total_tva=Math.round(total_commande*100-sous_total_commande*100)/100;
		}
		document.getElementById("tmp_total").value=tmp_total+" €";
		total_commande=Math.round(total_commande*100)/100;
		total_tva=Math.round(total_tva*100)/100;
		document.getElementById("total_commande_fdp").value=total_commande+" €";
		document.getElementById("total_tva").value=total_tva+" €";
		
	}
}

