function ValidateAddToCart(f)
{
	var valid = true;
	var msg = 'The item was not added to your cart because:\n\n';
	
	if(f.SizeID.value == 0) { valid = false; msg += ' - You must select a size\t\n'; }
	if(f.ColourID.value == 0) { valid = false; msg += ' - You must select a colour\t\n'; }
	
	if(valid)
	{
		return true;
	}
	else
	{
		alert(msg);
		return false;
	}
}

function CalculatePrice(f)
{	
	var size = (f.SizeID.nodeName == 'SELECT') ? parseInt(f.SizeID.options[f.SizeID.selectedIndex].value) : parseInt(f.SizeID.value);
	var colour = (f.ColourID.nodeName == 'SELECT') ? parseInt(f.ColourID.options[f.ColourID.selectedIndex].value) : parseInt(f.ColourID.value);
	
	//alert(size);
	//alert(colour);
	
	var qty = parseInt(f.Quantity.options[f.Quantity.selectedIndex].value);
	
	var validoption = false;
	
	var price = document.getElementById('price').firstChild;
	var msg = document.getElementById('msg');
	var addbutton = document.getElementById('SubmitButton');
	
	if(size > 0 && colour > 0)
	{
		for(var x=0; x<productoptions.length; x++)
		{
			if(productoptions[x].SizeID == size && productoptions[x].ColourID == colour)
			{
				if(productoptions[x].Stock)
				{
					price.nodeValue = (productoptions[x].Offer) ? 'Special Offer: £' + productoptions[x].OfferPrice : '£' + productoptions[x].Price;
					addbutton.disabled = false;
				}
				else
				{
					price.nodeValue = 'Out Of Stock';
					addbutton.disabled = true;
				}
				
				msg.style.display = 'none';
				validoption = true;
				
				break;
			}
		}
		
		if(!validoption)
		{
			price.nodeValue = 'Not Available';
			addbutton.disabled = true;
		}
	}
	else
	{
		price.nodeValue = range;
		msg.style.display = 'block';
		addbutton.disabled = true;
	}
}

function ProductOption(sizeid, colourid, price, offer, offerprice, stock)
{
	this.SizeID = sizeid;
	this.ColourID = colourid;
	this.Price = price;
	this.Offer = offer;
	this.OfferPrice = offerprice;
	this.Stock = stock;
}

function SetupAddForm()
{
	if(document.forms['optionform'])
	{
		var f = document.forms['optionform'];
		
		if(f.ColourID.nodeName == 'SELECT' || f.SizeID.nodeName == 'SELECT')
			document.getElementById('SubmitButton').disabled = true;
		
		if(f.SizeID.nodeName == 'SELECT')
			f.SizeID.selectedIndex = 0;
		
		if(f.ColourID.nodeName == 'SELECT')
			f.ColourID.selectedIndex = 0;
	}
}

addEvent(window, 'load', SetupAddForm);