
function DeleteBasket(BasketID)
{
	var data = "action=DeleteBasket&BasketID=" + BasketID;	
	var thepage = "/modules/basket/processbasket.asp";
	var DeleteItem = function (oXML) {
		var retvalue = oXML.responseText;
		regularCursor();
	}	
	if (confirm('Are you sure you want to delete the item from basket?'))
	{
		hiddenSubmit(thepage, data, completedSingleLoad, 1, 'topcontent', null, false)
		checkAction(60,211,1,null,false,null,false);
	}
}

function SaveBasket(InputQty, StockID, PriceDiv, UnitPrice,StockCount, StockTypeID)
{
	var Quantity = InputQty.value;
	var OrgQty = document.getElementById('txtPrevQty_'+StockID).value;
	
	if(Quantity == '')
	{
		Quantity = 0;	
	}
	if(InputQty.value > StockCount)
	{
		alert("The warehouse hasn't got sufficient stock to fulfill this request. Please reduce your quantity");
		InputQty.focus();
	}
	else
	{
		var AfterSaveBasket = function (oXML) {
			var retvalue = oXML.responseText;
			if (retvalue != '')
			{
				var PriceValue = (Quantity * UnitPrice);
				var SubTotal = Math.round(retvalue);
				var Vat = (SubTotal * .14);
				var Total = Math.round(SubTotal + Vat);
				
				document.getElementById(PriceDiv).innerHTML = 'R ' + CurrencyFormatted(Math.round(PriceValue));
				document.getElementById('spSubTotal').innerHTML = 'R ' + CurrencyFormatted(SubTotal);
				var Vat = document.getElementById('spVat').innerHTML = 'R ' + CurrencyFormatted(Vat);
				var Total = document.getElementById('spTotal').innerHTML = 'R ' + CurrencyFormatted(Total);	
			}
			regularCursor();
		}
		
		var QtyExceed = false;
		var EngTotal = document.getElementById('EngValue').value;
		var MathTotal = document.getElementById('MathValue').value;
		var EQtyAllowed = document.getElementById('EngAllowed').value;
		var MQtyAllowed = document.getElementById('MathAllowed').value;
		var EDiffQty = 0;
		var MDiffQty = 0;
		var SEngTotal;
		var SMathTotal;
		
		if(StockTypeID == 5)
		{
			EDiffQty = eval(Quantity) - eval(OrgQty);
			EngTotal = eval(EngTotal) + eval(EDiffQty);
		
			SEngTotal = EngTotal;	
			if (EngTotal > EQtyAllowed)
			{
				SEngTotal = '<font color=#ff0000>' + EngTotal + '</font>'
			}
			else
			{
				SEngTotal = '<font color=#000000>' + EngTotal + '</font>'
			}
			
		}
		else if(StockTypeID == 6)
		{
			MDiffQty = eval(Quantity) - eval(OrgQty);
			MathTotal = eval(MathTotal) + eval(MDiffQty);
			//alert(MathTotal);	
			SMathTotal = MathTotal;	
			if(MathTotal > MQtyAllowed)
			{
				SMathTotal = '<font color=#ff0000>' + MathTotal + '</font>'
			}
			else
			{
				SMathTotal = '<font color=#000000>' + MathTotal + '</font>'
			}
			
		}
		
		var data = "action=SaveBasket&StockID=" + StockID + "&Qty=" + Quantity;	
		var thepage = "/modules/basket/processbasket.asp";
		hiddenSubmit(thepage, data, AfterSaveBasket, 1, 'topcontent', null, false)
		//alert(document.getElementById(PriceDiv).innerHTML);
		if (StockTypeID == 5)
		{
			document.getElementById('EngTotal').innerHTML = SEngTotal;
			document.getElementById('EngValue').value = EngTotal;
		}		
		else if(StockTypeID == 6)
		{
			document.getElementById('MathTotal').innerHTML = SMathTotal;
			document.getElementById('MathValue').value = MathTotal;
		}
			
		document.getElementById('txtPrevQty_'+StockID).value = Quantity;
	}
}

function SaveStoredBasket(InputQty, StockID, BasketName)
{
	var Quantity = InputQty.value;
	if(Quantity == '')
	{
		Quantity = 0;	
	}
	var data = "action=SaveStoredBasket&StockID=" + StockID + "&Qty=" + Quantity + "&BaketName=" + encodeURIComponent(BasketName);	
	var thepage = "/modules/basket/processbasket.asp";
	hiddenSubmit(thepage, data, completedSingleLoad, 1, 'topcontent', null, false)
}

function StoreBasket()
{
	var thepage = "/modules/basket/edBasketName.asp";
	returnid = openModalWindow(thepage,520,150,'');
	if(returnid != '' && returnid != 'undefined' && returnid != null)
	{
		data = "action=StoreBasket&BasketName="+returnid;
		thepage = "/modules/basket/processbasket.asp";
		hiddenSubmit(thepage, data, alertHiddenResponse, 1, 'topcontent', null, false)
	}
}

function ClearBasket()
{
	var data = "action=ClearBasket";
	var thepage = "/modules/basket/processbasket.asp";
	var DeleteItem = function (oXML) {
		var retvalue = oXML.responseText;
		regularCursor();
	}	
	if (confirm('Are you sure you want to clear your items from basket?'))
	{
		hiddenSubmit(thepage, data, completedSingleLoad, 1, 'topcontent', null, false)
		checkAction(60,211,1,null,false,null,false);
	}
}

function DeleteStoredBasket(BasketName)
{
	var data = "action=DeleteStoredBasket&BasketName="+encodeURIComponent(BasketName);
	var thepage = "/modules/basket/processbasket.asp";
	
	var DeleteSTBasket = function (oXML) {
		var retvalue = oXML.responseText;
		regularCursor();
	}	
	
	if (confirm('Are you sure you want to delete stored basket?'))
	{
		hiddenSubmit(thepage, data, DeleteSTBasket, 1, 'topcontent', null, false)
		checkAction(60,211,1,null,false,null,false);		
	}
}

function DeleteStoredBasketItem(BasketStorageID, StockID)
{
	var data = "action=DeleteStoredBasketItem&BasketStorageID=" + BasketStorageID + '&StockID=' + StockID;	
	var thepage = "/modules/basket/processbasket.asp";
	var DeleteItem = function (oXML) {
		var retvalue = oXML.responseText;
		regularCursor();
	}	
	if (confirm('Are you sure you want to delete the item from stored basket?'))
	{
		hiddenSubmit(thepage, data, DeleteItem, 1, 'topcontent', null, false)
	}
}

function OpenBasket()
{
	var thepage = "/modules/basket/edBasketName.asp?action=SavedBasket";
	returnid = openModalWindow(thepage,520,150,'');
	if(returnid != '' && returnid != 'undefined' && returnid != null)
	{
		if (confirm('Are you sure you want to open stored basket because it will replace your current basket?'))
		{
			data = "action=StoreBasket&BasketName="+returnid;
			thepage = "/modules/basket/edStoredBasket.asp";
			hiddenSubmit(thepage, data, completedSingleLoad, 1, 'topcontent', null, false)
		}
	}
}

function CheckOutBasket()
{
	var data = "action=CheckoutBakset"
	var thepage = "/modules/orders/edCheckout.asp";
	hiddenSubmit(thepage, data, completedSingleLoad, 1, 'topcontent', null, false)
}
