﻿var textBoxAmmountID = "mc_textBoxAmmount_";

function AddProduct(sender, productID, pageID)
{
	if(finishedAddingProdut)
	{
		//var ammountBox = GetElement(textBoxAmmountID + productID, "INPUT");
		var ammount = "1";

		//if(ammountBox != null){ammount = ammountBox.value;}
		
		if(ammount != "" && IsNumeric(ammount))
		{
			finishedAddingProdut = false;
			addToCartStartTime = new Date();
			if(sender.tagName == "IMG"){sender.src = "../images/loading2.gif"; clickedCartImage = sender; }

			makeHttpRequest(cartHandlerUrl + "?PageID=" + pageID + "&ProductID=" + productID + "&Ammount=" + ammount, "UpdateCartWhenFinished", false);
		}
	}
}

function ResetCartImage()
{
	if(clickedCartImage != null){clickedCartImage.src = "../Images/add_to_cart.jpg"; finishedAddingProdut = true;}
}

function FlashCart(target, count, time)
{
	//alert(target.id);
	if(target != null)
	{
		if(time <= count)
		{
			setTimeout('ChangeCartBorder(\"' + target.id + '\", ' + count + ', + ' + (time + 1) + ')', 500);
		}
		else
		{
			target.className = "cartAreaRedBorder"
		}
	}
}

function ChangeCartBorder(target, count, time)
{
	if(target != null)
	{
		var targetElement = GetElement(target, "DIV");
		
		if(targetElement.className == "cartArea")
		{
			targetElement.className = "cartAreaRedBorder"
		}
		else
		{
			targetElement.className = "cartArea"
		}
		
		FlashCart(targetElement, count, time)
	}
}