var sTmpVarList;
function checkQuantity(value1, StockQty, txtbox, frm, thisForm, ItemMFGDesc, blnHideProducts, bHasVariants)
{
	for(var intEleCount =0;intEleCount <frm.elements.length;intEleCount++)
	{
		if(frm.elements[intEleCount].name == "ProdQty")
		{	
			value2 = txtbox.value
							
			if (isNaN(value2))
				{
				 	alert("Please enter a valid quantity");
				 	//txtbox.focus()
				 	return false
				}
			//if(!validate_INTEGER(txtbox,"quantity")) return false;	
			if (parseFloat(value2) != parseInt(parseFloat(value2)))
				{
					alert("The quantity for this product should be a whole number")
		 			if (txtbox.type != 'hidden')
		 				txtbox.focus();
					return false
				}
			if (!validate_DOUBLE(txtbox,"quantity")) return false;		
			if (value1 > value2)
				{
					alert("The minimum quantity for this product is " + value1)
					txtbox.value = value1
		 			if (txtbox.type != 'hidden')
		 				txtbox.focus();
					return false;
				}
			if(blnHideProducts == "1")
			{
				sTmpVarList = '';
				if (bHasVariants) 
					StockQty = GetMaxStockQty(thisForm,StockQty)
				if (value2 > StockQty && StockQty != -1)
					{
						if (sTmpVarList!='')
							ItemMFGDesc=ItemMFGDesc + '(' + sTmpVarList + ')'
						if(StockQty != 0) {
							alert('The available quantity in stock for "' + ItemMFGDesc + '" is ' + StockQty + '. Please reduce the order quantity in order to proceed');
						} else {
							alert(ItemMFGDesc + ' is not in stock at this time. Please check back later.');
						}
											
						return false;
					}
			}
		}
	}
	return true;
}

function GetMaxStockQty(frm, vStockQty)
{
	var tmpMaxValue
	var finalMaxValue
	sTmpVarList = '';
	finalMaxValue = vStockQty
	for (i = 1; i <= frm.GroupCounter.value; i++)
	{
		ind = frm.elements["VariantGroup" + i].selectedIndex
		tmpMaxValue = eval(frm.name + '_varMaxStock' + i + '[' + ind + ']');
		if (tmpMaxValue<finalMaxValue && tmpMaxValue!=-1)
			finalMaxValue = tmpMaxValue;

		//for getting the variant options string
		if (sTmpVarList != '')
			sTmpVarList = sTmpVarList + ' - '
		sTmpVarList = sTmpVarList + (frm.elements["VariantGroup" + i].options[ind].text);

	}
	return finalMaxValue;
}

function checkQuantitySetPrice(frm,value1,StockQty, txtbox, frm_next,ItemMFGDesc, strProdVarIDDesc, strProdPrice, blnHideProductsinStk)
{
	if (checkQuantity(value1, StockQty, txtbox, frm_next, frm,ItemMFGDesc, blnHideProductsinStk, true))
	{
		description_text = ""
		total_price = 0
		for (i = 1; i <= frm.GroupCounter.value; i++)
		{
			ind = frm.elements["VariantGroup" + i].selectedIndex
																					
			description_text += frm.elements["VariantGroup" + i][ind].value + ";"
			total_price += parseFloat(frm.elements["variant" + i + "_" + (ind + 1)].value)
		}
		frm.elements[strProdVarIDDesc].value = description_text			
		frm.elements[strProdPrice].value = parseFloat(frm.elements[strProdPrice].value) + total_price
		return true
	}
	else
		return false
}
