function show_digibrochure()
{
	Lightview.show({
						href: 'http://www.luminati.co.uk/digibrochure/',
						options: 
						{
							width: 790,
							height: 660,
							closeButton: 'large',
							menubar: 'bottom'
						}
				   });
}

function thanks()
{
	document.observe('lightview:loaded', function() {
		Lightview.show({
							href: '/thanks.php',
							options: 
							{
								width: 410,
								height: 220,
								closeButton: 'large',
								menubar: 'bottom'
							}
					   });
	});
}

function continue_shopping()
{
	// hide the lightbox first
	Lightview.hide();
	
	// then refresh the current page
	refresh();
}

function refresh()
{
    window.location.reload(false);
}

function pass_item()
{	
	// get the id
	var theID_field = window.frames[0].document.getElementById('sc_product_number');
		
	var theID = theID_field.value;
	
	// add the item to the cart
	cart_add_item(theID);
}

function bespoke_enquiry(node, type)
{
	var theHeight = 515;
	
	if(type == 'brand')
	{
		theHeight = 570;	
	}
	
	Lightview.show({
						href: '/bespoke_enquiry.php?n=' + encodeURIComponent(node) + '&t=' + encodeURIComponent(type),
						options: 
						{
							width: 422,
							height: theHeight,
							closeButton: 'large'
						}
				   });	
}

function volume_form(node)
{
	var dimensions_element = document.getElementById('product_dimensions');
	var quantity = document.getElementById('dd_product_quantity').value;
	var selected_dimensions = dimensions_element.options[dimensions_element.selectedIndex].value;
	
	var colour_option = '';
	var extra_option = '';
	
	if(document.getElementById('product_colour'))
	{
		var colour_element = document.getElementById('product_colour');
		
		colour_option = colour_element.options[colour_element.selectedIndex].value;
	}
	
	if(document.getElementById('product_options'))
	{
		var extras_element = document.getElementById('product_options');
		
		extra_option = extras_element.options[extras_element.selectedIndex].value;
	}
	
	Lightview.show({
						href: '/contact_volume_form.php?n=' + encodeURIComponent(node) + '&d=' +  encodeURIComponent(selected_dimensions) + '&q=' + encodeURIComponent(quantity) + '&c=' + encodeURIComponent(colour_option) + '&e=' + encodeURIComponent(extra_option),
						options: 
						{
							width: 422,
							height: 480,
							closeButton: 'large'
						}
				   });	
}

function buy_item(node)
{
	Lightview.show({
						href: '/get_product_options.php?n=' + encodeURIComponent(node),
						options: 
						{
							width: 522,
							height: 215,
							closeButton: false
						}
				   });
}

function buy_item_table(form_id, min_quant)
{
	// this function is only called from the table output of the product options
	
	if ((xml_request.readyState == 4) || (xml_request.readyState == 0))
	{	
		// no form id has been passed correctly.
		if(form_id == undefined)
		{
			// so show an error message
			var response = 'Fail'
			
			var message = 'There was a problem finding the specific product you wanted to add to your basket. Please try again.';
			
			Lightview.show({
								href: '/add_error.php?m=' + encodeURIComponent(message) + '&t=' + encodeURIComponent(response),
								options: 
								{
									width: 522,
									height: 170,
									closeButton: false
								}
						   });	
		}
		else
		{
			// get the id			
			var theID = document.getElementById(form_id).sc_product_number.value;
			
			var amount = document.getElementById(form_id).sc_product_quantity.value;
			
			// get the amount
			if(amount == "" && min_quant != undefined)
			{
				var amount = min_quant;
			}
			else if(amount == "")
			{
				amount = 1;	
			}
			
			var post_variables = "sc_product_number=" + encodeURIComponent(theID) + "&sc_product_quantity=" + encodeURIComponent(amount);

			xml_request.open("POST", "/shopping_cart_add_item.php", true);
			xml_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xml_request.onreadystatechange = card_add_item_response;
			xml_request.send(post_variables);
		}
	}
}

function cart_add_item(id)
{
	if ((xml_request.readyState == 4) || (xml_request.readyState == 0))
	{
		if(id == undefined)
		{
			// get the id
			var theID = document.getElementById('sc_product_number').value;
			
			// get the amount selected
			if(document.getElementById('dd_product_quantity'))
			{
				var amount = document.getElementById('dd_product_quantity').value;
			}
			else
			{
				var amount = 1;
			}
		}
		else
		{
			// get the amount selected
			if(document.getElementById('dd_product_quantity'))
			{
				var amount = document.getElementById('dd_product_quantity').value;
			}
			else
			{
				var amount = 1;
			}
			
			var theID = id;
			
			var the_extras = '';
			
			// check to see if extras have been ticked
			if (document.getElementById('num_extras')) 
			{
				var num_extras = document.getElementById('num_extras').value;
				
				if (num_extras > 0) 
				{
					extras_price = 0;
					extra_fields = "";
					num_checked = 0;
					
					for (i = 1; i <= num_extras; i++) 
					{
						if (document.getElementById('extra_' + i).checked) 
						{
							extra = dimensions["Extra" + i]['details'];
							
							extra_id = dimensions["Extra" + i]['details']['id'];
							
							var comma = (num_checked > 0) ? '_' : '';
							
							the_extras += comma + extra_id;
							
							num_checked++;
						}
					}
				}
			}
		}
		
		var post_variables = "sc_product_number=" + encodeURIComponent(theID) + "&sc_product_quantity=" + encodeURIComponent(amount) + "&extras=" + encodeURIComponent(the_extras);

		xml_request.open("POST", "/shopping_cart_add_item.php", true);
		xml_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xml_request.onreadystatechange = card_add_item_response;
		xml_request.send(post_variables);
	}
}

function card_add_item_response()
{
	// find the summary cart
	if(xml_request.readyState == 4)
	{
		var doc = xml_request.responseXML;
		
		var response = doc.getElementsByTagName('response')[0].firstChild.nodeValue;
		
		var message = doc.getElementsByTagName('message')[0].firstChild.nodeValue;
		
		if(doc == null || response == 'Fail')
		{			
			Lightview.show({
								href: '/add_error.php?m=' + encodeURIComponent(message) + '&t=' + encodeURIComponent(response),
								options: 
								{
									width: 522,
									height: 170,
									closeButton: false
								}
						   });
		}
		else if(response == 'Success')
		{
			var groupref = doc.getElementsByTagName('group_ref')[0].firstChild.nodeValue;
			
			Lightview.show({
								href: '/added_to_basket.php?m=' + encodeURIComponent(message) + '&t=' + encodeURIComponent(response) + '&gr=' + encodeURIComponent(groupref),
								options: 
								{
									width: 522,
									height: 190,
									closeButton: false
								}
						   });
		}
	}
}

function show_shipping()
{
	Lightview.show({
						href: '/shipping-info.php',
						options: 
						{
							width: 500,
							height: 190,
							closeButton: 'large',
							menubar: 'bottom'
						}
				   });
}
