//--------------------------------------------------------------------
//	val_qty_passed_in_min_max.js
//--------------------------------------------------------------------

function ValidateQty(form, minQty, maxQty)
{

    //alert("form.quantity.value"); 
	// strip leading and trailing blanks from string
	stripSpaces(form);
	//check if something was entered
   if(isEmpty(form.quantity.value)) 
   { 
      alert('You have not entered a quantity'); 
      form.quantity.focus(); 
      return false; 
   } 
 
	// check if only numbers 0->9 were entered 
   if (!IsNumeric(form.quantity.value)) 
   { 
      alert('Please enter a whole number with no decimals in the quantity field'); 
      form.quantity.focus(); 
      return false; 
	}

	// check if 0 was entered
	var num = parseInt(form.quantity.value);
	if(num <= 0)
	{
      alert('Please enter a non-zero amount in the quantity field'); 
	  form.quantity.focus(); 
      return false; 
	}
 
	// if passed-in minQty is not -1 then we need to check it
	if(minQty != -1)
	{
		if(num < minQty)
		{
		  alert('The minimum order quantity is ' + minQty); 
		  form.quantity.focus(); 
		  return false; 
		}
	}

	// if passed-in maxQty is not -1 then we need to check it
	if(maxQty != -1)
	{
		if(num > maxQty)
		{
		  alert('The maximum order quantity is ' + maxQty); 
		  form.quantity.focus(); 
		  return false; 
		}
	}



	return true;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (var i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function isEmpty(field)
{
	return ((field == null) || (field.length == 0)) 
}

function stripSpaces(myForm)
{
	var x = myForm.quantity.value;
	while (x.substring(0,1) == ' ') x = x.substring(1);
	while (x.substring(x.length-1,x.length) == ' ') x = x.substring(0,x.length-1);
	myForm.quantity.value = x;
}


