TableRow = new Class({
	initialize: function (id)
	{
		this.element = $('item_' + id);
		this.selected_class = 'selected';
		this.deleting_class = 'deleting';
	},
	
	highlight: function()
	{
		this.element.addClass(this.selected_class);
	},
	
	unhighlight: function()
	{
		this.element.removeClass(this.selected_class);
	},
	
	transition: function()
	{
		this.unhighlight();
		this.element.addClass(this.deleting_class);
	},
	
	hide: function()
	{
		if (this.element)
		{
			this.element.setStyle('display', 'none');
			this.element.empty();
		}
	}
});

function deleteRow(id, message, a_tag)
{
	row = new TableRow(id);	
	row.highlight();
	
	if(confirm(message))
	{
		row.transition();
		
		req = new XHR({method: 'get'});
		
		req.onSuccess = function(responseText, responseXML)
		{
			clearItem(id);
			row.hide();
		}
		
		req.send(a_tag.getAttribute('href'));
	}
	else
	{
		row.unhighlight();
	}
	
	return false;
}

var GCertificates = 0;
var GCertificatesTotal = 0;


function removeGC(id, message, a_tag, price)
{
	row = new TableRow(id);	
	row.highlight();
	
	if(confirm(message))
	{
		row.transition();
		
		req = new XHR({method: 'get'});
		
		req.onSuccess = function(responseText, responseXML)
		{
			row.hide();
			clearGC(price);
		}
		
		req.send(a_tag.getAttribute('href'));
	}
	else
	{
		row.unhighlight();
	}
	
	return false;
}
function clearGC(price)
{
	
	GCertificates -= 1;
	GCertificatesTotal -= price;
	if(GCertificates == 0)
	{
		$('giftcertificates').empty();
	}
	else
	{
		$('gctotal').innerHTML = '$' + GCertificatesTotal.toFixed(2);
	}
	
	updateItemsCount();
	
}
function addGC(price)
{
	GCertificates += 1;
	GCertificatesTotal += price;
}

function updateItemsCount()
{
	if (numShippingItems != null)
	{
		var c = GCertificates + numShippingItems;
		var elem = $('cartitemcount');
		
		if(elem)
		{
			if(c == 1)
			{
				elem.innerHTML = "Your Cart Contains 1 Item";
			}
			else
			{
				elem.innerHTML = "Your Cart Contains " + c + " Items";
			}
		}
	}
}

