function getArrayElementIndex(array, elementVal)
{
	if (NS)
		return array.indexOf(elementVal);
	else
		for (var i=0;i<array.length;i++)
			if (array[i] == elementVal)
				return i;
	return -1;
}

function removeArrayElement(array, elIndex)
{
	if (elIndex >= array.length) return false;

	for (var i=elIndex;i<array.length;i++)
		if (i != (array.length - 1))
			array[i] = array[i+1];

	delete array[array.length - 1];
	array.length--;

	return true;
}

function SoppingCart()
{
	this.CartItems = new Array();
	this.LoadCartItems();
}

SoppingCart.prototype =
{
	CartItems: null,
	
	IsEnabled: function()
	{
		return document.forms[0].EnableShoppingCart.value.toLowerCase();
	},
	
	CheckForAbilityToAddItem: function(partID)
	{
		return (getArrayElementIndex(this.CartItems, partID) == -1);
	},
	
	LoadCartItems: function()
	{
		var scItems = (this.IsEnabled() == 'true') ? document.forms[0].sCartItems.value : '';
		
		if (scItems == '')
			this.Clear();
		else	
			this.CartItems = scItems.split(',');
	},
	
	AddNewItem: function(partID)
	{
		this.CartItems.push(partID);
	},
	
	DeleteItem: function(partID)
	{
		removeArrayElement(this.CartItems, getArrayElementIndex(this.CartItems, partID));
	},
	
	Clear: function()
	{
		while (this.CartItems.length > 0)
			this.CartItems.pop();
	}
}