// Libellé des taille en UK
var tabtailleUK=new Array;
tabtailleUK["36-38"]="4-5";
tabtailleUK["37-38"]="4.5-5";
tabtailleUK["39-40"]="5.5-6.5";
tabtailleUK["39-41"]="5.5-7";
tabtailleUK["41-42"]="7-8";
tabtailleUK["41-43"]="7-8.5";
tabtailleUK["42-44"]="8-9.5";
tabtailleUK["43-44"]="8.5-9.5";
tabtailleUK["45-46"]="10-11";
tabtailleUK["47-48"]="11.5-12.5";
tabtailleUK["40-46"]="6.5-11";
tabtailleUK["35-38"]="2.5-5";
tabtailleUK["39-42"]="5.5-8";
tabtailleUK["43-45"]="8.5-10";
tabtailleUK["43-46"]="8.5-11";
tabtailleUK["42-43"]="8-8.5";
tabtailleUK["44-45"]="9.5-10";
tabtailleUK["44-46"]="9.5-11";
tabtailleUK["46-48"]="11-12.5";
tabtailleUK["44-48"]="9.5-12.5";
tabtailleUK["42-46"]="8-11";
tabtailleUK["45-47"]="10-12";
tabtailleUK["47-50"]="12-14";
tabtailleUK["49-50"]="13-14";
tabtailleUK["62-68"]="1-6 months";
tabtailleUK["74-80"]="12-16 months";
tabtailleUK["50-56"]="0-1 months";

// Libelle des tailles en USA
var tabtailleUSA=new Array;
tabtailleUSA["36-38"]="5-6";
tabtailleUSA["37-38"]="5.5-6";
tabtailleUSA["39-40"]="6.5-7.5";
tabtailleUSA["39-41"]="6.5-8";
tabtailleUSA["41-42"]="8-9";
tabtailleUSA["41-43"]="8-9.5";
tabtailleUSA["42-44"]="9-10.5";
tabtailleUSA["43-44"]="9.5-10.5";
tabtailleUSA["45-46"]="11-12";
tabtailleUSA["47-48"]="12.5-13.5";
tabtailleUSA["40-46"]="7.5-12";
tabtailleUSA["35-38"]="3.5-6";
tabtailleUSA["39-42"]="6.5-9";
tabtailleUSA["43-45"]="9.5-11";
tabtailleUSA["43-46"]="9.5-12";
tabtailleUSA["42-43"]="9-9.5";
tabtailleUSA["44-45"]="10.5-11";
tabtailleUSA["44-46"]="10.5-12";
tabtailleUSA["46-48"]="12-13.5";
tabtailleUSA["44-48"]="10.5-13.5";
tabtailleUSA["42-46"]="9-12";
tabtailleUSA["45-47"]="11-13";
tabtailleUSA["47-50"]="13-15";
tabtailleUSA["49-50"]="14-15";
tabtailleUSA["62-68"]="1-6 months";
tabtailleUSA["74-80"]="12-16 months";
tabtailleUSA["50-56"]="0-1 months";

		var msgPas = "" ;
		var msgT = "" ;
		
	function verify_association(x){
		var choix = new Array() ;
		
		var z1 ;
		var z ;
		var message ;
		var i ;
		
		if(x==0){
			for(i = 0;i<couleur.length;i++){
				document.mf["couleur"+couleur[i]].disabled = true ;
				document.mf["couleur"+couleur[i]].selectedIndex = 0 ;
				document.mf.tailleUK.value='';
				document.mf.tailleUSA.value='';
				z1 = document.getElementById(["couleurlbl"+couleur[i]]) ;
				z1.innerHTML = "&nbsp;" ;
			}
		}else{
			document.mf.tailleUK.value=tabtailleUK[tailles[x]];
			document.mf.tailleUSA.value=tabtailleUSA[tailles[x]];
			if (document.mf.tailleUK.value=="undefined") { document.mf.tailleUK.value=""; }
			if (document.mf.tailleUSA.value=="undefined") { document.mf.tailleUSA.value=""; }
	
			for(i = 0;i<couleur.length;i++){
				document.mf["couleur"+couleur[i]].disabled = true ;
				choix[couleur[i]] = document.mf["couleur"+couleur[i]].selectedIndex ;
				document.mf["couleur"+couleur[i]].selectedIndex = 0 ;
				var z = document.getElementById(["couleurlbl"+couleur[i]]) ;
				z.innerHTML = "&nbsp;" ;
			}
			
			for (var propriete in taille[x]){
				document.mf["couleur"+taille[x][propriete]].disabled = false ;
				document.mf["couleur"+taille[x][propriete]].selectedIndex = choix[taille[x][propriete]] ;
				/*
				for(var y=1;y<19;y++){
					document.mf["couleur"+taille[x][propriete]].options[y] = null ;
				}
				
				for(var y=1;y<19;y++){
					
				}
				*/
			}
		}
		construction() ;
		verify_stock_and_pricing() ;
	}
	
	function construction(){
		var t = document.getElementById("taille") ;
		var x = t.options[t.selectedIndex].id ;
		
		var z ;
		for (var propriete in taille[x]){
			var coul = taille[x][propriete] ;
			var min = minim[x][[taille[x][propriete]]] ; 
			gestionMultiOption(min,coul) ;
		}
		
	}
	
	var optio = new Array() ;
	optio[0] = 0 ;
	optio[1] = 1 ;
	optio[2] = 2 ;
	optio[3] = 3 ;
	optio[4] = 4 ;
	optio[5] = 5 ;
	optio[6] = 6 ;
	optio[7] = 7 ;
	optio[8] = 8 ;
	optio[9] = 9 ;
	optio[10] = 10 ;
	optio[11] = 12 ;
	optio[12] = 15 ;
	optio[13] = 20 ;
	/*optio[14] = 30 ;
	optio[15] = 40 ;
	optio[16] = 50 ;
	optio[17] = 75 ;
	optio[18] = 100 ;*/
	
	function gestionMultiOption(min,coul){
		videOption(coul) ;
		var i ;
		nouvel_element = new Option(0,0,true,true);
 		document.mf["couleur"+coul].options[document.mf["couleur"+coul].length] = nouvel_element;
		for(i=1;i<19;i++){
			if(optio[i]>=min){
				optionListAdd(optio[i],coul) ;
			}
		}
	}

	function videOption(coul){
		var i ;
		var z ;
		for(i=0;i<=19;i++){
			z = document.mf["couleur"+coul].length ;
			if(z-1 >= 0){
				effacer(coul) ;
			}
		}
	}

	function effacer(coul){
		var z = document.mf["couleur"+coul].length-1 ;
 		document.mf["couleur"+coul].options[z] = null;
	}

	function optionListAdd(nb,coul){
 		nouvel_element = new Option(nb,nb,false,false);
 		document.mf["couleur"+coul].options[document.mf["couleur"+coul].length] = nouvel_element;
	}
	
	function verify_stock_and_pricing(){
		var t = document.getElementById("taille") ;
		var x = t.options[t.selectedIndex].id ;
		var qtyz ;
		var qtyCol ;
		var z ;
		for (var propriete in taille[x]){
			qtyz = document.mf["couleur"+taille[x][propriete]].selectedIndex ;
			qtyCol = document.mf["couleur"+taille[x][propriete]].options[qtyz].value ;
			message = msgEnStock ;
			if(stock[x][[taille[x][propriete]]]['qty']<qtyCol){
				message = stock[x][[taille[x][propriete]]]['outOf'] ;
			}
			if(stock[x][[taille[x][propriete]]]['qty']<=0){
				message = stock[x][[taille[x][propriete]]]['outOf'] ;
			}
			if(qtyCol==0){
				message = "" ;
			}
			z = document.getElementById(["couleurlbl"+taille[x][propriete]]) ;
			z.innerHTML = message ;	
		}
		calculePrix() ;
	}
	
	function affichage(para)
		{
			testleftm = parseInt(para);
			testright = para - testleftm;
			fixright = (Math.round(testright*100))/100;
			if (fixright)
			{
				if (fixright*100 % 10)
				{
					return ( eval(testleftm)+eval(fixright) );
				}
				else
				{
					return (eval(testleftm)+eval(fixright) + '0');
				}
			}
			else
			{
				return (eval(testleftm)+eval(fixright) + '.00');
			}
		} 
		
	function change_typeoffre(valeur)
		{
			var x = document.getElementById("extended");
			if (valeur==1)
			{
				document.forms["mf"].elements["periodicite2"].disabled=true;	
				document.forms["mf"].elements["duree2"].disabled=true;
				x.style.display = "none";
			}
			else if (valeur==2)
			{
				document.forms["mf"].elements["periodicite2"].disabled=false;	
				document.forms["mf"].elements["duree2"].disabled=false;
				x.style.display = "block";
			}
			calculePrix() ;
		}
		
		function type_offre_cochee()
		{
			for ( i = 0 ; i < document.forms["mf"].length ; i++)
			{
				if ( document.forms["mf"].elements[i].name == "type_offre" ) 
				{
					if ( document.forms["mf"].elements[i].checked == true )
					{
						return (document.forms["mf"].elements[i].value);	
					}
				}
			}
		}
		
		
	function calculePrix(){

		if (document.forms["mf"].elements["bon_cadeau"].value==0) { 
		
			var t = document.getElementById("taille") ;
			var tailleD = t.options[t.selectedIndex].id ;
			var d = document.getElementById("devise") ;
			devise = d.options[d.selectedIndex].value ;
			var total = 0 ;
			var qtyCol ;
			var thisCol ;
			var associate ;
			var d2 ;
			var code_commande = "" ;
			var thisPrix ;
			var totalDevise ;
			var qtyz ;
			var p ;
			
			var type_offre = type_offre_cochee() ;
			if (type_offre==1){ 
				var periodicite = document.forms["mf"].elements["periodicite1"].value;
				var duree = document.forms["mf"].elements["duree1"].value;
			}
			else if (type_offre==2){ 
				var periodicite = document.forms["mf"].elements["periodicite2"].value;
				var duree = document.forms["mf"].elements["duree2"].value;
			}		
		
			for (var propriete in taille[tailleD]){
				qtyz = document.mf["couleur"+taille[tailleD][propriete]].selectedIndex ;
				qtyCol = document.mf["couleur"+taille[tailleD][propriete]].options[qtyz].value ;
				thisCol = taille[tailleD][propriete] ;
				associate = thisCol+"#"+tailleD ;
				thisPrix = Math.round((price[associate][devise]*qtyCol * (12 / periodicite) * duree) * 20) / 20 ;
				total += thisPrix ;
				if(qtyCol>0){
					code_commande += associate+"|"+qtyCol+"|"+price[associate][devise]+"@" ;
				}
			}

			p = document.getElementById('prix_client') ;
			p.value = affichage(total) ;
			
			var cut = (code_commande.length)-1 ;
			code_commande = code_commande.substring(0,cut) ;
			var cod = document.getElementById('code_commande') ;
			cod.value = code_commande ;
			
			for (var i=0;i<4;i++){
				totalDevise = 0 ;
				for (var propriete in taille[tailleD]){
					qtyz = document.mf["couleur"+taille[tailleD][propriete]].selectedIndex ;
					qtyCol = document.mf["couleur"+taille[tailleD][propriete]].options[qtyz].value ;
					thisCol = taille[tailleD][propriete] ;
					associate = thisCol+"#"+tailleD ;
					totalDevise += Math.round((price[associate][devises[i]]*qtyCol * (12 / periodicite) * duree) * 20) / 20 ; 
				}
				d2 = document.getElementById(['prix_'+devises[i]]) ;
				d2.value = affichage(totalDevise) ;
			}
		}
		else { 
			
			qty = document.forms["mf"].elements["qteBon"].value ;
			prix_chf = document.forms["mf"].elements["prix_chf"].value ;
			total = qty * prix_chf ;
			p = document.getElementById('prix_client') ;
			p.value = affichage(total) ;
			
			/*total = 0 ;
			p = document.getElementById('prix_client') ;
			p.value = affichage(total) ;
			totalDevise = 0 ;
			for (var i=0;i<4;i++){
				d2 = document.getElementById(['prix_'+devises[i]]) ;
				d2.value = affichage(totalDevise) ;
			}*/
			var codi = document.getElementById('code_commande') ;
			codi.value = "aucun|"+qty+"|"+prix_chf ;
		}
		
		if (total>0) { 
			document.forms["mf"].elements["ajout"].disabled=false; 
		}
		else { 
			document.forms["mf"].elements["ajout"].disabled=true; 
		}
	}		

