
function ValidateAvailability(o)
{
	if (o.ReadOnly == true)
		return;

	var i = parseInt(o.value);
	
	var avail = parseInt(o.availability);
	var original = parseInt(o.originalquantity);
	
	if (isNaN(avail)) 
		avail = parseInt(o.parentElement.availability);
	if (isNaN(avail)) 
		avail = 0;
	if (isNaN(i) && o.value != "")
	{ 
		alert("You must enter a number"); 
		if (IsCSR=='True')
			o.value = "0";
		else
			o.value = "" + OrderQuantity;
	}

	if (i < OrderQuantity && CartMode != 'Edit')
	{ 
		alert("The minimum order quantity is " + OrderQuantity); 
		o.value = "" + OrderQuantity; 
		return;
	}
	if (i < 0)
	{
		alert("Order Quantity set less than 0");
		o.value = "0"; 
		return;
	}		

	if((o.IsTag == 'False' || o.IsTag + '' == 'undefined') && !IsCSR=='True')
	{
		if (i > avail + original && !(o.enforceavailability == '1' || o.enforceavailability == '-1' || o.enforceavailability == 'True'))
		{
			alert("You must enter a number less than or equal to the available quantity");
			i = avail -51;
		}	
	}
		
	if (i < 0)
		i = 0;
	i = parseInt(Math.round((i)/OrderQuantity)) * OrderQuantity;
	
	if (!isNaN(i))
		o.value = i + "";
	else
	{	
		if (i=0) i = OrderQuantity; 
	}
}

function ValidateEOD(o)
{
	if(o.IsTag == 'False' || o.IsTag + '' == 'undefined')
		return;
	var i = parseInt(o.value);
	var original = parseInt(o.originalquantity);
	if (o.eodflag == '0' && o.PRCLEVEL == 'EOD' && i > original) 
	{ 
		alert("The early discount order period is over. You can not add more than the original quantity to this item. A new item with the additional amount requested will be added to the order at the standard price .");
		//o.value = o.originalquantity;
		return false;
	}
	return true;
	
}
