<!--

//********************* JUMP MENU FOR RANKS ******************************************

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


//********************* OPEN BROWSER WINDOW ******************************************

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


/*****************************************************************************
* FUNCTION FOR MENU DIVS
* 
******************************************************************************/

var oTime;

function antichambre()
	{
	oTime = setTimeout('showmenu()',250);
	}

function showmenu(name) 
	{
	if (name) clearTimeout(oTime);
	var ii;
	var m=2; // THE NUMBER OF MENUS HAS TO BE INSTERTED HERE
	var qq;
	var nen;
	NeMenu =  new Array();
	nename = new Array();
	for (ii=1; ii<=m; ii++)
		{
		nen="menu" + ii;
		nename[ii]=nen;
		if (name)
			{
			if (nen==name) qq=ii;
			}
		}
	if (document.getElementById)
		{ 
		if (name)
			{
			document.getElementById(name).style.visibility='visible';
			}
		for (ii=1; ii<=m; ii++)
			{
			if (ii!=qq)
				{
				NeMenu[ii] = document.getElementById(nename[ii]);
				NeMenu[ii].style.visibility='hidden';
				}
			}
		return true;
	  	}

	if (document.all)
		{
		if (name) document.all[name].style.visibility = 'visible';
		for (ii=1; ii<=m; ii++)
			{
			if (ii!=qq) document.all[nename[ii]].style.visibility = 'hidden'; 
			}
		return true;
		}

	if (document.layers)
		{
		if (name) document.layers[name].visibility = 'show';
		for (ii=1; ii<=m; ii++)
			{
			if (ii!=qq) document.layers[nename[ii]].visibility = 'hide';
    			}
		return true;
		}
	}





/*****************************************************************************
* FUNCTION TO CHANGE HEIGHT OF CONTENT DIV
* also requires <body onload="alertSize()">
******************************************************************************/

function alertSize() {}


var pageID="";
window.onresize = alertSize;






/**********************************************************************************
*
*   FONCTION POUR CALCULER LES PRODUITS PALC DANS LA COMMANDE (PALC = Panier A La Carte)
*   Elle est appelée lors du chargement de la page et quand un champ de quantité 
* 
*
**********************************************************************************/



function limitDecimalsInFormField(fd){	
	var vTemp;
	vTemp = fd.replace(/[/,]/,".");
	if(vTemp.indexOf(".")!= -1){
		var vTempArr = vTemp.split(".");		
		vTemp = vTempArr[1].substring(0,2);		
		vTemp = vTempArr[0] + "." + vTemp;
	}	
	return Number(vTemp);
}



function resetValTest(me){
	var fV = me.value;
	if(fV=="0"){
		me.value = '';
	}	
}


function focusNext(idnum, evt) {
		var d = (idnum+1);
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if ((charCode == 13) || (charCode == 3)) {
        document.forms['products'].elements["num"+d].focus();
        return false;
    }
    return true;
}



function addUp(idVar){
		// idVar est le numéro de ligne du produit qu'on utilise pour mettre son
		// champ de quantité à 0 si le client saisit une quantité trop grande ou 	 
		// qui risque de faire dépasser le poids
		
		
	// vérifier que le client est loggé avant de faire quoi que ce soit
	if(jsClientId &&(jsClientId!='')){

		var numTotalProds= document.forms['products'].elements['numProds'].value; // le nombre de lignes de produits à parcourir
		//alert("num prods = " + numTotalProds);
		
		var val;
		var sum = 0;
		var consNum;
		var consToAdd = 0;
		var PALCnum;
		var valPansTot = 0;
		var numPansClassique = 0;
		var added = 0;
		var fam;
		var texteAlerte = "";
		var stopP = 0;
		var numProduits = 0;
		var poidsProduitsPALC = 0.00;
		var poidsProduitsNonPALC = 0.00;
		var prodType;
		var poidsTotProduit = 0;
		var qOfprod = 0;
		var qOfprodKg;
		var poidsTotCommande = 0;
		var prodPALCcommande = 0;
		var numPALC = 0;
		var numConsPALC = 0;
		var prixProduit;
		var i;
		var numConsignesInCommande;
		
		//var rmk = window.document.getElementById['remarks'];
		
		//alert("consigne = " + consigne);

	
		// D'abord vérifier que les conditions globales sont satisfaites	
		for(i=1;i<=numTotalProds;i++){
			
			
			// obtenir le numéro id de la famille
			fam = document.forms['products'].elements['fam' + i].value;
			// obtenir le type du produit pour savoir si c'est un produit PALC
			prodType = document.forms['products'].elements['type' + i].value;
			// obtenir l'unité du produit
			AR_UNITE = document.forms['products'].elements['AR_UNITE' + i].value;
			// obtenir le poids du produit
			AR_POIDS = Number(document.forms['products'].elements['AR_POIDS' + i].value);
			// savoir si le produit est hors poids pour le PALC
			AR_HORS_POIDS = document.forms['products'].elements['AR_HORS_POIDS' + i].value;
			// obtenir la quantité pour le produit
			if(qOfprod = document.forms['products'].elements['num' + i]){
				qOfprod = document.forms['products'].elements['num' + i].value;
			}
			// obtenir le numéro id du produit
			prodIDnum = document.forms['products'].elements['prodIDnum' + i].value;
			// obtenir le prix TTC du produit
			prixProduit = Number(document.forms['products'].elements['val' + i].value);
			
			
		
			
			// obtenir la position du produit consigne dans la liste des produits
			// afin de pouvoir lui affecter une valeur par la suite
			if((fam == "40CONS")&&(stopP==0)){
				consNum = document.forms['products'].elements['count' + i].value;
				numConsignesInCommande = qOfprod;
			}
		
		
		
			
			// obtenir le nombre de PALC déjà dans la commande et la position du produit PALC dans la liste des produits
			// afin de pouvoir lui affecter une valeur par la suite
			if((prodIDnum == "02PACA_PANI")&&(stopP==0)){
				numPALC = Number(document.forms['products'].elements['num' + i].value);
				PALCnum = document.forms['products'].elements['count' + i].value
			}		
			
			
			/*
			// remettre à 0 ou 0.00 si le client vide le champ et sort du champ
			if(qOfprod==""){
				if(AR_UNITE=='kg'){
					document.forms['products'].elements['num' + i].value = '0.0';
				}else{
					document.forms['products'].elements['num' + i].value = '0';
				}
				
				document.forms['products'].elements['prodTot' + i].value = '';
			}
			*/
		
		
			
			
			
		
			// si une quantité >0 existe dans le champ quantité pour cet article
			if((qOfprod!="0")&&(qOfprod!="0.0")&&(qOfprod!="")&&(qOfprod!=undefined)){			
			
				
				qOfprod = limitDecimalsInFormField(qOfprod);
				
							
				// vérifier qu'il n'y a que des chiffres et le point dans la chaîne
				if((!isNaN(qOfprod)==false)&&(stopP==0)){
					if(document.forms['products'].elements['num' + i]){
						document.forms['products'].elements['num' + i].value = '';
					}
					document.forms['products'].elements['prodTot' + i].value = 0;
					//alert("Variable qOfprod value is " + typeof(qOfprod));
					alert("Les quantités saisies ne peuvent contenir que les chiffres");
					stopP = 1;
				}	
				
				
				
				// remplacer le virgule par un point
				// limiter le nombre de décimals à 2
				// affecter la quantité au champ
				if(stopP==0){
					//qOfprodv = limitDecimalsInFormField(qOfprod);	
					document.forms['products'].elements['num' + i].value = qOfprod;
					// changer le var type en nombre			
					qOfprod = Number(document.forms['products'].elements['num' + i].value);
				}
				
				
				
				// vérifier que c'est un nombre entier
				if((AR_UNITE == "u")&&(Math.floor(qOfprod)!=qOfprod)&&(stopP==0)){
					document.forms['products'].elements['num' + i].value = '';
					document.forms['products'].elements['prodTot' + i].value = 0;
					alert("Ce produit est vendu à l'unité; sa quantité saisie doit être un nombre entier");	
					stopP = 1;
				}
			
				
				
				// si c'est un panier ajouter 1 au total des paniers dans la commande
				if((fam == "01PANI")&&(stopP==0)){
					val = Number(document.forms['products'].elements['num' + i].value);	
					if(val>0){
						valPansTot += val;						
					}
				}	
				
				
				
				
		
				
				
				
				// compter le nombre de lignes de produits commandés (qu'on ne doit pas dépasser à cause des Bonjours) - ce nombre est défini plus bas
				///if((prodType == "4")&&(fam != "02PACA")){
					if((qOfprod>0)&&(stopP==0)){
						numProduits++;
					}	
				//}
				
				
				// si un produit du type PALC a été commandé 
				// basculer le var prodPALCcommande en 1;
				if((prodType == "4")&&(prodIDnum != "02PACA_PANI")&&(qOfprod>0)&&(stopP==0)){
					prodPALCcommande = 1;
				}
				
				
				
				
				
				
				
				// si le produit a l'unité 'u' vérifer que la quantité se trouve 
				// entre 0 et 99
				// si le produit a l'unité 'kg' vérifer que la quantité se trouve 
				// entre 0.1 et 24
				if((qOfprod>0)&&(stopP==0)){
					if(AR_UNITE == "u"){
						if((qOfprod<1)||(qOfprod>99)){
							//stopP = 1; // arreter le processus
							document.forms['products'].elements['num' + i].value = '';
							document.forms['products'].elements['prodTot' + i].value = 0;
							alert("La quantité doit être entre 1 et 99");
							break;
						}
					}	
					if(AR_UNITE == "kg"){
						if((qOfprod<0.1)||(qOfprod>24)){
							//stopP = 1; // arreter le processus
							document.forms['products'].elements['num' + i].value = '';
							document.forms['products'].elements['prodTot' + i].value = 0;
							alert("La quantité doit être entre 0.1kg et 24kg");
							break;
						}
					}
				}





				// si le produit doit être compté dans le poids du panier
				if((AR_HORS_POIDS=='0')&&(stopP==0)&&(qOfprod>0)){
					//calculer le poids commandé
					//if(AR_UNITE == "kg"){
					//	poidsTotproduit = qOfprod;
					//}else{
						poidsTotproduit = Number(AR_POIDS*qOfprod);
						//alert (AR_POIDS + " * " + qOfprod)
						poidsTotproduit.toFixed(2);
					//}
					// ajouter au poids total de la commande 
					poidsTotCommande += poidsTotproduit;
					
				}
				
				
								
		
				
				
				
				// calculer la valeur total de la ligne
				if(stopP==0){	// si tout va bien			
					if(qOfprod>0){
						if((prodIDnum != "02PACA_PANI")&&(fam != "40CONS")){
							$totProdLigne = (qOfprod*prixProduit);
							document.forms['products'].elements['prodTot' + i].value = $totProdLigne.toFixed(2);
						}
					}	
				}			
				
			
			}else{ // si le quantité est 0
				if((prodIDnum != "02PACA_PANI")&&(fam != "40CONS")){
					document.forms['products'].elements['prodTot' + i].value = "";	
				}
			}// fin vérification existence de quantité pour cet article 
			
			
			
			
		} // end boucle for()
		
		
		
		// nombre total de paniers classiques 
		numPansClassique = valPansTot;
		
		
		

	
		// NOMBRE MAXI D'ARTICLES DANS LA COMMANDE
		// si il y a plus de 27 articles c'est pas bon
		if((numProduits > 27)&&(stopP==0)){
			//stopP = 1;
			// mettre à 0 le champ quantité du dernier produit commandé 
			document.forms['products'].elements['num' + idVar].value = ''; 
			document.forms['products'].elements['prodTot' + idVar].value = 0;
			alert("Vous ne pouvez pas commander plus de 30 articles différents");
		}
		
		
		
	
		
		
		
		
		
		// sil il y a au moins article PALC ajouter 3.50 au cumul total de la commande
		if((stopP==0)&&(prodPALCcommande==1)){
			if(numPALC==0){ // si le PALC n'est pas déjà dans la commande					
					alert('Vous venez de choisir un article livrable avec un panier « sur mesure » ; nous ajoutons donc à votre commande le poste « frais fixes attachés à la livraison d’un panier « sur mesure » », 3,50€.');				
					document.forms['products'].elements['num' + PALCnum].value = 1;	
					document.forms['products'].elements['prodTot' + PALCnum].value = "3.50";
				}				
			//sum += 3.50;	
		}else{
			document.forms['products'].elements['num' + PALCnum].value = '';	
			document.forms['products'].elements['prodTot' + PALCnum].value = 0;
		}
		
		
		
				//alert("numProduits = " + numProduits + "\n" + "poids commande = " + poidsTotCommande.toFixed(2) + "kg");
	
	
		// si le poids total dépasse 24 kg c'est pas bon
		if((poidsTotCommande>24.00)&&(stopP==0)){
			//stopP = 1;
			
			//re-calculer le poids commandé en enlevant celui qui fait dépasser
			AR_UNITE = document.forms['products'].elements['AR_UNITE' + idVar].value
			qOfprod = document.forms['products'].elements['num' + idVar].value;
			AR_POIDS = Number(document.forms['products'].elements['AR_POIDS' + idVar].value);

			if(AR_UNITE == "kg"){
				poidsTotproduit = qOfprod;
			}else{
				poidsTotproduit = (AR_POIDS*qOfprod);
			}
			// soustraire du poids total de la commande 
			poidsTotCommande -= poidsTotproduit;			
					
			// mettre à 0 le champ quantité du dernier produit commandé 
			document.forms['products'].elements['num' + idVar].value = ''; 
			document.forms['products'].elements['prodTot' + idVar].value = 0;
			alert("Votre commande ne peut pas dépasser 24 kg");
		}
		
		
		
		
		
		
		// calculer le nombre de PALC par rapport au poids total
		if((poidsTotCommande>0)&&(prodPALCcommande==1)){
			if((poidsTotCommande>0)&&(poidsTotCommande<=12.00)){
				// ajouter 1 au total des consignes requis pour cette commande			
				numConsPALC = 1;
				valPansTot += numConsPALC;
			}			
			if((poidsTotCommande>12.00)&&(poidsTotCommande<=24.00)){
				// ajouter 2 au total des consignes requis pour cette commande
				numConsPALC = 2;
				valPansTot += numConsPALC;
			}
		}
	
		
		
		// calculer si le nombre de consignes dans la commande
		// dépasse le nombre de consignes actuel du client	
		
		
	
			
			if(consigne==''){
				consigne == 0;	
			}				
			if(valPansTot>0){
				var consToAdd = (valPansTot-consigne);
        if(consToAdd>=1){			
				  document.forms['products'].elements['num' + consNum].value = consToAdd;
        }	
			}else{
				document.forms['products'].elements['num' + consNum].value = 0;	
			}
		
	
		
		
		
		
		for(i=1;i<=numTotalProds;i++){
			// obtenir le numéro id de la famille
			fam = document.forms['products'].elements['fam' + i].value;
			// obtenir le type du produit pour savoir si c'est un produit PALC
			prodType = document.forms['products'].elements['type' + i].value;
			// obtenir l'unité du produit
			AR_UNITE = document.forms['products'].elements['AR_UNITE' + i].value;
			// obtenir le poids du produit
			AR_POIDS = Number(document.forms['products'].elements['AR_POIDS' + i].value);
			// savoir si le produit est hors poids pour le PALC
			AR_HORS_POIDS = document.forms['products'].elements['AR_HORS_POIDS' + i].value;
			// obtenir la quantité pour le produit
			if(document.forms['products'].elements['num' + i]){
				qOfprod = document.forms['products'].elements['num' + i].value;
			}
			// obtenir le numéro id du produit
			prodIDnum = document.forms['products'].elements['prodIDnum' + i].value;
			// obtenir le prix TTC du produit
			prixProduit = Number(document.forms['products'].elements['val' + i].value);
			

			
			
			if(fam != "40CONS"){
				$totProdLigne = (qOfprod*prixProduit);
				if($totProdLigne>0){
					document.forms['products'].elements['prodTot' + i].value = $totProdLigne.toFixed(2);	
				}else{
					document.forms['products'].elements['prodTot' + i].value = "";
				}							
				sum += $totProdLigne;
			}
		}
		
		
		
		
		
		
	
		// ajouter palc sur commande
		//if(stopP==0){
			document.forms['products'].elements['total'].value = sum.toFixed(2);	
		//}
		
	
		// afficher le compte des consignes etc
		document.getElementById("remarks").innerHTML = 'Votre commande comprend ' + numPansClassique  + ' panier(s) classique(s) et ' + numConsPALC + ' panier(s) "sur mesure" ( 1 panier "sur mesure" par tranche de 12 kg), ce qui correspond à ' + valPansTot + ' panier(s) consigné(s).<br /><br />Vous disposez sur votre compte de ' + consigne + ' consigne(s) ; nous rajoutons donc ' + consToAdd + ' consigne(s) à votre commande.<br /><br />';
		
		
		// empecher le formulaire de d'être envoyé si il y une errer 
		if(stopP==1){
			return false;
		}
	}
	
}// end function







// pour vérifier qu'il y a au moins 1 panier dans la commande
function checkBasket(){
	//var numFields=((document.forms['products'].elements.length)-2)/5;
	var numFields= document.forms['products'].elements['numProds'].value;
	var i;
	var val;
	var fam;
	var found=0;
	for(i=1;i<=numFields;i++){
		val = Number(document.forms['products'].elements['num' + i].value);
		prodType = document.forms['products'].elements['type' + i].value;
		if(val>0){
			
			fam = document.forms['products'].elements['fam' + i].value;	
			//alert(fam);
			if((fam=="01PANI")||(prodType=="4")){
				found=1;
				//alert("found");
			}
		}		
	}
	
	if(found==1){
		//alert(found);
		document.forms['products'].submit();
		return true;
	}else{
		alert("la livraison des paniers de fruits et légumes constituent le coeur du métier de Ma Terre : nous ne pourront vous livrer des produits complémentaires qu'en accompagnement d'un panier.\nVous pouvez compléter ou annuler votre commande. Merci.");
		return false;
	}
}




/************************** CHECK MAIL FORM FIELDS *******************************/

function checkrequired(which, txt){
	var pass=true
	if (document.images){
		for (i=0;i<which.length;i++){
			var tempobj=which.elements[i]
			if (tempobj.name.substring(0,2)=="r_"){
				if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
					pass=false
					break
				}
			}
		}
	}
	if (!pass){
		alert("Champ(s) obligatoire(s) : " + txt + " ! \n Veuillez vérifier le(s) champ(s)")
		return false
	}else{	
		return true
	}
}

/***********************************************
* Fixed ToolTip script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
		
var tipwidth='150px' //default tooltip width
var tipbgcolor='white'  //tooltip bgcolor
var disappeardelay=0  //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset="0px" //horizontal offset of tooltip from anchor link
var horizontal_offset="30px" //horizontal offset of tooltip from anchor link


var message = Array();

// MESSAGES FOR LIENS
message[1] = "Les champs E-MAIL et NOM sont OBLIGATOIRES. Vous devez utiliser votre adresse email habituelle afin de vous identifier";


/////No further editing needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="fixedtipdiv" style="visibility:hidden;width:'+tipwidth+';background-color:'+tipbgcolor+'" ></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, tipwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
}
return edgeoffset
}

function fixedtooltip(contentNum, imgname, obj, e, tipwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidetip()
dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
if(imgname != ''){
	dropmenuobj.innerHTML='<span class="left"><img class="popimg" src="agendaImages/' + imgname + '" width="50" height="50"/></span><b>Description</b><br>' + message[contentNum];
}else{
	dropmenuobj.innerHTML=message[contentNum];
}

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}
}

function hidetip(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidetip(){
if (ie4||ns6)
delayhide=setTimeout("hidetip()",disappeardelay)
}

function clearhidetip(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

//  onclick="toggleTarget('altadressediv','block')"
function toggleTarget(what,how){	
	if(document.getElementById){
		document.getElementById(what).style.display=how;
	}
}

/************************** LIMIT NUM CHARACTERS IN FORM FIELD *******************************/

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}



function clientLoginDetect(){
	//alert("login detect");
	if(jsClientId &&(jsClientId!='')){
		return true;		
	}else{
		alert("veuillez vous identifier avant de commencer votre commande");
		window.location.replace("paniers-legumes-bio-login.php");
	}
}

//-->
