function ValidateProductForm()
{
	var str = ValidateInsertProduct();
		
	if(str!="")
	{
		alert(str);
		return false;
	}
		
	return true;
}

function ValidateInsertProduct()
{
  	if(!HasValue(document.main.iName.value)) return "Please enter a name for the product";
  	if(!HasValue(document.main.iShortDescription.value) || (document.main.iShortDescription.value == '<p></p>')) return "Please enter a short description for the product.";
  	if(!HasValue(document.main.iUnitPrice.value) || !IsFloat(document.main.iUnitPrice.value) || (parseFloat(document.main.iUnitPrice.value) < 0)) return "Please enter the unit price for the product.";
  	if(HasValue(document.main.iSalePrice.value) && (!IsFloat(document.main.iSalePrice.value) || (parseFloat(document.main.iSalePrice.value) < 0))) return "Please enter a valid sale price for the product, or leave it blank.";
  	if(!HasValue(document.main.iMinQuantity.value) || !IsNumeric(document.main.iMinQuantity.value) || (parseInt(document.main.iMinQuantity.value,10) < 1)) return "Please enter a positive numerical value for the min quantity.";
  	if(!HasValue(document.main.iMaxQuantity.value) || !IsNumeric(document.main.iMaxQuantity.value) || (parseInt(document.main.iMaxQuantity.value,10) < 1)) return "Please enter a positive numerical value for the max quantity.";
  	if(parseInt(document.main.iMinQuantity.value,10) > parseInt(document.main.iMaxQuantity.value,10)) return "The min quantity cannot be greater than the max quantity.";
  	if(!HasValue(document.main.iStockCount.value) || !IsNumeric(document.main.iStockCount.value) || (parseInt(document.main.iStockCount.value,10) < 0)) return "Please enter a non-negative numerical value for the stock count.";
  	
  	if(document.main.iIsShipable[0].checked || HasValue(document.main.iWeightInOunces.value))
  	{
		if(!HasValue(document.main.iWeightInOunces.value) || !IsFloat(document.main.iWeightInOunces.value) || (parseFloat(document.main.iWeightInOunces.value) < 0.5)) return "Please enter the weight (in ounces) for the product.";
	}
	
	return "";
}

function ValidateProductUpdateForm()
{
	var str = ValidateUpdateProduct();
		
	if(str!="")
	{
		alert(str);
		return false;
	}
		
	return true;
}

function ValidateUpdateProduct()
{
  	if(!HasValue(document.main.iName.value)) return "Please enter a name for the product";
  	if(!HasValue(document.main.iShortDescription.value) || (document.main.iShortDescription.value == '<p></p>')) return "Please enter a short description for the product.";
  	if(!HasValue(document.main.iUnitPrice.value) || !IsFloat(document.main.iUnitPrice.value) || (parseFloat(document.main.iUnitPrice.value) < 0)) return "Please enter the unit price for the product.";
  	if(HasValue(document.main.iSalePrice.value) && (!IsFloat(document.main.iSalePrice.value) || (parseFloat(document.main.iSalePrice.value) < 0))) return "Please enter a valid sale price for the product, or leave it blank.";
  	if(!HasValue(document.main.iMinQuantity.value) || !IsNumeric(document.main.iMinQuantity.value) || (parseInt(document.main.iMinQuantity.value,10) < 1)) return "Please enter a positive numerical value for the min quantity.";
  	if(!HasValue(document.main.iMaxQuantity.value) || !IsNumeric(document.main.iMaxQuantity.value) || (parseInt(document.main.iMaxQuantity.value,10) < 1)) return "Please enter a positive numerical value for the max quantity.";
  	if(parseInt(document.main.iMinQuantity.value,10) > parseInt(document.main.iMaxQuantity.value,10)) return "The min quantity cannot be greater than the max quantity.";
  	if(!HasValue(document.main.iStockCount.value) || !IsNumeric(document.main.iStockCount.value) || (parseInt(document.main.iStockCount.value,10) < 0)) return "Please enter a non-negative numerical value for the stock count.";
  	
  	if(document.main.iIsShipable[0].checked || HasValue(document.main.iWeightInOunces.value))
  	{
		if(!HasValue(document.main.iWeightInOunces.value) || !IsFloat(document.main.iWeightInOunces.value) || (parseFloat(document.main.iWeightInOunces.value) < 0.5)) return "Please enter the weight (in ounces) for the product.";
	}
	
	return "";
}
