// JavaScript Document



function getXhr(){
    var xhr = null; 
	if(window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer
	   try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	} else { // XMLHttpRequest non supporté par le navigateur 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		xhr = false; 
	} 
    return xhr;
}


//espace ambassadrice, passer d'une étape à l'autre
function cmdsuivant(cacher, afficher) {
	document.getElementById(cacher).style.display = "none";
	document.getElementById(afficher).style.display = "block";
}



function recapitulatif() {
	var toti = document.forms['tabambas'].elements['nbrechamps'].value;
	var contenu = '';
	contenu += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"tabambas\">";
	contenu += "<tr><th width=\"50\">Ref</th> <th width=\"110\">Designation articles</th> <th width=\"40\">Taille</th> <th width=\"15\">Couleur</th> <th width=\"18\">Qte</th> <th width=\"40\">P.U.</th> <th width=\"40\">Rem %</th> <th width=\"55\">Total ttc</th> <th width=\"18\">Qte</th> <th width=\"40\">P.U.</th> <th width=\"55\">Total ttc</th> <th width=\"18\">Qte</th> <th width=\"40\">P.U.</th> <th width=\"55\">Total ttc</th> </tr>";
	
	for(var i = 1; i != toti; i++) {
		if(document.forms['tabambas'].elements['ref'+i] && document.forms['tabambas'].elements['ref'+i].value != "") {
			contenu += '<tr>';
			contenu += '<td align="center">'+document.forms['tabambas'].elements['ref'+i].value+'</td>';
			contenu += '<td>'+document.forms['tabambas'].elements['design'+i].value+'</td>';
			contenu += '<td align="center">'+document.forms['tabambas'].elements['taille'+i].value+'</td>';
			contenu += '<td align="center"><img src="images/spacer.gif" style="background-color:'+document.forms['tabambas'].elements['couleur'+i].value+'; width:10px; height:12px; margin:0 2px; border:solid 2px #E0E0E0;"></td>';
			contenu += '<td align="center">'+document.forms['tabambas'].elements['cqte'+i].value+'</td>';
			contenu += '<td align="right">'+document.forms['tabambas'].elements['cpu'+i].value+' €</td>';
			contenu += '<td align="center">'+document.forms['tabambas'].elements['cremise'+i].value+' %</td>';
			contenu += '<td align="right">'+document.forms['tabambas'].elements['ctotal'+i].value+' €</td>';
			contenu += '<td align="center">'+document.forms['tabambas'].elements['hqte'+i].value+'</td>';
			contenu += '<td align="right">'+document.forms['tabambas'].elements['hpu'+i].value+' €</td>';
			contenu += '<td align="right">'+document.forms['tabambas'].elements['htotal'+i].value+' €</td>';
			contenu += '<td align="center">'+document.forms['tabambas'].elements['aqte'+i].value+'</td>';
			contenu += '<td align="right">'+document.forms['tabambas'].elements['apu'+i].value+' €</td>';
			contenu += '<td align="right">'+document.forms['tabambas'].elements['atotal'+i].value+' €</td>';
			contenu += '</tr>';
		} //fin if
	}//fin for

	for(var j = i; j != (toti+5); j++) {
		if(document.forms['tabambas'].elements['ref'+j] && document.forms['tabambas'].elements['ref'+j].value != "") {
			contenu += '<tr>';
			contenu += '<td align="center">'+document.forms['tabambas'].elements['ref'+j].value+'</td>';
			contenu += '<td>'+document.forms['tabambas'].elements['design'+j].value+'</td>';
			contenu += '<td align="center">'+document.forms['tabambas'].elements['taille'+j].value+'</td>';
			contenu += '<td align="center"><img src="images/spacer.gif" style="background-color:'+document.forms['tabambas'].elements['couleur'+j].value+'; width:10px; height:12px; margin:0 2px; border:solid 2px #E0E0E0;"></td>';
			contenu += '<td align="center">&nbsp;</td>';
			contenu += '<td align="right">&nbsp;</td>';
			contenu += '<td align="center">&nbsp;</td>';
			contenu += '<td align="right">&nbsp;</td>';
			contenu += '<td align="center">'+document.forms['tabambas'].elements['hqte'+j].value+'</td>';
			contenu += '<td align="right">'+document.forms['tabambas'].elements['hpu'+j].value+' €</td>';
			contenu += '<td align="right">'+document.forms['tabambas'].elements['htotal'+j].value+' €</td>';
			contenu += '<td align="center">&nbsp;</td>';
			contenu += '<td align="right">&nbsp;</td>';
			contenu += '<td align="right">&nbsp;</td>';
			contenu += '</tr>';
		} //fin if
	}//fin for
	contenu += "</table><br /><br />";
	
	//aides à la vente
	contenu += '<table cellpadding="0" cellspacing="0" border="0" class="tabambas">';
	contenu += '<tr>';
	contenu += '<th width="200">Designation articles</th>';
	contenu += '<th width="50">Qte</th>';
	contenu += '<th width="50">P.U.</th>';
	contenu += '<th width="60">Total ttc</th>';
	contenu += '</tr>';
	
	var aideliste = document.forms['tabambas'].elements['listidaide'].value.split('-');

	for(var k = 0; k != aideliste.length; k++) {
		if(document.forms['tabambas'].elements['aideqte'+k]) {
			if(document.forms['tabambas'].elements['aideqte'+k].value > 0) {
				contenu += '<tr>';
				contenu += '<td>'+document.forms['tabambas'].elements['designaide'+k].value+'</td>';
				contenu += '<td align="center">'+document.forms['tabambas'].elements['aideqte'+k].value+'</td>';
				contenu += '<td align="right">'+document.forms['tabambas'].elements['aidepu'+k].value+' €</td>';
				contenu += '<td align="right">'+document.forms['tabambas'].elements['aidetot'+k].value+' €</td>';
				contenu += '</tr>';
			}//fin if > 0
		} // fin if
	}//fin for aide	
	
	contenu += '<tr>';
	contenu += '<th colspan="3" align="right">Total aides</th>';
	contenu += '<th align="right">'+document.forms['tabambas'].elements['totalaides'].value+' €</th>';
	contenu += '</tr>';	
	contenu += '<tr>';
	contenu += '<td>&nbsp;</td>';//report du total A tableau caché
	contenu += '<th colspan="2" align="right">Report total ttc A :</th>';
	contenu += '<th align="right">'+document.forms['tabambas'].elements['totala2'].value+' €</th>';
	contenu += '</tr>';
	contenu += '<td>&nbsp;</td>';//report du total B tableau caché
	contenu += '<th colspan="2" align="right">Report total ttc B :</th>';
	contenu += '<th align="right">'+document.forms['tabambas'].elements['totalb2'].value+' €</th>';
	contenu += '</tr>';
	contenu += '<tr>';
	contenu += '<td>&nbsp;</td>';
	contenu += '<th colspan="2" align="right">Report total ttc C :</th>';//report du total C tableau caché
	contenu += '<th align="right">'+document.forms['tabambas'].elements['totalc2'].value+' €</th>';
	contenu += '</tr>';
	//frais de port à saisir
	contenu += '<tr class="margeplus">';
	contenu += '<td align="right" colspan="3">Frais de port :</td>';
	contenu += '<td align="right">'+document.forms['tabambas'].elements['fraisport'].value+' €</td>';
	contenu += '</tr>';
	contenu += '<tr>';//total TTC = A+b+c+aides+port
	contenu += '<th align="right" colspan="3">Total a payer :</th>';
	contenu += '<th align="right">'+document.forms['tabambas'].elements['prixtotalttc'].value+' €</th>';
	contenu += '</tr>';
	contenu += "</table>";	
	
	return document.getElementById('etape3').innerHTML = contenu + document.getElementById('etape3fin').innerHTML;
}



/*** tableau ambassadrice ***/
function retourndesign(i, sel) {
	var reference = document.forms['tabambas'].elements['ref'+i].value;
	if(reference != '') {
		//désignation articles
		var xhr = getXhr();			
		xhr.open("GET","httprequest/tabambas.php?ref="+reference+"&indice="+i+"&lang="+lang+"&sel="+sel,false);
		xhr.send(null);		
		
		if(xhr.responseText) {
			var contenu = xhr.responseText;
			contenu = contenu.split('___');
			document.getElementById('design'+i).innerHTML = contenu[0];
			document.getElementById('taille'+i).innerHTML = contenu[1];
			document.getElementById('clr'+i).innerHTML = contenu[2];
			document.forms['tabambas'].elements['couleur'+i].value = contenu[3];
			document.forms['tabambas'].elements['cpu'+i].style.color = '#000000';
			document.forms['tabambas'].elements['hpu'+i].style.color = '#000000';
			document.forms['tabambas'].elements['apu'+i].style.color = '#000000';
			document.forms['tabambas'].elements['cpu'+i].value = parseFloat(contenu[4]).toFixed(1);
			document.forms['tabambas'].elements['hpu'+i].value = parseFloat(contenu[4]).toFixed(1);
			document.forms['tabambas'].elements['apu'+i].value = parseFloat(contenu[4]).toFixed(1);
			
			if(contenu[5] == 1) //la ref n'existe pas
				document.forms['tabambas'].elements['ref'+i].value = '';
			
		} // fin if
		xhr.abort();
	} // fin if
	
	//verifdoublon(i);	
} // fin function retourndesign()

/*** tableau ambassadrice PRODUITS REMISES ***/
function retourndesignrem(i, sel) {
	var reference = document.forms['tabambas'].elements['ref'+i].value;
	var remisepou = document.forms['tabambas'].elements['remisepour'].value;
	if(reference != '') {
		//désignation articles
		var xhr = getXhr();			
		xhr.open("GET","httprequest/tabambas.php?ref2="+reference+"&indice2="+i+"&lang2="+lang+"&sel2="+sel+"&remise="+remisepou,false);
		xhr.send(null);		
		
		if(xhr.responseText) {
			var contenu = xhr.responseText;
			contenu = contenu.split('___');
			document.getElementById('design'+i).innerHTML = contenu[0];
			document.getElementById('taille'+i).innerHTML = contenu[1];
			document.getElementById('clr'+i).innerHTML = contenu[2];
			document.forms['tabambas'].elements['couleur'+i].value = contenu[3];
			document.forms['tabambas'].elements['hpu'+i].style.color = '#000000';
			document.forms['tabambas'].elements['hpu'+i].value = parseFloat(contenu[4]).toFixed(1);
			
			if(contenu[5] == 1) //la ref n'existe pas
				document.forms['tabambas'].elements['ref'+i].value = '';
			
		} // fin if
		xhr.abort();
	} // fin if
	
	//verifdoublon(i);	
} // fin function retourndesignrem()


/*
//------------- Vérifie si le même produit avec les mêmes préférences (taille, âge couleur) n'est pas resaisi---------
function verifdoublon(i) {
	var compte = 0;
	var reference  = document.forms['tabambas'].elements['ref'+i].value;
	var reftaille  = document.forms['tabambas'].elements['taille'+i].value;
	var refcouleur = document.forms['tabambas'].elements['couleur'+i].value;
	for(var j = 1; j <= 5; j++) {
	
		alert(reference+' - '+document.forms['tabambas'].elements['ref'+j].value+'\n'+
			reftaille+' - '+document.forms['tabambas'].elements['taille'+j].value+'\n'+
			refcouleur+' - '+document.forms['tabambas'].elements['couleur'+j].value);
			
		if(reference == document.forms['tabambas'].elements['ref'+j].value &&
			reftaille == document.forms['tabambas'].elements['taille'+j].value &&
			refcouleur == document.forms['tabambas'].elements['couleur'+j].value) {
			
			compte++;
			if(compte > 1) {
				alert("Vous avez déjà saisi ce produit");
				document.forms['tabambas'].elements['ref'+j].value = '';
				document.forms['tabambas'].elements['design'+j].value = '';
			}
			
		}
	}//fin for
}
*/


/*** COULEUR SELECTIONNEE TABLEAU AMBASSADRICE ***/
function selecoul(couleur, i, selectionne, prix) {
	document.forms['tabambas'].elements['couleur'+i].value = couleur;	

	for(var plus = 1; plus <= 3; plus++) {
		if(document.getElementById(i+'_'+plus)) {
			document.getElementById(i+'_'+plus).style.border = "solid 2px #E0E0E0";						
		}
	}
	
	document.getElementById(i+'_'+selectionne).style.border = "solid 2px #FF861A";		
	//document.forms['tabambas'].elements['cpu'+i].value = prix.toFixed(1);	
	//document.forms['tabambas'].elements['hpu'+i].value = prix.toFixed(1);	
	//document.forms['tabambas'].elements['apu'+i].value = prix.toFixed(1);	
	//prixunit(i);
}



function prixunit(i, champ, champ2, champ3) {
	document.forms['tabambas'].elements[champ2+i].value = document.forms['tabambas'].elements[champ+i].value;
	document.forms['tabambas'].elements[champ3+i].value = document.forms['tabambas'].elements[champ+i].value;
	
	document.forms['tabambas'].elements['cpu'+i].style.color = '#000000';
	document.forms['tabambas'].elements['hpu'+i].style.color = '#000000';
	document.forms['tabambas'].elements['apu'+i].style.color = '#000000';
	document.forms['tabambas'].elements['ctotal'+i].style.color = '#000000';
	document.forms['tabambas'].elements['htotal'+i].style.color = '#000000';
	document.forms['tabambas'].elements['atotal'+i].style.color = '#000000';
	
	
	//--------------------------------------total client A
	var cqte = document.forms['tabambas'].elements['cqte'+i].value.split('.');
	cqte = cqte[0];
	document.forms['tabambas'].elements['cqte'+i].value = cqte;
	var cpu = document.forms['tabambas'].elements['cpu'+i].value;
	var crem = document.forms['tabambas'].elements['cremise'+i].value;
	
	if(crem > 0) {
		var prixcremise = parseFloat(cpu*crem/100);
		cpu -= prixcremise;
		cpu = cpu.toFixed(1);
	}
	
	document.forms['tabambas'].elements['ctotal'+i].value = (cqte * cpu).toFixed(1);
	document.forms['tabambas'].elements['htotal'+i].value = (document.forms['tabambas'].elements['hpu'+i].value * document.forms['tabambas'].elements['hqte'+i].value).toFixed(1);
	document.forms['tabambas'].elements['atotal'+i].value = (document.forms['tabambas'].elements['apu'+i].value * document.forms['tabambas'].elements['aqte'+i].value).toFixed(1);
}




/***AFFICHAGE PRIX UNITAIRE ***/
function prixunit2(i) {
	var reference = document.forms['tabambas'].elements['ref'+i].value;

	if(reference != '') {
		//désignation articles
		var taille = document.forms['tabambas'].elements['taille'+i].value;
		var xhr = getXhr();			
		xhr.open("GET","httprequest/tabambas.php?ref="+reference+"&ind="+i+"&taille="+taille,false);
		xhr.send(null);		
		if(xhr.responseText) {
			var contenu = xhr.responseText;
			contenu = contenu.split('___');
			document.getElementById('clr'+i).innerHTML = contenu[0];
			document.forms['tabambas'].elements['couleur'+i].value = contenu[1];
			document.forms['tabambas'].elements['cpu'+i].value = parseFloat(contenu[2]).toFixed(1);
			document.forms['tabambas'].elements['hpu'+i].value = parseFloat(contenu[2]).toFixed(1);
			document.forms['tabambas'].elements['apu'+i].value = parseFloat(contenu[2]).toFixed(1);
			xhr.abort();
		} // fin if
	}
}


/***AFFICHAGE PRIX UNITAIRE REMISE ***/
function prixunit2rem(i) {
	var reference = document.forms['tabambas'].elements['ref'+i].value;

	if(reference != '') {
		//désignation articles
		var taille = document.forms['tabambas'].elements['taille'+i].value;
		var pourcentage = document.forms['tabambas'].elements['remisepour'].value;
		var xhr = getXhr();			
		xhr.open("GET","httprequest/tabambas.php?ref="+reference+"&ind="+i+"&taille="+taille,false);
		xhr.send(null);		
		if(xhr.responseText) {
			var contenu = xhr.responseText;
			contenu = contenu.split('___');
			document.getElementById('clr'+i).innerHTML = contenu[0];
			document.forms['tabambas'].elements['couleur'+i].value = contenu[1];			
			var nouvpu = contenu[2] - ((contenu[2] * pourcentage)/100); // moins pourcentage remise			
			document.forms['tabambas'].elements['hpu'+i].value = parseFloat(nouvpu).toFixed(1);
			xhr.abort();
		} // fin if
	}
}





/*** TOTAL DE CHAQUE LIGNE TABLEAU AMBASSADRICE ***/
function totalchacun(i) {

	//--------------------------------------total client A
	var cqte = document.forms['tabambas'].elements['cqte'+i].value.split('.');
	cqte = cqte[0];
	document.forms['tabambas'].elements['cqte'+i].value = cqte;
	var cpu = document.forms['tabambas'].elements['cpu'+i].value;
	var crem = document.forms['tabambas'].elements['cremise'+i].value;
	
	if(crem > 0) {
		var prixcremise = parseFloat(cpu*crem/100);
		cpu -= prixcremise;
		cpu = cpu.toFixed(1);
	}
	
	document.forms['tabambas'].elements['ctotal'+i].value = (cqte * cpu).toFixed(1);
	
	if(document.forms['tabambas'].elements['cqte'+i].value != 0) 
		document.forms['tabambas'].elements['cqte'+i].style.color = '#000000';
	else
		document.forms['tabambas'].elements['cqte'+i].style.color = '#828485';
		
	if(document.forms['tabambas'].elements['cremise'+i].value != 0) 
		document.forms['tabambas'].elements['cremise'+i].style.color = '#000000';
	else
		document.forms['tabambas'].elements['cremise'+i].style.color = '#828485';

	
	//--------------------------------------total hotesse B
	var hqte = document.forms['tabambas'].elements['hqte'+i].value.split('.');
	hqte = hqte[0];
	document.forms['tabambas'].elements['hqte'+i].value = hqte;
	var hpu = document.forms['tabambas'].elements['hpu'+i].value; 
	
	document.forms['tabambas'].elements['htotal'+i].value = (hqte * hpu).toFixed(1);
	if(document.forms['tabambas'].elements['hqte'+i].value != 0) 
		document.forms['tabambas'].elements['hqte'+i].style.color = '#000000';
	else 
		document.forms['tabambas'].elements['hqte'+i].style.color = '#828485';
	
	//--------------------------------------total ambassadrice C
	var aqte = document.forms['tabambas'].elements['aqte'+i].value.split('.');
	aqte = aqte[0];
	document.forms['tabambas'].elements['aqte'+i].value = aqte;
	
	var apu = document.forms['tabambas'].elements['apu'+i].value; 
	document.forms['tabambas'].elements['atotal'+i].value = (aqte * apu).toFixed(1);
	if(document.forms['tabambas'].elements['aqte'+i].value != 0) {
		document.forms['tabambas'].elements['aqte'+i].style.color = '#000000';
	} else {
		document.forms['tabambas'].elements['aqte'+i].style.color = '#828485';
	}
	
	//------------------------------- vérification stock disponible 
	var qtectot = 0;
	var qtehtot = 0;
	var qteatot = 0;
	
	var nbre_champ = document.forms['tabambas'].elements['nbrechamps'].value;
	var refac = document.forms['tabambas'].elements['ref'+i].value;
	var tailleac = document.forms['tabambas'].elements['taille'+i].value;
	var couleurac = document.forms['tabambas'].elements['couleur'+i].value;
	
	for(var j = 1; j != nbre_champ; j++) {
		if(document.forms['tabambas'].elements['ref'+j] && (document.forms['tabambas'].elements['ref'+j].value == refac) && (document.forms['tabambas'].elements['taille'+j].value == tailleac) && (document.forms['tabambas'].elements['couleur'+j].value == couleurac)) {		
			qtectot += parseFloat(document.forms['tabambas'].elements['cqte'+j].value);
			qtehtot += parseFloat(document.forms['tabambas'].elements['hqte'+j].value);
			qteatot += parseFloat(document.forms['tabambas'].elements['aqte'+j].value);	
		}
	}
	
	var qtetot = parseFloat(qtectot + qtehtot + qteatot);
	var nouvcoul = couleurac.replace('#', '');
	
	var xhr = getXhr();			
	xhr.open("GET","httprequest/tabambas.php?ref="+refac+"&taille="+tailleac+"&couleur="+nouvcoul+"&qte="+qtetot,false);
	xhr.send(null);		
	if(xhr.responseText) {
		var contenu = xhr.responseText;
		contenu = contenu.split('___');
		if(contenu[0] < 0) 
			alert("Vous dépassez le stock disponible.\nIl reste "+contenu[1]+" article(s)\nVous en commandez "+contenu[2]+" de trop");
		xhr.abort();
	} // fin if
	
	if(document.forms['tabambas'].elements['totala']) 
		totalcolonne(0);
}





/*** TOTAL DE CHAQUE LIGNE TABLEAU AMBASSADRICE ***/
function totalchacunrem(i) {
	
	//--------------------------------------total hotesse B
	var hqte = document.forms['tabambas'].elements['hqte'+i].value.split('.');
	hqte = hqte[0];
	document.forms['tabambas'].elements['hqte'+i].value = hqte;
	var hpu = document.forms['tabambas'].elements['hpu'+i].value; 
	
	document.forms['tabambas'].elements['htotal'+i].value = (hqte * hpu).toFixed(1);
	if(document.forms['tabambas'].elements['hqte'+i].value != 0) {
		document.forms['tabambas'].elements['hqte'+i].style.color = '#000000';
		document.forms['tabambas'].elements['htotal'+i].style.color = '#000000';
	} else {
		document.forms['tabambas'].elements['hqte'+i].style.color = '#828485';
		document.forms['tabambas'].elements['htotal'+i].style.color = '#828485';
	}
	
	//------------------------------- vérification stock disponible 
	var qtehtot = 0;
	
	var nbre_champ = document.forms['tabambas'].elements['nbrechamps'].value;
	var refac = document.forms['tabambas'].elements['ref'+i].value;
	var tailleac = document.forms['tabambas'].elements['taille'+i].value;
	var couleurac = document.forms['tabambas'].elements['couleur'+i].value;
	
	for(var j = 1; j != nbre_champ; j++) {
		if(document.forms['tabambas'].elements['ref'+j] && (document.forms['tabambas'].elements['ref'+j].value == refac) && (document.forms['tabambas'].elements['taille'+j].value == tailleac) && (document.forms['tabambas'].elements['couleur'+j].value == couleurac)) {		
			qtehtot += parseFloat(document.forms['tabambas'].elements['hqte'+j].value);
		}
	}
	
	var qtetot = parseFloat(qtehtot);
	var nouvcoul = couleurac.replace('#', '');
	
	var xhr = getXhr();			
	xhr.open("GET","httprequest/tabambas.php?ref="+refac+"&taille="+tailleac+"&couleur="+nouvcoul+"&qte="+qtetot,false);
	xhr.send(null);		
	if(xhr.responseText) {
		var contenu = xhr.responseText;
		contenu = contenu.split('___');
		if(contenu[0] < 0) 
			alert("Vous dépassez le stock disponible.\nIl reste "+contenu[1]+" article(s)\nVous en commandez "+contenu[2]+" de trop");
		xhr.abort();
	} // fin if
	
		
	if(document.forms['tabambas'].elements['totalb']) 
		totalcolonne(1);//calcul des totaux sans appeler l'AJAX
	
}//fin totalchacunrem()


//frais de port selon FRANCE ou étranger
function fraisportpays() {
	var total  = parseFloat(document.forms['tabambas'].elements['totala2'].value);
		total += parseFloat(document.forms['tabambas'].elements['totalb2'].value);
		total += parseFloat(document.forms['tabambas'].elements['totalc2'].value);
		
	if(document.forms['tabambas'].elements['paysport'].checked == true) {
		if(total < 200)
			document.forms['tabambas'].elements['fraisport'].value = 20;
		else if(total > 400)
			document.forms['tabambas'].elements['fraisport'].value = 0;
		else 
			document.forms['tabambas'].elements['fraisport'].value = 10;
	} else {
		if(total < 200)
			document.forms['tabambas'].elements['fraisport'].value = 10;
		else 
			document.forms['tabambas'].elements['fraisport'].value = 0;	
	}
	totalttccmd(); //on recalcul le total
}






//va chercher le montant de la réduction selon le numéro de bon saisi
function verifbonreduc() {
	var bona = document.forms['tabambas'].elements['reduca'].value;
	var bonb = document.forms['tabambas'].elements['reducb'].value;
	var xhr = getXhr();			
	xhr.open("GET","httprequest/tabambas.php?bona="+bona+"&bonb="+bonb,false);
	xhr.send(null);		
	if(xhr.responseText) {
		var contenu = xhr.responseText;
		contenu = contenu.split('___');
		//case A
		if(contenu[3] == 1 && bona != '')
			document.getElementById('bonreduca').innerHTML = '<input type="text" class="designprod" name="reduca" value="code incorrect">';	
		else if(bona == '')	
			document.getElementById('bonreduca').innerHTML = '<input type="text" class="designprod" name="reduca">';	
		else {
			document.getElementById('bonreduca').innerHTML  = '<input type="hidden" name="reduca" value="'+bona+'">';
			document.getElementById('bonreduca').innerHTML += contenu[0];
			document.getElementById('bonreduca').innerHTML += '<input type="hidden" name="reducav" value="'+contenu[0]+'">';
			document.getElementById('bonreduca').innerHTML += '<input type="hidden" name="reducam" value="'+contenu[1]+'">';
			document.getElementById('bonreduca').innerHTML += '<input type="hidden" name="reducat" value="'+contenu[2]+'">';
		}		
		//case B
		if(contenu[7] == 1 && bonb != '')
			document.getElementById('bonreducb').innerHTML = '<input type="text" class="designprod" name="reducb" value="code incorrect">';	
		else if(bonb == '')	
			document.getElementById('bonreducb').innerHTML = '<input type="text" class="designprod" name="reducb">';	
		else {
			document.getElementById('bonreducb').innerHTML  = '<input type="hidden" name="reducb" value="'+bonb+'">';
			document.getElementById('bonreducb').innerHTML += contenu[4];
			document.getElementById('bonreducb').innerHTML += '<input type="hidden" name="reducbv" value="'+contenu[4]+'">';
			document.getElementById('bonreducb').innerHTML += '<input type="hidden" name="reducbm" value="'+contenu[5]+'">';
			document.getElementById('bonreducb').innerHTML += '<input type="hidden" name="reducbt" value="'+contenu[6]+'">';
		}
		
		if(contenu[7] == 0 && contenu[3] == 0) //le bouton "ok" n'existe plus
			document.getElementById('bonbtnab').innerHTML = '';

		xhr.abort();
	}
	
	totalcolonne(1);
}




/*** TOTAL DE CHAQUE COLONNE ---- A ---- B ----  C ---- TABLEAU AMBASSADRICE ***/
function totalcolonne(etape) {

	var totalclient = 0;
	var totalclientbas = 0;
	var totalhotesse = 0;
	var totalambas = 0;
	
	var nbre_champ = document.forms['tabambas'].elements['nbrechamps'].value;
	
	for(var i = 1; i != nbre_champ; i++) {
		if(document.forms['tabambas'].elements['ctotal'+i]) totalclient += parseFloat(document.forms['tabambas'].elements['ctotal'+i].value);
		if(document.forms['tabambas'].elements['ctotal'+i]) totalclientbas += parseFloat(document.forms['tabambas'].elements['ctotal'+i].value);
		if(document.forms['tabambas'].elements['htotal'+i]) totalhotesse += parseFloat(document.forms['tabambas'].elements['htotal'+i].value);
		if(document.forms['tabambas'].elements['atotal'+i]) totalambas += parseFloat(document.forms['tabambas'].elements['atotal'+i].value);
		
		
		//total CLIENT A
		if(document.forms['tabambas'].elements['ctotal'+i]) {
			if(document.forms['tabambas'].elements['ctotal'+i].value != 0) 
				document.forms['tabambas'].elements['ctotal'+i].style.color = '#000000';
			else 
				document.forms['tabambas'].elements['ctotal'+i].style.color = '#828485';		
		}
		
		//total HOTESSE B
		if(document.forms['tabambas'].elements['htotal'+i]) {
			if(document.forms['tabambas'].elements['htotal'+i].value != 0) 
				document.forms['tabambas'].elements['htotal'+i].style.color = '#000000';
			else 
				document.forms['tabambas'].elements['htotal'+i].style.color = '#828485';			
		}
		
		//total AMBASSADRICE C
		if(document.forms['tabambas'].elements['atotal'+i]) {
			if(document.forms['tabambas'].elements['atotal'+i].value != 0) 
				document.forms['tabambas'].elements['atotal'+i].style.color = '#000000';
			else 
				document.forms['tabambas'].elements['atotal'+i].style.color = '#828485';	
		}
	}//fin boucle for
			
	//remise de 40% pour C
	var quarantepourc = parseFloat((totalambas * 40) /100);

	//premiers totaux
	document.forms['tabambas'].elements['totala'].value = totalclient.toFixed(1); //total A
	document.forms['tabambas'].elements['totalb'].value = totalhotesse.toFixed(1); //total B
	document.forms['tabambas'].elements['totalc'].value = totalambas.toFixed(1); //total C
	document.getElementById('remise40').innerHTML = '-'+quarantepourc.toFixed(1)+' €';	//taux remise 40%
	
	//DEFINIR LES BONUS / CADEAUX HOTESSES
	if(etape == 0) {//alors on exécute l'AJAX (remise à 0 de la liste des produits remisés)
		var xhr = getXhr();			
		xhr.open("GET","httprequest/tabambas.php?i="+nbre_champ+"&totala="+totalclient,false);
		xhr.send(null);		
		if(xhr.responseText) {
			var contenu = xhr.responseText;
			contenu = contenu.split('___');
			document.getElementById('bonusreunion').innerHTML = contenu[0];	//bonus réunion design
			document.forms['tabambas'].elements['bonusr'].value = contenu[1];	//bonus réunion montant
			document.getElementById('bonusventes').innerHTML = contenu[2];	//bonus ventes design
			document.forms['tabambas'].elements['bonusv'].value = contenu[3];	//bonus ventes montant
			document.getElementById('bonusrema').innerHTML = contenu[4];	//nombre article remisé
			document.getElementById('bonusremp').innerHTML = contenu[5];	//pourcentage remise
			document.forms['tabambas'].elements['remisepour'].value = contenu[6];	//pourcentage remise
			document.forms['tabambas'].elements['remisenbart'].value = contenu[7];	//pourcentage remise
			document.getElementById('artdroitremise').innerHTML = contenu[8];	//tableau liste articles remisés
			
			xhr.abort();
		} // fin if AJAX
	} // fin if AJAX
	
	var bonusreu = parseFloat(document.forms['tabambas'].elements['bonusr'].value);
	var bonusven = parseFloat(document.forms['tabambas'].elements['bonusv'].value);
		
	//article remisé pour l'hotesse B
	var totalprodremises = 0;
	var nbre_art = document.forms['tabambas'].elements['remisenbart'].value;
	for(var listi = nbre_champ; listi != (nbre_champ + nbre_art); listi++) {
		if(document.forms['tabambas'].elements['ref'+listi]) 
			totalprodremises += parseFloat(document.forms['tabambas'].elements['htotal'+listi].value);
	}//fin for
	
	//-------------------------------- totaux TTC ------------------------------
	//----------total ttc A bon de réduction client
	if(document.forms['tabambas'].elements['reducam']) {
		var bonmonta = document.forms['tabambas'].elements['reducam'].value;
		var bontypea = document.forms['tabambas'].elements['reducat'].value;
		if(bontypea == "p") 
			totalclientbas = parseFloat(totalclient - ((totalclient * bonmonta)/100));
		else 
			totalclientbas = parseFloat(totalclient - bonmonta);
	}
		totalclientbas = (totalclientbas<0?0:totalclientbas);
	
	//----------total hotesse = TOTAL B - (additions des réduc cadeaux) + prix des produits remisés
	totalhotesse -= (bonusreu + bonusven); //on soustrait les cadeaux
	totalhotesse = (totalhotesse<0?0:totalhotesse); //pas de total négatif
	if(document.forms['tabambas'].elements['reducbm']) {
		var bonmontb = document.forms['tabambas'].elements['reducbm'].value;
		var bontypeb = document.forms['tabambas'].elements['reducbt'].value;
		if(bontypeb == "p") 
			totalhotesse = parseFloat(totalhotesse - ((totalhotesse * bonmontb)/100));
		else 
			totalhotesse = parseFloat(totalhotesse - bonmontb);
		totalhotesse = (totalhotesse<0?0:totalhotesse);
	}
	totalhotesse = parseFloat(totalhotesse + totalprodremises); //on rajoute le prix des produits remisés
	
	document.forms['tabambas'].elements['totalttca'].value = totalclientbas.toFixed(1); //total A
	document.forms['tabambas'].elements['totala2'].value = totalclientbas.toFixed(1); //total A
	document.forms['tabambas'].elements['totalttcb'].value = totalhotesse.toFixed(1); //total B
	document.forms['tabambas'].elements['totalb2'].value = totalhotesse.toFixed(1); //total B
	document.forms['tabambas'].elements['totalttcc'].value = (totalambas-quarantepourc).toFixed(1); //total C	
	document.forms['tabambas'].elements['totalc2'].value = (totalambas-quarantepourc).toFixed(1); //total C	
	//frais de port 
	if(totalclient < 200) document.forms['tabambas'].elements['fraisport'].value = "10.00";
	else document.forms['tabambas'].elements['fraisport'].value = "0.00";
	
}//fin totalcolonne()


//total de chaque ligne aides à la vente
function totalaide(i) {
	var totligne = document.forms['tabambas'].elements['aideqte'+i].value * document.forms['tabambas'].elements['aidepuc'+i].value;
	document.forms['tabambas'].elements['aidetot'+i].value = totligne.toFixed(1);
	
	totalcolonneaide();
}

//total de la colonne aides à la vente
function totalcolonneaide() {
	var list = document.forms['tabambas'].elements['listidaide'].value.split('-');
	var total = 0;
	for(var i = 0; i != list.length; i++) {
		if(document.forms['tabambas'].elements['aidetot'+list[i]])
			total += parseFloat(document.forms['tabambas'].elements['aidetot'+list[i]].value);
	}
	
	document.forms['tabambas'].elements['totalaides'].value = parseFloat(total).toFixed(1);
	totalttccmd();//recalcul du total à payer
}

//total à payer A + B + C + aides
function totalttccmd() {
	var port = document.forms['tabambas'].elements['fraisport'].value==""?0:document.forms['tabambas'].elements['fraisport'].value;
	var total = parseFloat(document.forms['tabambas'].elements['totala2'].value);
	total += parseFloat(document.forms['tabambas'].elements['totalb2'].value);
	total += parseFloat(document.forms['tabambas'].elements['totalc2'].value);
	total += parseFloat(document.forms['tabambas'].elements['totalaides'].value); 
	total += parseFloat(port); 
	
	document.forms['tabambas'].elements['prixtotalttc'].value = total.toFixed(1);
}


function envoiform() {	
	var totala = parseFloat(document.forms['tabambas'].elements['totala'].value);
	var totalb = parseFloat(document.forms['tabambas'].elements['totalb'].value);
	var totalc = parseFloat(document.forms['tabambas'].elements['totalc'].value);
	
	if((totala + totalb + totalc) != 0) 
		document.forms['tabambas'].submit();
	else 
		alert('Vous devez indiquer les quantités désirées pour chaque article.');
}




/*** CALCUL FRAIS DE PORT oui ou non***/
function fraisport(cmd, frais) {


}



/*** TOTAL AIDES A LA VENTE ***/
function totalaidevente() {
	var total = 0;
	var champ = new Array('man', 'lia', 'cat', 'pla', 'rel', 'env', 'car', 'por', 'cin', 'cinp', 'sty', 'sac', 'con');

	for(var i = 0; i <= 12; i++) {
		var qte = document.forms['tabconfirm'].elements['qte'+champ[i]].value.split('.');
		qte = qte[0];
		document.forms['tabconfirm'].elements['qte'+champ[i]].value = qte;
		var pu = document.forms['tabconfirm'].elements['pu'+champ[i]].value;
		total += (qte * pu);
	}
	
	
	//MAJ du taux de réduction		
	if(document.forms['tabconfirm'].elements['reduc'])
		var reduc = parseFloat(document.forms['tabconfirm'].elements['reduc'].value);
	else 
		var reduc = 0;
	var totalabc = 0;
	if(document.forms['tabconfirm'].elements['totalabc'])
		totalabc  = parseFloat(document.forms['tabconfirm'].elements['totalabc'].value);
	if(document.forms['tabconfirm'].elements['codereduc'])
		var codereduc  = document.forms['tabconfirm'].elements['codereduc'].value;	
	else
		var codereduc;
	var xhr = getXhr();			
		
		xhr.open("GET","httprequest/tabambas.php?code="+codereduc+"&total="+totalabc+"&aide="+total,false);
		xhr.send(null);		
		
	if(xhr.responseText) {
		//alert(xhr.responseText);
		document.forms['tabconfirm'].elements['reduc'].value = xhr.responseText;
		document.getElementById('reduction').innerHTML = "- "+xhr.responseText+" €";
	}
	xhr.abort();
	
	document.forms['tabconfirm'].elements['totalaide2'].value = total;
	document.getElementById('totalaide').innerHTML = total.toFixed(1)+' €';
	totalapayer();
}



/*** TOTAL TTC final ***/
function totalapayer() {
	
	var totabc = parseFloat(document.forms['tabconfirm'].elements['totalabc'].value);
	var totalaide  = parseFloat(document.forms['tabconfirm'].elements['totalaide2'].value);
	var reduc  = parseFloat(document.forms['tabconfirm'].elements['reduc'].value);
	var frais  = parseFloat(document.forms['tabconfirm'].elements['frais'].value);
	var totalfinal = parseFloat(((totalaide + totabc) - reduc) + frais);

	document.getElementById('totalttc').innerHTML = totalfinal.toFixed(1)+' €';
}



/*** ENVOI FORMULAIRE VERS RECAPITULATIF COMMANDE ***/
function envoicmd() {
	var identvaleur = document.forms['tabconfirm'].elements['identifiant'].value.toUpperCase();
		
	if(identvaleur == identifiant) {
		document.forms['tabconfirm'].submit();
	} else {
		alert("Veuillez indiquer votre NUMERO D'IDENTIFICATION.");
	}	
}






/*** FLASH - SWF OBJECT ***/
if(typeof deconcept == "undefined")
{
	var deconcept = new Object();
}

if(typeof deconcept.util=="undefined")
{
	deconcept.util = new Object();
}

if(typeof deconcept.SWFObjectUtil == "undefined")
{
	deconcept.SWFObjectUtil = new Object();
}

deconcept.SWFObject=function(_1, id, w, h, _5, c, _7, _8, _9, _a)
{
	if(!document.getElementById){return;}
	
	this.DETECT_KEY = (_a ? _a : "detectflash");
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	
	if(_1)
	{
		this.setAttribute("swf", _1);
	}
	
	if(id)
	{
		this.setAttribute("id", id);
	}
	
	if(w)
	{
		this.setAttribute("width", w);
	}
	
	if(h)
	{
		this.setAttribute("height",h);
	}
	
	if(_5)
	{
		this.setAttribute("version", new deconcept.PlayerVersion(_5.toString().split(".")));
	}
	
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	
	if(!window.opera && document.all && this.installedVer.major > 7)
	{
		deconcept.SWFObject.doPrepUnload = true;
	}
	
	if(c)
	{
		this.addParam("bgcolor", c);
	}
	
	var q = (_7 ? _7 : "high");
	
	this.addParam("quality", q);
	this.setAttribute("useExpressInstall", false);
	this.setAttribute("doExpressInstall", false);
	var _c = ((_8)? _8 : window.location); 
	this.setAttribute("xiRedirectUrl", _c);
	this.setAttribute("redirectUrl", "");
	
	if(_9)
	{
		this.setAttribute("redirectUrl", _9);
	}
};


deconcept.SWFObject.prototype =
{
	useExpressInstall:function(_d)
	{
		this.xiSWFPath = (!_d ? "expressinstall.swf" : _d);
		this.setAttribute("useExpressInstall",true);
	},
	
	setAttribute:function(_e, _f)
	{
		this.attributes[_e] = _f;
	},
	
	getAttribute:function(_10)
	{
		return this.attributes[_10];
	},
	
	addParam:function(_11, _12)
	{
		this.params[_11] = _12;
	},
	
	getParams:function()
	{
		return this.params;
	},
	
	addVariable:function(_13, _14)
	{
		this.variables[_13] = _14;
	},
	
	getVariable:function(_15)
	{
		return this.variables[_15];
	},
	
	getVariables:function()
	{
		return this.variables;
	},
	
	getVariablePairs:function()
	{
		var _16 = new Array();
		var key;
		var _18 = this.getVariables();
		for(key in _18)
		{
			_16[_16.length] = key + "=" + _18[key];
		}
		return _16;
	},
	
	getSWFHTML:function()
	{
		var _19 = "";
		if(navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length)
		{
			if(this.getAttribute("doExpressInstall"))
			{
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute("swf", this.xiSWFPath);
			}
			
			_19 = "<embed type=\"application/x-shockwave-flash\" src=\"" + this.getAttribute("swf") + "\" width=\"" + this.getAttribute("width") + "\" height=\"" + this.getAttribute("height") + "\" style=\"" + this.getAttribute("style") + "\"";
			_19 += " id=\"" + this.getAttribute("id") + "\" name=\"" + this.getAttribute("id") + "\" ";
			var _1a = this.getParams();
			
			for(var key in _1a)
			{
				_19 += [key] + "=\"" + _1a[key] + "\" ";
			}
			
			var _1c = this.getVariablePairs().join("&");
			
			if(_1c.length > 0)
			{
				_19 += "flashvars=\"" + _1c + "\"";
			}
			
			_19 += "/>";
		}
		else
		{
			if(this.getAttribute("doExpressInstall"))
			{
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute("swf", this.xiSWFPath);
			}
			
			_19 = "<object id=\"" + this.getAttribute("id") + "\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"" + this.getAttribute("width") + "\" height=\"" + this.getAttribute("height") + "\" style=\"" + this.getAttribute("style") + "\">";
			_19 += "<param name=\"movie\" value=\"" + this.getAttribute("swf") + "\" />";
			var _1d = this.getParams();
			
			for(var key in _1d)
			{
				_19 += "<param name=\"" + key + "\" value=\"" + _1d[key] + "\" />";
			}
			
			var _1f = this.getVariablePairs().join("&");
			
			if(_1f.length > 0)
			{
				_19 += "<param name=\"flashvars\" value=\"" + _1f + "\" />";
			}
			
			_19 += "</object>";
		}
		return _19;
	},
	
	write:function(_20)
	{
		if(this.getAttribute("useExpressInstall"))
		{
			var _21 = new deconcept.PlayerVersion([6, 0, 65]);
			if(this.installedVer.versionIsValid(_21) && !this.installedVer.versionIsValid(this.getAttribute("version")))
			{
				this.setAttribute("doExpressInstall", true);
				this.addVariable("MMredirectURL", escape(this.getAttribute("xiRedirectUrl")));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		
		if(this.skipDetect || this.getAttribute("doExpressInstall") || this.installedVer.versionIsValid(this.getAttribute("version")))
		{
			var n = (typeof _20 == "string") ? document.getElementById(_20) : _20;
			n.innerHTML = this.getSWFHTML();
			return true;
		}
		else
		{
			if(this.getAttribute("redirectUrl") != "")
			{
				document.location.replace(this.getAttribute("redirectUrl"));
			}
		}
		return false;
		}
	};
	
	deconcept.SWFObjectUtil.getPlayerVersion = function()
	{
		var _23 = new deconcept.PlayerVersion([0, 0, 0]);
		
		if(navigator.plugins && navigator.mimeTypes.length)
		{
			var x = navigator.plugins["Shockwave Flash"];
			
			if(x && x.description)
			{
				_23 = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
			}
		}
		else
		{
			if(navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0)
			{
				var axo = 1;
				var _26 = 3;
				
				while(axo)
				{
					try
					{
						_26++;
						axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + _26);
						_23 = new deconcept.PlayerVersion([_26, 0, 0]);
					}
					catch(e)
					{
						axo = null;
					}
				}
			}
			else
			{
				try
				{
					var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
				}
				
				catch(e)
				{
					try
					{
						var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
						_23 = new deconcept.PlayerVersion([6, 0, 21]);
						axo.AllowScriptAccess = "always";
					}
					
					catch(e)
					{
						if(_23.major == 6)
						{
							return _23;
						}
					}
					
					try
					{
						axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
					}
					
					catch(e){}
				}
				if(axo != null)
				{
					_23 = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
				}
			}
		}
		return _23;
	};
	
	deconcept.PlayerVersion = function(_29)
	{
		this.major = (_29[0] != null ? parseInt(_29[0]) : 0);
		this.minor = (_29[1] != null ? parseInt(_29[1]) : 0);
		this.rev = (_29[2] != null ? parseInt(_29[2]) : 0);
	};
	
	deconcept.PlayerVersion.prototype.versionIsValid = function(fv)
	{
		if(this.major < fv.major)
		{
			return false;
		}
		
		if(this.major > fv.major)
		{
			return true;
		}
		
		if(this.minor < fv.minor)
		{
			return false;
		}
		
		if(this.minor > fv.minor)
		{
			return true;
		}
		
		if(this.rev < fv.rev)
		{
			return false;
		}
		
		return true;
	};
	
	deconcept.util = 
	{
		getRequestParameter:function(_2b)
		{
			var q = document.location.search || document.location.hash;
			
			if(_2b == null)
			{
				return q;
			}
			
			if(q)
			{
				var _2d = q.substring(1).split("&");
				
				for(var i = 0; i < _2d.length; i++)
				{
					if(_2d[i].substring(0,_2d[i].indexOf("=")) == _2b)
					{
						return _2d[i].substring((_2d[i].indexOf("=") + 1));
					}
				}
			}
			return "";
		}
	};
	
	deconcept.SWFObjectUtil.cleanupSWFs = function()
	{
		var _2f = document.getElementsByTagName("OBJECT");
		
		for(var i = _2f.length-1 ; i >= 0 ; i--)
		{
			_2f[i].style.display = "none";
			
			for(var x in _2f[i])
			{
				
				if(typeof _2f[i][x] == "function")
				{
					_2f[i][x] = function() {};
				}
			}
		}
	};
	
	if(deconcept.SWFObject.doPrepUnload)
	{
		if(!deconcept.unloadSet)
		{
			deconcept.SWFObjectUtil.prepUnload = function()
			{
				__flash_unloadHandler = function() {};
				__flash_savedUnloadHandler = function() {};
				window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
			};
			window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
			deconcept.unloadSet = true;
		}
	}
	
	if(!document.getElementById && document.all)
	{
		document.getElementById = function(id)
		{
			return document.all[id];
		};
	}
	var getQueryParamValue = deconcept.util.getRequestParameter;
	var FlashObject = deconcept.SWFObject;
	var SWFObject = deconcept.SWFObject;


/*** GENERAL ***/ 

function sw(a, b)
{
	if(b == 1)
	{
		if(a.value == a.accept)	
			a.value = '';
	}
	else
	{
		if(a.value == '')
			a.value = a.accept;
	}
} // fin function sw(a, b)

function getCN(t)
{
	var c = document.getElementsByTagName("*");
	if(!c.length && document.all)
		c.document.all;

	var res = [], re = new RegExp("(^| )" + t + "( |$)");
	
	for(var i = 0, el; (el = c[i]); ++i)
	{ 
		if(el.className && re.test(el.className))
		{	
			res[res.length] = el;
		} // fin if
	} // fin for
	
	return res; 
} // fin function getElementsByClassName(t)


/* CONTACT */

function tabEnfants(n, m)
{
	if(n == 0)
		document.getElementById('enfentete').style.display = 'none';
	else
		document.getElementById('enfentete').style.display = 'inline';
		
	for(var i = 0; i <= n; i++)	
	{
		if(document.getElementById('enf' + i))
			document.getElementById('enf' + i).style.display = 'inline';
	} // fin for
	
	for(i; i <= m; i++)
	{
		if(document.getElementById('enf' + i))
			document.getElementById('enf' + i).style.display = 'none';
	} // fin for
} // fin function tabEnfants(n)


/* CATALOGUE */

/* Article détails */

function swTaille()
{ 
	var t = document.getElementById('taillechoisie').value;
	if(document.getElementById('hiddentaille'))
		document.getElementById('hiddentaille').value = t;

	getInfo();	

	var c = getCN('arttaillepicto'); 
	for(var i = 0; i < c.length; i++)
		c[i].style.border = 'solid 2px #E8F6FB';

	/*if(document.getElementById(t))
		document.getElementById(t).style.border = 'solid 2px #FF861A';*/
} // fin function swTaille(t)

function swCouleur(t)
{
	if(document.getElementById('hiddencouleur'))
		document.getElementById('hiddencouleur').value = t;

	getInfo();

	var c = getCN('artcouleurpicto');

	/*for(var i = 0; i < c.length; i++)
		c[i].style.border = 'solid 2px #E8F6FB';*/

	t = t.substring(1);
	/*if(document.getElementById(t))
		document.getElementById(t).style.border = 'solid 2px #FF861A';*/

	if(photos[t][0])
		document.getElementById('artvisuel').src = photos[t][0];

	if(photos[t].length < 2)	
		document.getElementById('artautresphotos').style.display = 'none';
	else
		document.getElementById('artautresphotos').style.display = 'inline';

} // fin function swCouleur(t)

function getInfo()
{
	var req = ''; 
	if(window.XMLHttpRequest) 
		 req = new XMLHttpRequest(); 
	else if(window.ActiveXObject)
	{ 
		try 
	   	{	req = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) 
		{	req = new ActiveXObject("Microsoft.XMLHTTP"); }

	}
	else 
	{ 
	   alert("Veuillez activer le Javascript"); 
	   req = false; 
	} 

	req.open("GET", "httprequest/artinfo.php?ref=" + document.getElementById('hiddenref').value + "&taille=" + document.getElementById('hiddentaille').value + "&couleur=" + document.getElementById('hiddencouleur').value.substring(1), false);

	req.onReadyStateChange = function()
	{
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				var s = req.responseText;
				document.getElementById("artinfo").innerHTML = s;
				if(s == '')
				{	if(document.getElementById('prixdefaut'))
						document.getElementById('artinfo').innerHTML = document.getElementById('prixdefaut').value;
				}
				/*else
					document.getElementById('choixtaille').style.display = 'none';*/
					
				document.getElementById("site").style.height = "935px";
			document.getElementById('artautresphotos').style.width = '213px';			
				if(s.search('&euro;') != -1)
					document.getElementById('tdfrmcmd').style.display='inline';
				else
					document.getElementById('tdfrmcmd').style.display='none';
			}
			req.abort();

		} // fin if
	} // fin function

	req.send(null);

	if(req.readyState == 4)
	{ 
		if(req.status == 200)
		{
			var s = req.responseText;// alert(s);
			document.getElementById("artinfo").innerHTML = s; //alert(s . ' t');
				if(s == '')
				{	
					//document.getElementById('choixtaille').style.display = 'inline';
					//alert(document.getElementById('prixdefaut').value);
					if(document.getElementById('prixdefaut'))
						document.getElementById('artinfo').innerHTML = document.getElementById('prixdefaut').value;
				}
				/*else
					document.getElementById('choixtaille').style.display = 'none';*/

			if(s.search('&euro;') != -1)
				document.getElementById('tdfrmcmd').style.display='inline';
			else
				document.getElementById('tdfrmcmd').style.display='none';
		}
		req.abort();
		document.getElementById('artautresphotos').style.width = '213px';
	} // fin if

	if(photos[document.getElementById("hiddencouleur").value.substring(1)].length < 2)	
		document.getElementById('artautresphotos').style.display = 'none';
	else
		document.getElementById('artautresphotos').style.display = 'inline';
} // fin function getInfo


function artvisuelpopup(uri)
{
	window.open(uri, '_blank', 'toolbar=0;location=0;directories=0,menuBar=0,scrollbars=0,resizable=1,width=400,height=600');
} // fin function artvisuelpopup(uri)


function artvisuelrotation()
{
	
	var col = (document.getElementById('hiddencouleur').value == '' && photos[couleurdefaut]) ? couleurdefaut : document.getElementById('hiddencouleur').value.substring(1);

	var uri = document.getElementById('artvisuel').src;

	uri = parseInt(uri.substring((uri.length - 5), uri.length - 4));
	uri = uri == (photos[col].length - 1) ? 0 : uri + 1;	
	if(photos[col][uri])
		document.getElementById('artvisuel').src = photos[col][uri];
} // fin function artvisuelrotation()


/* Look2 détails */

function swLk2t(n, t)
{ 
	if(document.getElementById('hiddentaille_' + n))
		document.getElementById('hiddentaille_' + n).value = t;
		
	getLk2info();	

	var c = getCN('lk2taillepicto_' + n); 
	for(var i = 0; i < c.length; i++)
		c[i].style.border = 'solid 2px #E8F6FB';

	if(document.getElementById(n + '_' + t))
		document.getElementById(n + '_' + t).style.border = 'solid 2px #FF861A';
} // fin function swTaille(t)

function swLk2c(n, t)
{
	if(document.getElementById('hiddencouleur_' + n))
		document.getElementById('hiddencouleur_' + n).value = t;
	
	getLk2info();
	
	var c = getCN('lk2couleurpicto_' + n);

	for(var i = 0; i < c.length; i++)
		c[i].style.border = 'solid 2px #E8F6FB';

	t = t.substring(1);
	if(document.getElementById(n + '_' + t))
	{
		document.getElementById(n + '_' + t).style.border = 'solid 2px #FF861A';
		if(photos[n][t][1])
			document.getElementById('lk2autresphotos_' + n).style.display = 'inline';
		else
			document.getElementById('lk2autresphotos_' + n).style.display = 'none';
	}
	if(photos[n][t][0])
		document.getElementById('lk2img_' + n).src = photos[n][t][0];
	else
	{
		document.getElementById('lk2img_' + n).src = 'images/defaut.jpg';
		document.getElementById('lk2autresphotos_' + n).style.display = 'none';
	}
} // fin function swCouleur(t)



function newRq()
{
	var rq = false;
	
	if(window.XMLHttpRequest)
		rq = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{
		try
		{	rq = new ActiveXObject('Msxml2.XMLHTTP'); }
		catch(e)
		{	rq = new ActiveXObject('Microsoft.XMLHTTP'); }			
	}
	else
	{
		alert('Veuillez activer le JavaScript');
	}
	
	return rq;
} // fin function newRq();


function getLk2info()
{
	var req = new Array(); 
	var rupture = false;
	
	for(var i = 0; i < refs.length; i++)
	{

		if(window.XMLHttpRequest) 
			 req[i] = new XMLHttpRequest(); 
		else if(window.ActiveXObject)
		{ 
			try 
			{	req[i] = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch (e) 
			{	req[i] = new ActiveXObject("Microsoft.XMLHTTP"); }
	
		}
		else 
		{ 
		   alert("Veuillez activer le Javascript"); 
		   req[i] = false; 
		} 

		req[i].open("GET", "httprequest/lk2info.php?ref=" + refs[i] + "&taille=" + document.getElementById('hiddentaille_' + refs[i]).value + "&couleur=" + document.getElementById('hiddencouleur_' + refs[i]).value.substring(1), false);

		req[i].onReadyStateChange = function()
		{
			if(req[i].readyState == 4)
			{
				if(req[i].status == 200)
				{
					var s = req[i].responseText;
					if(s.substring(0, 7) == 'RUPTURE')
						rupture = s.substring(8);
					else
					{
						s = s.split('!');
						if(s.length == 2)
						{
							document.getElementById("hiddenprix_" + refs[i]).value = s[0];
							document.getElementById("qtemax_" + refs[i]).value = s[1];
						}
						else
							document.getElementById("hiddenprix_" + refs[i]).value = s; 
					}
				}
				req[i].abort();

			} // fin if
		} // fin function

		req[i].send(null);
		
		if(req[i].readyState == 4)
		{ 
			if(req[i].status == 200)
			{
					var s = req[i].responseText;
					if(s.substring(0, 7) == 'RUPTURE')
						rupture = s.substring(8);
					else
						document.getElementById("hiddenprix_" + refs[i]).value = s; 
			}
			req[i].abort();
			//document.getElementById('artautresphotos').style.width = '213px';
		} // fin if
		
	} // fin for
	
	
	prixbrut = 0;
	complet = true;
	remise = document.getElementById('hiddenremise').value;
	remise = (100 - remise) / 100;
	qtemax = 10000;
	
	for(var i = 0; i < refs.length; i++)
	{
		val = document.getElementById('hiddenprix_' + refs[i]).value; 
		if(val == '' || val == 0)
			complet = false;
		else
			prixbrut += parseFloat(val);


		tmpcouleur = (document.getElementById('hiddencouleur_' + refs[i]).value == '' ? couleur[refs[i]] : document.getElementById('hiddencouleur_' + refs[i]).value);

		tmpcouleur = tmpcouleur.replace('#', '');

		if(photos[refs[i]][tmpcouleur].length > 1)
			document.getElementById('lk2autresphotos_' + refs[i]).style.display = 'inline';
		else
			document.getElementById('lk2autresphotos_' + refs[i]).style.display = 'none';
		
		if(document.getElementById('qtemax_' + refs[i]))
		{
			if(document.getElementById('qtemax_' + refs[i]).value < qtemax)	
				qtemax = document.getElementById('qtemax_' + refs[i]).value;
		}
	} // fin for


	if(complet == true)
	{
		prix = (Math.round(prixbrut * remise * 100) / 100);
		if(!isNaN(prix))
		{
			document.getElementById('lk2info').innerHTML = libprix + " : " + prix + "&euro;";
			document.getElementById('lk2basfrm').style.display = 'inline';
		}
		else
		{
			document.getElementById('lk2info').innerHTML = "Choisissez la taille de chaque produit.";
			document.getElementById('lk2basfrm').style.display = 'none';
		}
		document.getElementById('hiddenprixbrut').value = prixbrut;
		document.getElementById('hiddenprix').value = prix;
		if(document.getElementById('qtemax') && qtemax)
			document.getElementById('qtemax').value = qtemax;

	}
	else if(complet == false)
	{
		document.getElementById('lk2info').innerHTML = libchoix;
		document.getElementById('lk2basfrm').style.display = 'none';
	}

	if(rupture)
	{
		document.getElementById('lk2info').innerHTML = rupture;
		document.getElementById('lk2basfrm').style.display = 'none';
	}

	if(photoslk)
	{
		if(photoslk.length < 2)
			document.getElementById('divacacherimglk').style.display = 'none';
	} // fin if
} // fin function getLk2Info


function lk2visuelrotation(n)
{
	var col = (document.getElementById('hiddencouleur_' + n).value == '' && photos[n][couleur[n]]) ? couleur[n] : document.getElementById('hiddencouleur_' + n).value.substring(1);
	var uri = document.getElementById('lk2img_' + n).src;
	uri = parseInt(uri.substring(uri.length - 5, uri.length - 4)); 
	uri = (uri == (photos[n][col].length - 1) ? 0 : (uri + 1));
	if(photos[n][col][uri])
	{ 
		document.getElementById('lk2img_' + n).src = photos[n][col][uri];
	}
} // fin function artvisuelrotation()


function lk2lkrotation()
{
	var uri = document.getElementById('lk2img').src.split('.');
	uri = parseInt(uri[0].substring(uri[0].length - 1));
	uri = (uri == (photoslk.length - 1) ? 0 : (uri + 1));
	if(photoslk[uri])
		document.getElementById('lk2img').src = photoslk[uri];
} // fin function lk2lkrotation()


function e1majcadeau(mtt)
{// 	document.getElementById('e1cadeaumtt').innerHTML = ;
	rq = newRq();
	var url = 'httprequest/e1.php?cadeau=';
	if(document.getElementById('e1ckbcadeau').checked == true)
	{
		url += 'true';
		document.getElementById('e1cadeaumtt').innerHTML = parseFloat(mtt).toFixed(1).replace('.', ',') + " &euro;";
	}
	else
	{
		url += 'false';
		document.getElementById('e1cadeaumtt').innerHTML = '';
	}

	rq.open('GET', url, false);
	rq.send(null);
	rq.abort();
	
	e1nap();

} // fin function e1majcadeau()


function getport(v)
{
	return tport[v];
} // fin function e1majport(v)


function e1majport()
{
	document.getElementById('e1portmtt').innerHTML = getport(document.getElementById('e1listepays').value).toFixed(2).toString().replace('.', ',') + ' &euro;';
	
	var rq = newRq();
	rq.open('GET', 'httprequest/e1.php?payslivraison=' + encodeURI(document.getElementById('e1listepays').value), false);
	rq.send(null);
	rq.abort();	
	
	e1nap();
} // fin function e1majport()

function getnap()
{
	var rq = newRq();
	rq.open('GET', 'httprequest/commande.php?calcul=nap', false);
	
	rq.onreadystatechange = function()
	{
		if(rq.readyState == 4)
		{
			if(rq.status == 200)
				return rq.responseText;
			else
				return "ERROR3";
		} // fin if
	} // fin function
	
	rq.send(null);
	
	if(rq.status == 200)
		return rq.responseText;
	else
		return "ERROR3";
		
} // fin function getnap()


function e1nap()
{
	var nap = getnap();
	if(nap.toString().substring(0, 5) == 'ERROR')
	{
		alert('Une erreur est survenue lors du calcul du net-à-payer. Veuillez nous contacter.');
		window.location.href = 'index.php';
	}
	else
		document.getElementById('e1nap').innerHTML = parseFloat(nap).toFixed(2).toString().replace('.', ',') + ' &euro;';
} // fin function e1nap()



function e1majreduction()
{
	var code = document.getElementById('e1iptcreduc').value;
	var rq = newRq();
	rq.open('GET', 'httprequest/e1.php?codereduction=' + code, false);
	
	rq.onreadystatechange = function() 
	{
		if(rq.readyState == 4)
		{
			if(rq.status == 200)
			{
				var s = rq.responseText;
				if(s.substring(0, 5) == 'ERROR')
				{
					var nerror = s.substring(5);
					if(nerror == 1)
					{
						var msg = reducerrors[nerror];
						msg = msg.replace("%", code);
						alert(msg);
						document.getElementById('e1iptcreduc').value = '';
						//if(navigator.appName.search('Microsoft') === false)
							document.getElementById('e1iptcreduc').focus();
						document.getElementById('e1reductionmtt').innerHTML = '';
						var tqte = getCN('e1iptqte');
						for(var i = 0; i < tqte.length; i++)
							tqte[i].disabled = false;
					} // fin if
				} // fin if
				else
				{
					document.getElementById('e1reductionmtt').innerHTML = parseFloat(s).toFixed(2).toString().replace('.',',') + ' &euro;';
					e1nap();
					var tqte = getCN('e1iptqte');
					for(var i = 0; i < tqte.length; i++)
						tqte[i].disabled = true;
				} // fin else
			} // fin if
			rq.abort();
		}	// fin if
	} // fin function 
	
	rq.send(null);	
	
if(navigator.appName.search('Microsoft') === false)
{
	if(rq.status == 200)
	{
		var s = rq.responseText; 
		if(s.substring(0, 5) == 'ERROR')
		{
			var nerror = s.substring(5);
			if(nerror == 1)
			{
				var msg = reducerrors[nerror];
				msg = msg.replace("%", code);
				alert(msg);
				document.getElementById('e1iptcreduc').value = '';
				//document.getElementById('e1iptcreduc').focus();
				document.getElementById('e1reductionmtt').innerHTML = '';
			} // fin if
		} // fin if
		else
		{
			document.getElementById('e1reductionmtt').innerHTML = parseFloat(s).toFixed(2).toString().replace('.', ',') + ' &euro;';
			e1nap();
		} // fin else
	} // fin if
} // fin if
	e1nap();
} // fin function e1majreduction()



/* Etape 2 : Adresses */

function swchoixadr(v)
{
	var listenoms = new Array('nom', 'prenom', 'adr1', 'adr2', 'cp', 'ville', 'pays', 'tel');
	switch(v)
	{
		case 'm' :
		{
			for(var i = 0; i < listenoms.length; i++)
			{
				document.getElementById('l' + listenoms[i]).disabled = true;
				document.getElementById('l' + listenoms[i]).value = document.getElementById('f' + listenoms[i]).value;
			} // fin for
		} break;
		
		case 'd' :
		{
			for(var j = 0; j < listenoms.length; j++)
			{
				document.getElementById('l' + listenoms[j]).disabled = false;
			} // fin for
		} break;
	} // fin switch
} // fin function swchoixadr()


function e2fw(from, to)
{
	if(document.getElementById('cam').checked) {
		if(document.getElementById(to))
			document.getElementById(to).value = document.getElementById(from).value;
	} // fin if
} // fin function e2fw(from, to)



/* Etape 4 : Type de paiement */

function e4enregmsg(txt)
{
	var rq = newRq();
	rq.open('GET', 'httprequest/commande.php?setmsg=' + encodeURI(txt), false);
	rq.send(null);
	rq.abort();
} // fin function e4enregmsg(txt)


function e4sbt()
{
	if(document.getElementById('e4ckbcgv').checked == true)
	{
		if(document.getElementById('carte').checked == true)
			window.location.href='paiementcb.php';
		else if(document.getElementById('cheque').checked == true)
			window.location.href='paiementcheque.php';
	} // fin if
} // fin function e4sbt()


function e4ambassbt() {
	if(document.getElementById('e4ckbcgv').checked == true) {
		if(document.getElementById('carte').checked == true)
			window.location.href='paiementcb_ambassadrice.php';
		else if(document.getElementById('cheque').checked == true)
			window.location.href='paiementcheque_ambassadrice.php';
		else if(document.getElementById('prelevement').checked == true)
			window.location.href='paiement21_ambassadrice.php';
	} // fin if
} //fin function e4ambassbt


function f3sub(n)
{ 	// Affiche la 2è liste déroulante dans le moteur de recherche une fois la catégorie sélectionnée
	if(n != '')
	{
		var rq = newRq();
		rq.open('GET', 'httprequest/recherche.php?n=' + n, false);
		
		rq.onreadystatechange = function() 
		{
			if(rq.readyState == 4)
			{
				if(rq.status == 200)
				{
					var s = rq.responseText;
					document.getElementById('selectf3').innerHTML = s;
				} // fin if
				rq.abort();
			}	// fin if
		} // fin function 

		rq.send(null);	

			if(rq.readyState == 4 && rq.status == 200)
			{
				var s = rq.responseText; 
				document.getElementById('selectf3').innerHTML = s;				
			} // fin if
	
	} // fin if(n != '')
} // fin function f3sub(n)