/* =====================================================================
//	Vérification et Correction si la quantité entrée n'est pas un entier  											*** À COMPLÉTER ***
// ===================================================================== */
/* Pour faire une vérification sans autoriser le point ("."), suivez les instructions qui sont écrites en commentaire */
function verif_nombre(champ) {
	/*var chiffres = new RegExp("[0-9\.]");*/ /* Modifier pour : var chiffres = new RegExp("[0-9]"); */
	var chiffres = new RegExp("[0-9]");

	var verif;
	/*var points = 0;*/ /* Supprimer cette ligne */

	for(x = 0; x < champ.value.length; x++) {
		verif = chiffres.test(champ.value.charAt(x));
		/*if(champ.value.charAt(x) == "."){points++;}*/ /* Supprimer cette ligne */
		/*if(points > 1){verif = false; points = 1;}*/ /* Supprimer cette ligne */
		if(verif == false){
			champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1); x--;

		}
	}
}
/* ==================================================
//	Vérification des champs obligatoire du Formulaire
// ================================================== */
function verifierFormulaire() {
	var champs1 = document.form1.enterprise.value;	var champs2 = document.form1.reference.value;	var champs3 = document.form1.adresse.value;
	var champs4 = document.form1.tel.value;			var champs5 = document.form1.notes.value;		var champs6 = document.form1.date.value;
	var mess = "S.V.P., veuillez compléter le(s) champs suivant(s) :\n\n";
	if (champs1 == "") {
		mess = mess + "\t=> Entreprise\n";
			if (champs2 == "")	{mess = mess + "\t=> Numéro de commande\n";}
			if (champs3 == "") 	{mess = mess + "\t=> Adresse\n";}
			if (champs4 == "") 	{mess = mess + "\t=> Tél.\n";}
			if (champs5 == "") 	{mess = mess + "\t=> Commandé par\n";}
			if (champs6 == "") 	{mess = mess + "\t=> Date\n";}
		alert (mess + "\n ");
		document.form1.enterprise.focus();
		return false;
	}
	if (champs2 == "") {
		mess = mess + "\t=> Numéro de commande\n";
			if (champs3 == "") 	{mess = mess + "\t=> Adresse\n";}
			if (champs4 == "") 	{mess = mess + "\t=> Tél.\n";}
			if (champs5 == "") 	{mess = mess + "\t=> Commandé par\n";}
			if (champs6 == "") 	{mess = mess + "\t=> Date\n";}
		alert (mess + "\n ");
		document.form1.reference.focus();
		return false;
	}
	if (champs3 == "") {
		mess = mess + "\t=> Adresse\n";
			if (champs4 == "") 	{mess = mess + "\t=> Tél.\n";}
			if (champs5 == "") 	{mess = mess + "\t=> Commandé par\n";}
			if (champs6 == "") 	{mess = mess + "\t=> Date\n";}
		alert (mess + "\n ");
		document.form1.adresse.focus();
		return false;
	}
	if (champs4 == "") {
		mess = mess + "\t=> Tél.\n";
			if (champs5 == "") 	{mess = mess + "\t=> Commandé par\n";}
			if (champs6 == "") 	{mess = mess + "\t=> Date\n";}
		alert (mess + "\n ");
		document.form1.tel.focus();
		return false;
	}
	if (champs5 == "") {
		mess = mess + "\t=> Commandé par\n";
			if (champs6 == "") 	{mess = mess + "\t=> Date\n";}
		alert (mess + "\n ");
		document.form1.notes.focus();
		return false;
	}
	if (champs6 == "") {
		alert (mess + "\t=> Date\n\n ");
		document.form1.date.focus();
		return false;
	}
	/* Si tous les champs obligatoires sont remplis */
	/*var AchatTotal = document.form1.grand_total.value;*/
	
	var Total_275 = document.form1.totaldesachats_275g_commande.value;
	var Total_600 = document.form1.totaldesachats_600g_commande.value;
	var Total_16 = document.form1.totaldesachats_1_6kg_commande.value;
	var Total_60 = document.form1.totaldesachats_60ml_commande.value;
	
	/*if (AchatTotal == "") {*/
	if ((Total_275 == "") && (Total_600 == "") && (Total_16 == "") && (Total_60 == "")) {
		alert ("Pour nous faire parvenir votre commande, il vous faut choisir au moins 1 item. ;o)\n");
		return false;
	}
	else {
		return(confirm ("Voulez-vous transmettre votre commande maintenant?    \n \n> Cliqué sur \"Annuler\" pour retourner au formulaire.\n \n"));
	}
}
/* =========================================
//	Activation et Désactivation des TextArea
// ========================================= */
function GereControle(Format, Controleur, Controle) {
	var objControleur = document.getElementById(Controleur);
	var objControle = document.getElementById(Controle);
		objControle.disabled=(objControleur.checked==true)?false:true;
	/* Donne le focus au TextArea si CheckBox est coché */
	if (objControleur.checked) {objControle.focus();}
	switch (Format) {
		case 'ech':  calcule_QTech();
		break;
		case 'f275': calcule_QT275g();
		break;
		case 'f600': calcule_QT600g();
		break;
		case 'f16':  calcule_QT1_6kg();
		break;
		case 'vapo': calcule_QT60ml();
		break;
	}
}
/* ========================================================
//	Calcul et Affichage du prix total pour les ÉCHANTILLONS
// ======================================================== */
function calcule_QTech() {
	QteEchFloral = parseInt(document.forms.form1.floral_echantillons_commande.value);
	QteEchHerbal = parseInt(document.forms.form1.herbal_echantillons_commande.value);
	QteEchAroma  = parseInt(document.forms.form1.aroma_echantillons_commande.value);
	QteEchSpicy  = parseInt(document.forms.form1.spicy_echantillons_commande.value);
	if ((isNaN(QteEchFloral)) || (document.forms.form1.floral_echantillons_commande.disabled)) (QteEchFloral = parseInt(0));
	if ((isNaN(QteEchHerbal)) || (document.forms.form1.herbal_echantillons_commande.disabled)) (QteEchHerbal = parseInt(0));
	if ((isNaN(QteEchAroma))  ||  (document.forms.form1.aroma_echantillons_commande.disabled))  (QteEchAroma  = parseInt(0));
	if ((isNaN(QteEchSpicy))  ||  (document.forms.form1.spicy_echantillons_commande.disabled))  (QteEchSpicy  = parseInt(0));
	QTech = parseInt(QteEchFloral + QteEchHerbal + QteEchAroma + QteEchSpicy);
	if (QTech > 0) {
		document.forms["form1"].totaldesachats_echantillons.checked = true;
		document.forms["form1"].totaldesachats_echantillons_commande.value = QTech + "      ";
		document.forms["form1"].prixtotal_echantillons.value = "";
	}
	else {
		document.forms["form1"].totaldesachats_echantillons.checked = false;
		document.forms["form1"].totaldesachats_echantillons_commande.value = "";
		document.forms["form1"].prixtotal_echantillons.value = "";
	}
	calcule_GTotal();
}
/* ==================================================
//	Calcul et Affichage du prix total pour les 275 g
// ================================================== */
function calcule_QT275g() {
	Qte275gFloral = parseInt(document.forms.form1.floral_275g_commande.value);
	Qte275gHerbal = parseInt(document.forms.form1.herbal_275g_commande.value);
	Qte275gAroma  = parseInt(document.forms.form1.aroma_275g_commande.value);
	Qte275gSpicy  = parseInt(document.forms.form1.spicy_275g_commande.value);
	if ((isNaN(Qte275gFloral)) || (document.forms.form1.floral_275g_commande.disabled)) (Qte275gFloral = parseInt(0));
	if ((isNaN(Qte275gHerbal)) || (document.forms.form1.herbal_275g_commande.disabled)) (Qte275gHerbal = parseInt(0));
	if ((isNaN(Qte275gAroma))  || (document.forms.form1.aroma_275g_commande.disabled))  (Qte275gAroma  = parseInt(0));
	if ((isNaN(Qte275gSpicy))  || (document.forms.form1.spicy_275g_commande.disabled))  (Qte275gSpicy  = parseInt(0));
	QT275g = parseInt(Qte275gFloral + Qte275gHerbal + Qte275gAroma + Qte275gSpicy);
	if (QT275g > 0) {
		document.forms["form1"].totaldesachats_275g.checked = true;
		document.forms["form1"].totaldesachats_275g_commande.value = QT275g + "      ";
		document.forms["form1"].prixtotal_275g.value = "";
	}
	else {
		document.forms["form1"].totaldesachats_275g.checked = false;
		document.forms["form1"].totaldesachats_275g_commande.value = "";
		document.forms["form1"].prixtotal_275g.value = "";
	}
	calcule_GTotal();
}
/* ==================================================
//	Calcul et Affichage du prix total pour les 600 g
// ================================================== */
function calcule_QT600g() {
	Qte600gFloral = parseInt(document.forms.form1.floral_600g_commande.value);
	Qte600gHerbal = parseInt(document.forms.form1.herbal_600g_commande.value);
	Qte600gAroma  = parseInt(document.forms.form1.aroma_600g_commande.value);
	Qte600gSpicy  = parseInt(document.forms.form1.spicy_600g_commande.value);
	if ((isNaN(Qte600gFloral)) || (document.forms.form1.floral_600g_commande.disabled)) (Qte600gFloral = parseInt(0));
	if ((isNaN(Qte600gHerbal)) || (document.forms.form1.herbal_600g_commande.disabled)) (Qte600gHerbal = parseInt(0));
	if ((isNaN(Qte600gAroma))  || (document.forms.form1.aroma_600g_commande.disabled))  (Qte600gAroma  = parseInt(0));
	if ((isNaN(Qte600gSpicy))  || (document.forms.form1.spicy_600g_commande.disabled))  (Qte600gSpicy  = parseInt(0));
	QT600g = parseInt(Qte600gFloral + Qte600gHerbal + Qte600gAroma + Qte600gSpicy);
	if (QT600g > 0) {
		document.forms["form1"].totaldesachats_600g.checked = true;
		document.forms["form1"].totaldesachats_600g_commande.value = QT600g + "      ";
		document.forms["form1"].prixtotal_600g.value = "";
	}
	else {
		document.forms["form1"].totaldesachats_600g.checked = false;
		document.forms["form1"].totaldesachats_600g_commande.value = "";
		document.forms["form1"].prixtotal_600g.value = "";
	}
	calcule_GTotal();
}
/* ===================================================
//	Calcul et Affichage du prix total pour les 1.6 kg
// =================================================== */
function calcule_QT1_6kg() {
	Qte1_6kgFloral = parseInt(document.forms.form1.floral_1_6kg_commande.value);
	Qte1_6kgHerbal = parseInt(document.forms.form1.herbal_1_6kg_commande.value);
	Qte1_6kgAroma  = parseInt(document.forms.form1.aroma_1_6kg_commande.value);
	Qte1_6kgSpicy  = parseInt(document.forms.form1.spicy_1_6kg_commande.value);
	if ((isNaN(Qte1_6kgFloral)) || (document.forms.form1.floral_1_6kg_commande.disabled)) (Qte1_6kgFloral = parseInt(0));
	if ((isNaN(Qte1_6kgHerbal)) || (document.forms.form1.herbal_1_6kg_commande.disabled)) (Qte1_6kgHerbal = parseInt(0));
	if ((isNaN(Qte1_6kgAroma))  || (document.forms.form1.aroma_1_6kg_commande.disabled))  (Qte1_6kgAroma  = parseInt(0));
	if ((isNaN(Qte1_6kgSpicy))  || (document.forms.form1.spicy_1_6kg_commande.disabled))  (Qte1_6kgSpicy  = parseInt(0));
	QT1_6kg = parseInt(Qte1_6kgFloral + Qte1_6kgHerbal + Qte1_6kgAroma + Qte1_6kgSpicy);
	if (QT1_6kg > 0) {
		document.forms["form1"].totaldesachats_1_6kg.checked = true;
		document.forms["form1"].totaldesachats_1_6kg_commande.value = QT1_6kg + "      ";
		document.forms["form1"].prixtotal_1_6kg.value = "";
	}
	else {
		document.forms["form1"].totaldesachats_1_6kg.checked = false;
		document.forms["form1"].totaldesachats_1_6kg_commande.value = "";
		document.forms["form1"].prixtotal_1_6kg.value = "";
	}
	calcule_GTotal();
}
/* =====================================================================
//	Calcul et Affichage du prix total pour les VAPO-AIR Contenant 60 ml
// ===================================================================== */
function calcule_QT60ml() {
	Qte60mlFloral = parseInt(document.forms.form1.vapoair_floral_commande.value);
	Qte60mlHerbal = parseInt(document.forms.form1.vapoair_herbal_commande.value);
	Qte60mlAroma  = parseInt(document.forms.form1.vapoair_aroma_commande.value);
	Qte60mlSpicy  = parseInt(document.forms.form1.vapoair_spicy_commande.value);
	if ((isNaN(Qte60mlFloral)) || (document.forms.form1.vapoair_floral_commande.disabled)) (Qte60mlFloral = parseInt(0));
	if ((isNaN(Qte60mlHerbal)) || (document.forms.form1.vapoair_herbal_commande.disabled)) (Qte60mlHerbal = parseInt(0));
	if ((isNaN(Qte60mlAroma))  || (document.forms.form1.vapoair_aroma_commande.disabled))  (Qte60mlAroma  = parseInt(0));
	if ((isNaN(Qte60mlSpicy))  || (document.forms.form1.vapoair_spicy_commande.disabled))  (Qte60mlSpicy  = parseInt(0));
	QT60ml = parseInt(Qte60mlFloral + Qte60mlHerbal + Qte60mlAroma + Qte60mlSpicy);
	if (QT60ml > 0) {
		document.forms["form1"].totaldesachats_60ml.checked = true;
		document.forms["form1"].totaldesachats_60ml_commande.value = QT60ml + "      ";
		document.forms["form1"].prixtotal_60ml.value = "";
	}
	else {
		document.forms["form1"].totaldesachats_60ml.checked = false;
		document.forms["form1"].totaldesachats_60ml_commande.value = "";
		document.forms["form1"].prixtotal_60ml.value = "";
	}
	calcule_GTotal();
}
/* ====================================
//	Calcul et Affichage du GRAND TOTAL
// ==================================== */
function calcule_GTotal() {
	GTech = parseFloat(document.forms.form1.prixtotal_echantillons.value);
	GT275 = parseFloat(document.forms.form1.prixtotal_275g.value);
	GT600 = parseFloat(document.forms.form1.prixtotal_600g.value);
	GT16  = parseFloat(document.forms.form1.prixtotal_1_6kg.value);
	GT60  = parseFloat(document.forms.form1.prixtotal_60ml.value);
	if (isNaN(GTech)) (GTech = parseInt(0));
	if (isNaN(GT275)) (GT275 = parseInt(0));
	if (isNaN(GT600)) (GT600 = parseInt(0));
	if (isNaN(GT16))  (GT16 = parseInt(0));
	if (isNaN(GT60))  (GT60 = parseInt(0));
	GTotal = GTech + GT275 + GT600 + GT16 + GT60
	/*alert("GTotal =  " + GTotal); */
	document.forms["form1"].grand_total.value = "";
}
/* =============================================================================
//	Lors d'un retour arrière (surtout pour IE), Chexbox=Off et Quantités=Disable
//  Sinon, (avec IE), les Checkbox=On et les Quantités sont désactivées
// ============================================================================== */
function verifChamps_onLoad () {

	document.forms['form1'].floral_echantillons.checked = false;	document.forms['form1'].floral_echantillons_commande.disable = true;
	document.forms['form1'].floral_275g.checked = false;			document.forms['form1'].floral_275g_commande.disable = true;
	document.forms['form1'].floral_600g.checked = false;			document.forms['form1'].floral_600g_commande.disable = true;
	document.forms['form1'].floral_1_6kg.checked = false;			document.forms['form1'].floral_1_6kg_commande.disable = true;
	
	document.forms['form1'].herbal_echantillons.checked = false;	document.forms['form1'].herbal_echantillons_commande.disable = true;
	document.forms['form1'].herbal_275g.checked = false;			document.forms['form1'].herbal_275g_commande.disable = true;
	document.forms['form1'].herbal_600g.checked = false;			document.forms['form1'].herbal_600g_commande.disable = true;
	document.forms['form1'].herbal_1_6kg.checked = false;			document.forms['form1'].herbal_1_6kg_commande.disable = true;
	
	document.forms['form1'].aroma_echantillons.checked = false;		document.forms['form1'].aroma_echantillons_commande.disable = true;
	document.forms['form1'].aroma_275g.checked = false;				document.forms['form1'].aroma_275g_commande.disable = true;
	document.forms['form1'].aroma_600g.checked = false;				document.forms['form1'].aroma_600g_commande.disable = true;
	document.forms['form1'].aroma_1_6kg.checked = false;			document.forms['form1'].aroma_1_6kg_commande.disable = true;
	
	document.forms['form1'].spicy_echantillons.checked = false;		document.forms['form1'].spicy_echantillons_commande.disable = true;
	document.forms['form1'].spicy_275g.checked = false;				document.forms['form1'].spicy_275g_commande.disable = true;
	document.forms['form1'].spicy_600g.checked = false;				document.forms['form1'].spicy_600g_commande.disable = true;
	document.forms['form1'].spicy_1_6kg.checked = false;			document.forms['form1'].spicy_1_6kg_commande.disable = true;
	
	document.forms['form1'].vapoair_floral.checked = false;			document.forms['form1'].vapoair_floral_commande.disable = true;
	document.forms['form1'].vapoair_herbal.checked = false;			document.forms['form1'].vapoair_herbal_commande.disable = true;
	document.forms['form1'].vapoair_aroma.checked = false;			document.forms['form1'].vapoair_aroma_commande.disable = true;
	document.forms['form1'].vapoair_spicy.checked = false;			document.forms['form1'].vapoair_spicy_commande.disable = true;
	
	/* Remet les Totaux à zéro */
	calcule_QTech(); calcule_QT275g(); calcule_QT600g(); calcule_QT1_6kg(); calcule_QT60ml();
}

