
// dans le cas ou on vient du détail du coffre
if (dansCoffre == null) {
  var dansCoffre = new Array();
}

//Fonction incr&eacute;mente quantit&eacute; article panier
function inc(cug,qteMaxComm,stockRestant,objet,i,libelle,typeStockPanier,stockCirculantDispo) {

	var inputQuantite = objet.parentNode.getElementsByTagName('INPUT');
 
	// Controle quantite saisie lors de la mise au coffre par rapport a la qte commandable
	var qteSaisie = parseInt(inputQuantite[0].value , 10);
	var qteLim = qteMaxComm;
	
	if ( dansCoffre[cug] )
		qteSaisie += dansCoffre[cug];
	
	
	if(typeStockPanier=="NO" || typeStockPanier=="SC_NON_ACTIVE")
	{
		//alert(typeStockPanier+" "+qteMaxComm+" "+stockRestant );
		if (qteMaxComm > stockRestant || qteMaxComm == 0)
			qteLim = stockRestant;
	}
	//alert(typeStockPanier);
	if(typeStockPanier=="SC_ACTIVE" || typeStockPanier=="SC_NON_ACTIVE_CRENEAU_OK")
	{
		//alert(typeStockPanier);
		if ((qteMaxComm > (stockRestant+stockCirculantDispo)) || qteMaxComm == 0)
			qteLim = parseInt(stockRestant+ parseInt(stockCirculantDispo));
		//alert(qteLim);
					
	}
	
	if(typeStockPanier=="SE_ACTIVE" || typeStockPanier=="SE_NON_ACTIVE")
	{
		
		qteLim = 50;
		//alert("qteLim "+qteLim);
	}
	
	
		
	bool = true;
	
	if (qteLim <= 0 ) {
		alert($("#quantiteMaxTextWithoutStock").val());
//		alert ("Vous avez atteint la quantité maximum commandable pour le produit "+libelle);
		bool = false;
	} 
	
	if (qteSaisie >= qteLim && qteLim > 0) {
		alert($("#quantiteMaxText").val()+" "+qteLim+")");
		bool = false;
	} 
	
	if (bool == true ) inputQuantite[0].value++;
			
			//alert("+++/qteSaisie="+qteSaisie+"\ndans coffre = " + dansCoffre[cug]+"\nqteMaxComm"+qteMaxComm+"\nstockRestant"+stockRestant);
	return true;
}

/*function inc(objet){
	var inputQuantite = objet.parentNode.getElementsByTagName('INPUT');
   inputQuantite[0].lvalue++;
}*/
         
//Fonction d&eacute;cr&eacute;mente quantit&eacute; article panier
function dec(objet,prov){
	var inputQuantite = objet.parentNode.getElementsByTagName('INPUT');
	if ( prov=='mag'){
   		if (inputQuantite[0].value > 1) {
        	inputQuantite[0].value--;
     	}
   	} else {
   		if (inputQuantite[0].value > 0) {
        	inputQuantite[0].value--;
        }
   	}
	return true;
}
//Fonction saisie au clavier de la quantité article panier
function saisieQte(cug,qteMaxComm,stockRestant,objet,i,libelle,prov,typeStockPanier,stockCirculantDispo) {

	if ( prov=='mag'){
		if ( objet.parentNode.getElementsByTagName('INPUT')[0].value == "" ||objet.parentNode.getElementsByTagName('INPUT')[0].value == "0") {
			alert("La quantité ne peut etre vide !");
			objet.parentNode.getElementsByTagName('INPUT')[0].value = "1" ;
			bool = false;
			return;
		}
	} else {
		if ( objet.parentNode.getElementsByTagName('INPUT')[0].value == "" ) {
			alert("La quantité ne peut etre vide !");
			objet.parentNode.getElementsByTagName('INPUT')[0].value = "1" ;
			bool = false;
			return;
		}
	}
	
	if(isNaN(objet.parentNode.getElementsByTagName('INPUT')[0].value) == true)
	 {
	  alert("'"+objet.parentNode.getElementsByTagName('INPUT')[0].value+"' "+"n'est pas un nombre !");
	  objet.parentNode.getElementsByTagName('INPUT')[0].value = "1" ;
	  bool = false;
	  return;
	 }
	
	var inputQuantite = objet.parentNode.getElementsByTagName('INPUT');
 
	// Controle quantite saisie lors de la mise au coffre par rapport a la qte commandable
	var qteSaisie = parseInt(inputQuantite[0].value , 10);
	var qteLim = qteMaxComm;
	var qteCoffre = 0;
	if ( dansCoffre[cug] ){
		//alert("qteSaisie="+qteSaisie+"\ndans coffre = " + dansCoffre[cug]+"\nqteMaxComm"+qteMaxComm+"\nstockRestant"+stockRestant);
		qteCoffre = dansCoffre[cug];
		qteSaisie += dansCoffre[cug];

	}
	
		if(typeStockPanier=="NO" || typeStockPanier=="SC_NON_ACTIVE")
	{
		//alert(typeStockPanier+" "+qteMaxComm+" "+stockRestant );
		if (qteMaxComm > stockRestant || qteMaxComm == 0)
			qteLim = stockRestant;
	}
	//alert(typeStockPanier);
	if(typeStockPanier=="SC_ACTIVE" || typeStockPanier=="SC_NON_ACTIVE_CRENEAU_OK")
	{
		if ((qteMaxComm > (stockRestant+stockCirculantDispo)) || qteMaxComm == 0)
			qteLim = parseInt(stockRestant+parseInt(stockCirculantDispo));
		
					
	}
	
	if(typeStockPanier=="SE_ACTIVE" || typeStockPanier=="SE_NON_ACTIVE")
	{
		
		qteLim = 50;
		//alert("qteLim "+qteLim);
	}
	
	
		
	bool = true;
	
	if (qteLim <= 0 ) {
		alert ($("#quantiteMaxTextWithoutStock").val());
//		alert ("Vous avez atteint la quantité maximum commandable pour le produit "+libelle);
		inputQuantite[0].value = qteLim - qteCoffre;
		if (inputQuantite[0].value<1){inputQuantite[0].value=1;}
		bool = false;
	} 
	
	if (qteSaisie > qteLim && qteLim > 0) {
		alert ($("#quantiteMaxText").val()+" "+qteLim+")");
//		alert("la quantité maximum autorisée pour le produit "+libelle  +" est de "+qteLim+". Veuillez modifier la quantité.");
		inputQuantite[0].value = qteLim - qteCoffre;
		bool = false;
	} 
	
}

// Controle quantite saisie lors de la mise au coffre par rapport a la qte commandable
function ctrlQteComm(qteMaxComm,stockRestant,i) {
	var qteSaisie = document.getElementsByName('qty')[i].value;
	var qteLim = qteMaxComm;
	if (qteMaxComm > stockRestant || qteMaxComm == 0)
		qteLim = stockRestant;
	bool = true;
	if (qteSaisie > qteLim) {
		alert($("#quantiteMaxText").val()+" "+ qteLim + ")");
		bool = false;
		//alert("La quantité maximum autorisée est de " + qteLim + ". Veuillez modifier la quantité.");
	}
	return bool;
}

