function AddToCart(units,qty) {
	if(BagCount()==units*qty) {$("#formFlavors").submit();return true;}
	return false;
}
function AdjustCart(units,qty) {
	if(BagCount()==units*qty) return true;
	return false;
}
function BagCount() {
	var s=0;
	$("#formFlavors input[type=text]").each(function(intIndex){s+=Number(this.value);});
	return s;
}
function ButtonActivate(btn) {
	var f="#"+($(btn.form).attr("name"))+" #chooseFlavors";
	if(btn.value>0 && btn.value%1==0) {
		$(f).attr("disabled","");
		return;
	}
	$(f).attr("disabled","disabled");
}
function CartObjectsEnable(obj) {
	var n=$(obj.form).attr("name");
	var f="#"+(n)+" #"+n+"chooseFlavors";
	$(f).attr("disabled","");
	f="#"+(n)+" #"+n+"cartQuantity";
	$(f).attr("disabled","");
	$(f).focus();
	return;
}
function FlavorChooser(sc,id,units,qty) {
	ModalBox('modalView', 'vwFlavorChooser&vwName=flavors&id='+id+'&units='+units+'&qty='+qty+'&sc='+sc);
	return false;
}
function FlavorChooserEdit(sc,id,units,qty,ci) {
	ModalBox('modalView', 'vwFlavorChooser&vwName=flavorsEdit&id='+id+'&units='+units+'&qty='+qty+'&sc='+webRoot+'&ci='+ci);
	return false;
}
function QuantityCheck(units,qty,ctrl) {
	var c=Number($(ctrl).val());
	if(BagCount()>units*qty||!isNumeric(c)){$(ctrl).val('');QuantityCheck(units,qty,ctrl);return false;}
	$(ctrl).val(c?c:'');
	$("#bagCount").html("You have "+((units*qty)-BagCount())+" out of "+units*qty+" bags remaining");
}