// Add product to shopping basket
function AddProduct(productId)
{
	//return;
	var objectId = "product_" + productId;
	
	

	// Check if the product info is valid
	if (ValidateProductInfo(objectId))
	{
		// Post data to server
		PostProductInfoToServer(objectId);
	}
}

// Validate product info
function ValidateProductInfo(objectId)
{
	if (top.document.getElementById(objectId) == null) 
	{
		return false; // Admin mode
	}

	var arrValues = top.document.getElementById(objectId).value.split("^`*");
	var Quantity = top.document.getElementById("LotHidden" + arrValues[3]).value;
		
	if (Quantity.search("[^0-9]") != -1)
	{
		alert('Please enter numeric quantity value(s).');
		return false;
	}
	if (Quantity == '')
	{
		alert('Please enter at least one item quantity to order.');
		return false;
	}
	return true;
}

// Post product info to server in order to add it to shopping basket
function PostProductInfoToServer(objectId)
{
	// Get required data
	
	var arrValues	= top.document.getElementById(objectId).value.split("^`*");
	var ProductId	= arrValues[0];
	var ProductName = arrValues[1];
	var Quantity	= top.document.getElementById("LotHidden" + arrValues[3]).value;
	
	if (Quantity == '') return;

    var formObject		= top.document.getElementById("ProductDataForm");
	var productIdObject = top.document.getElementById("newitem");
	var quantityObject	= top.document.getElementById("quantity");
	var locationObject	= top.document.getElementById("newlocation");
	var productName = ProductName;

	productIdObject.value	= ProductId;
	quantityObject.value	= Quantity;
	locationObject.value	= window.location.href;
	formObject.submit();
}

function fnCheckKey()
{
	var intKeyCode = event.keyCode;
	if((intKeyCode < 48) || (intKeyCode > 57))
	{
		event.returnValue = false;
		return false;
	}
}
function fnCheckQnty(ctrl)
{
	var re = /\D/;
	var str = re.test(ctrl.value);
	if (str)
	{
		alert("De indtastede antal indeholder ugyldige karakterer.");
		ctrl.value = ctrl.parentElement.childNodes[1].value;
		ctrl.focus();
	}
	else
	{
		if((ctrl.value % ctrl.parentElement.childNodes[2].value) != 0)
		{
			alert("Det mindste antal der kan købes er minimumordern (" + ctrl.parentElement.childNodes[2].value + ") eller\net antal der kan deles med denne.");
			ctrl.value = ctrl.lotsize;
			ctrl.focus();
		}
	}
}