﻿// Fichier JScript
function quantite(ordre,id,stock)
{
	var qString = document.getElementById(id).value;
	var qInt = parseInt(qString);
	if(isNaN(qInt) || qString.charAt(0) == '-' || qString.charAt(0) == 0 || qString.charAt(0) == '')
	{
		alert('Entier non valide !');
		document.getElementById(id).value = '1';
	}
	else
	{
		if(ordre == 'plus' && qInt < stock)
		{
			document.getElementById(id).value = qInt + 1;
		}
		else if(ordre == 'plus' && qInt >= stock)
		{
			alert('Quantité indisponible');
		}
		else if(ordre == 'moins')
		{
			if(qInt > 1)
			{
				document.getElementById(id).value = qInt - 1;
			}
			else
			{
				alert("Vous ne pouvez pas saisir un nombre inférieur à 1");
				document.getElementById(id).value = '1';
			}	
		}
	}
}

