﻿
function doUpdateQuantity(frmBasket,flag)
{
	frmBasket.action = uri + "global/shopping.asp";
	frmBasket.returnALERT.value = flag?flag:"true";
	frmBasket.op.value = "update";
	frmBasket.target = "hidden";
	frmBasket.submit();
}

function doCheckout(frmBasket)
{
	doUpdateQuantity(frmBasket,"false");

	frmBasket.action = uri + "global/checkout.asp";
	frmBasket.op.value = "add";
	frmBasket.target = "";

	if (frmBasket.position.value == 0)
	{
		alert (label_shopping_isnull);
		return false;
	}else{
		if (doCheckAccountPoints())
		{
			frmBasket.submit();
		}else{
			alert (LABEL_FP_SHOPPING_MYPOINTSNOTENOUGH_LESS.replace("{0}",MyAccountPoints));
			return false;
		}
	}
}

function doExecuteInBasket(thisform)
{
	var position = thisform.position.value;
	var total = 0;
	var totalqty = 0;

	for (var i=1;i<=position;i++)
	{
		var goodsprice = 0;
		var qty = $$$("qty_" + i).value;
		var price = $$$("price_" + i).value;

		goodsprice = qty * price;
		totalqty += parseInt(qty);;

		$$$("unti_" + i).innerHTML  = toFloat(price * 1,2);
		$$$("total_" + i).innerHTML = toFloat(goodsprice,2);

		total += goodsprice;
	}

	total = parseFloat(total);

	$$$("totalqty").innerHTML = totalqty;
	$$$("pay").value = toFloat(total,2);
	$$$("divTotalNonShipping").innerHTML = toFloat(total,2);
}

function doCheckAccountPoints()
{
	var shoppingPosition = $$$("shoppingPosition").value;
	returnValue = false;

	if (shoppingPosition > 0)
	{
		if (MyIsLogined == 0)
		{
			$$$("accountPointDescription").innerHTML = LABEL_FP_SHOPPING_MYPOINTSNOTENOUGH_NOTLOGIN;
		}else{
			if (MyAccountPoints == 0)
			{
				$$$("accountPointDescription").innerHTML = LABEL_FP_SHOPPING_MYPOINTSNOTENOUGH;
			}else{
				var shoppingPoints = $$$("shoppingPoints").value;

				if (MyAccountPoints >= shoppingPoints)
				{
					if (shoppingPoints != 0)
					{
						$$$("accountPointDescription").innerHTML = LABEL_FP_SHOPPING_MYPOINTSNOTENOUGH_ABOVE.replace("{0}",MyAccountPoints);
					}else{
						$$$("accountPointDescription").innerHTML = LABEL_FP_SHOPPING_MYPOINTS.replace("{0}",MyAccountPoints);
					}

					returnValue = true;
				}else{
					$$$("accountPointDescription").innerHTML = LABEL_FP_SHOPPING_MYPOINTSNOTENOUGH_LESS.replace("{0}",MyAccountPoints);
				}
			}
		}
	}else{
		returnValue = true;
	}

	return returnValue;
}