function select_product_dimensions(dimensions_element)
{
	// get the selected dimensions
	var selected_dimensions = dimensions_element.options[dimensions_element.selectedIndex].value;

	// clear the colours list
	var colour_element = document.getElementById('product_colour');

	colour_element.options.length = 0;

	// clear the prices
	var prices_container = document.getElementById('product_prices');
	prices_container.innerHTML = '';

	if(selected_dimensions == "")
	{
		colour_element.options[0] = new Option("Please select dimensions", "");
		return false;
	}

	colour_element.options[0] = new Option("Please select a colour", "");

	var options_count = 1;

	for (var colour in dimensions[selected_dimensions])
	{
		if(dimensions[selected_dimensions].hasOwnProperty(colour))
		{
			colour_element.options[options_count] = new Option(colour, colour);
			options_count++;
		}
	}
}

function select_product_colour(colour_element, node)
{
	// get the selected dimensions
	var dimensions_element = document.getElementById('product_dimensions');
	var selected_dimensions = dimensions_element.options[dimensions_element.selectedIndex].value;

	// get the selected colour
	var selected_colour = colour_element.options[colour_element.selectedIndex].value;

	var prices = dimensions[selected_dimensions][selected_colour];

	var html = 	'<br />'+
				'<table style="width:100%;">'+
					'<tr>'+
						'<td style="width:125px;"><strong>Price per unit</strong></td>'+
						'<td>' + get_price_output(prices['price'], node) + '</td>'+
					'</tr>';

	if(prices['5off'] != "")
	{
		html += 	'<tr>'+
						'<td><strong>5 - 9</strong></td>'+
						'<td>' + get_price_output(prices['5off'], node) + '</td>'+
					'</tr>';
	}

	if(prices['10off'] != "")
	{
		html += 	'<tr>'+
						'<td><strong>10 - 19</strong></td>'+
						'<td>' + get_price_output(prices['10off'], node) + '</td>'+
					'</tr>';
	}

	if(prices['20off'] != "")
	{
		html += 	'<tr>'+
						'<td><strong>20 - 49</strong></td>'+
						'<td>' + get_price_output(prices['20off'], node) + '</td>'+
					'</tr>';
	}

	if(prices['50off'] != "")
	{
		html += 	'<tr>'+
						'<td><strong>50 - 99</strong></td>'+
						'<td>' + get_price_output(prices['50off'], node) + '</td>'+
					'</tr>';
	}

	if(prices['100off'] != "")
	{
		html += 	'<tr>'+
						'<td><strong>100+</strong></td>'+
						'<td>' + get_price_output(prices['100off'], node) + '</td>'+
					'</tr>';
	}

	html += 		'<tr>'+
						'<td><br /><strong>Quantity</strong></td>'+
						'<td><br /><form id="frm_buy_product" name="frm_buy_product" method="post" action="cart.php"><input type="hidden" id="sc_product_number" name="sc_product_number" value="" /><input type="text" name="sc_product_quantity" size="1" value="1" /> <input type="button" name="btn_buy_product" value="Buy" onclick="buy_product();"/></form></td>'+
					'</tr>'+
				'</table>';

	var prices_container = document.getElementById('product_prices');
	prices_container.innerHTML = html;

	var product_number = document.getElementById('sc_product_number');
	product_number.value = prices['id'];
}

function get_price_output(value, node)
{
	var output = '';

	switch (value.toLowerCase())
	{
		case 'n/a': output = 'Not Available'; break;
		case 'contact': output = '<a title="Contact Us" href="contact.php">Contact us.</a>'; break;
		case 'stockists': output = '<a title="Stockists" href="stockists.php?p=' + node + '">Stockists</a>'; break;
		default:  output = '&pound;' + value; break;
	}
	
	return output;
}

function buy_product()
{
	document.frm_buy_product.submit();
}