/*
	Plays the clock.
*/
function wshop_clock()
{
	var movie = new SWFObject('clock.swf', 'movie_clock', '178', '169', '9');
	movie.addParam('scale', 'noscale');
	movie.addParam('wmode', 'transparent');
	movie.write('area_top_clock')
	
	return false;
}


/*
	Initialises the timer for the Daily Giveaway page.
*/
var wshop_giveaway_midnight;
function wshop_giveaway_timer()
{
	wshop_giveaway_midnight = new Date();
	wshop_giveaway_midnight.setTime(document.getElementById('area_middle_right_page_products_giveaway_midnight').value * 1000);
	wshop_giveaway_timer_update();
}
function wshop_giveaway_timer_update()
{
	var difference = wshop_giveaway_midnight.getTime() - (new Date()).getTime();
	
	if (difference > 0)
	{
		var hours = parseInt(difference / 3600000);
		difference = difference - (hours * 3600000);
		hours = hours.toString();
		if (hours.length == 1)
			hours = '0'+hours;
			
		var minutes = parseInt(difference / 60000);
		difference = difference - (minutes * 60000);
		minutes = minutes.toString();
		if (minutes.length == 1)
			minutes = '0'+minutes;
	
		var seconds = parseInt(difference / 1000);
		seconds = seconds.toString();
		if (seconds.length == 1)
			seconds = '0'+seconds;
	
		for (var i = 0; i < 7; i++)
		{
			if (document.getElementById('area_middle_right_page_products_giveaway_'+i+'_time'))
			{
				if (i == 1)
					document.getElementById('area_middle_right_page_products_giveaway_'+i+'_time').innerHTML = i+' DAY, '+hours+':'+minutes+':'+seconds;
				else if (i > 0)
					document.getElementById('area_middle_right_page_products_giveaway_'+i+'_time').innerHTML = i+' DAYS, '+hours+':'+minutes+':'+seconds;
				else
					document.getElementById('area_middle_right_page_products_giveaway_'+i+'_time').innerHTML = hours+'&nbsp;:&nbsp;'+minutes+'&nbsp;:&nbsp;'+seconds;
			}
		}
		
		setTimeout('wshop_giveaway_timer_update()', 1000);
	}
}


/*
	Prints the viewable area of the page.
*/
function wshop_print()
{
	var area_content = null;
	try { area_content = document.getElementById('area_middle_both'); } catch (e) { }
	if (area_content === null)
		area_content = document.getElementById('area_middle_right');
	
	var print_window = window.open('','wshop_print_window','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400,height=550');
	print_window.document.open();
	print_window.document.title = 'www.watchesshop.com';
	print_window.document.write("<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"wshop_001.css\" /></head><body>"+area_content.innerHTML+"</body></html>");
	print_window.document.getElementsByTagName('body')[0].style.background = "none";
	print_window.document.close();

	print_window.focus();
	print_window.print();
	//print_window.close();

	return false;
}


/*
	Opens up a 3D product view.
*/
function wshop_3d(product_id)
{
	var movie = new SWFObject('threed.swf?url_root='+wshop_url_root+'&product_id='+product_id, 'movie_3d', '400', '440', '9');
	movie.addParam('scale', 'noscale');
	movie.addParam('wmode', 'transparent');
	movie.write('area_3d_movie')

	document.getElementById('area_3d').style.display = 'block';
	
	return false;
}
function wshop_3d_close()
{
	document.getElementById('area_3d').style.display = 'none';
	
	return false;
}


/*
	Opens up a zoomed product view.
*/
var wshop_zoom_opens = Array();
var wshop_zoom_zindex = 1000;
function wshop_zoom(product_id)
{
	wshop_zoom_zindex++;
	document.getElementById('area_modules_zoom_'+product_id).style.zIndex = wshop_zoom_zindex;
	
	Effect.Grow('area_modules_zoom_'+product_id, { direction : 'bottom-right', duration : 0.2, afterFinish : function()
		{
			Effect.Appear('area_modules_zoom_'+product_id+'_inner', { duration : 0.2 });
		}
	});
	wshop_zoom_opens[wshop_zoom_opens.length] = 'area_modules_zoom_'+product_id;
	
	document.onkeyup = function (e)
	{
		var keycode = '';
		try
		{
			keycode = e.keyCode;
		}
		catch (ex)
		{
			keycode = window.event.keyCode;
		}
		if (keycode == '27')
		{
			for (var i = 0; i < wshop_zoom_opens.length; i++)
			{
				wshop_zoom_close(wshop_zoom_opens[i]);
			}
			wshop_zoom_opens = Array();
		}
	};
	
	return false;
}
function wshop_zoom_close(area_id)
{
	document.getElementById(area_id).style.display = 'none';
	document.getElementById(area_id+'_inner').style.display = 'none';
	//Effect.Fade(area_id, { duration : 0.5 });
	
	return false;
}


/*
	Product Details.  Two functions:
	
		- Record the view.
		- Replace the current product image.
		- Enlarge the current product image.
*/
var wshop_details_enlarged = false;
var wshop_details_draggle;
function wshop_details_viewed(variation_id)
{
	var xml_response = wshop_request(wshop_url_root+'interface/products_viewed.do', 'variation_id='+variation_id);
	return false;
}
function wshop_details_replace(url_large, url_original)
{
	document.getElementById('area_middle_right_page_products_details_large').value = url_large;
	document.getElementById('area_middle_right_page_products_details_original').value = url_original;
	if (wshop_details_enlarged)
	{
		document.getElementById('area_middle_right_page_products_details_image_image').style.left = '0px';
		document.getElementById('area_middle_right_page_products_details_image_image').style.top = '0px';
		document.getElementById('area_middle_right_page_products_details_image').style.cursor = 'auto';
		document.getElementById('area_middle_right_page_products_details_image_enlarge').style.display = 'block';
		wshop_details_enlarged = false;
		wshop_details_draggle.destroy();
	}
	wshop_changeimage(document.getElementById('area_middle_right_page_products_details_image_image'), document.getElementById('area_middle_right_page_products_details_large').value);

	return false;
}
function wshop_details_enlarge()
{
	wshop_changeimage(document.getElementById('area_middle_right_page_products_details_image_image'), document.getElementById('area_middle_right_page_products_details_original').value);
	wshop_details_draggle = new Draggable('area_middle_right_page_products_details_image_image', { starteffect : null, endeffect : null } );
	document.getElementById('area_middle_right_page_products_details_image').style.cursor = 'move';
	document.getElementById('area_middle_right_page_products_details_image_enlarge').style.display = 'none';
	wshop_details_enlarged = true;
	
	document.getElementById('area_middle_right_page_products_details_image_image').onload = function()
	{
		document.getElementById('area_middle_right_page_products_details_image_image').style.left = (((document.getElementById('area_middle_right_page_products_details_image_image').width - 385) / 2) * -1)+'px';
		document.getElementById('area_middle_right_page_products_details_image_image').style.top = (((document.getElementById('area_middle_right_page_products_details_image_image').height - 385) / 2) * -1)+'px';
	}
	
	return false;
}


/*
	Updates the page location from a drop down.
*/
function wshop_switch_location(url)
{
	if (url != 'ignore')
	{
		document.location = url;
	}
		
	return false;

}


/*
	Used to dynamically change images on the site.
*/
function wshop_changeimage(image, url)
{
	image.src = url;
}


/*
	Creates an "are you sure?" dialogue.
*/
function wshop_areyousure_link(message, link)
{
	if (confirm(message))
	{
		document.location = link;
	}
	
	return false;
}


/*
	Updates the page location.
*/
function wshop_location(new_location)
{
	document.location = new_location;
	
	return false;
}


/*
	Shows the terms and conditions in a new window.
*/
function wshop_show_terms(terms_id)
{
	window.open(wshop_url_root+'terms.html?terms_id='+terms_id,'wshop_terms_window','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400,height=550');
	return false;
}


/*
	Used to clear an input.
*/
function wshop_clearinput(input)
{
	input.value = '';

	return false;
}


/*
	Converts a pricestring to pence.
*/
function wshop_format_pence(amount)
{
	// Make sure has content.
	if (amount == '')
		amount = 0;
		
	// Get rid of commas.
	amount = String(amount);
	amount = amount.replace(/,/g, '');
	
	// Convert to pence.
	amount = parseFloat(amount) * 100;
	amount = amount.toFixed(0);

	// Finished.
	return amount;
}


/*
	Converts a pence value to a pricestring.
*/
function wshop_format_pounds_pence(pence)
{
	// Convert to pounds.
	pounds = parseInt(pence) / 100;
	
	// Finished.
	return String(pounds.toFixed(2));
}


/*
	Scrolls thumbnails on the product details page.
*/
var wshop_scroll_position = 0;
function wshop_scroll(scroll_left, max_position)
{
	if (scroll_left)
	{
		if (wshop_scroll_position > 0)
		{
			wshop_scroll_position--;
			Effect.MoveBy('area_middle_right_page_products_details_thumbs', 0, 72, { duration : 0.5 });
		}
	}
	else
	{
		if (wshop_scroll_position < (max_position - 1))
		{
			wshop_scroll_position++;
			Effect.MoveBy('area_middle_right_page_products_details_thumbs', 0, -72, { duration : 0.5 });
		}
	}
	
	return false;
}


/*
	Toggles between panes on the product details page.
*/
function wshop_details_toggle(show_pane)
{
	// Update tab.
	try { document.getElementById('area_middle_right_page_products_details_tabs_description_off').style.display = 'inline'; } catch (e) { }
	try { document.getElementById('area_middle_right_page_products_details_tabs_reviews_off').style.display = 'inline'; } catch (e) { }
	try { document.getElementById('area_middle_right_page_products_details_tabs_more_info_off').style.display = 'inline'; } catch (e) { }
	try { document.getElementById('area_middle_right_page_products_details_tabs_packaging_off').style.display = 'inline'; } catch (e) { }
	try { document.getElementById('area_middle_right_page_products_details_tabs_description_on').style.display = 'none'; } catch (e) { }
	try { document.getElementById('area_middle_right_page_products_details_tabs_reviews_on').style.display = 'none'; } catch (e) { }
	try { document.getElementById('area_middle_right_page_products_details_tabs_more_info_on').style.display = 'none'; } catch (e) { }
	try { document.getElementById('area_middle_right_page_products_details_tabs_packaging_on').style.display = 'none'; } catch (e) { }
	try { document.getElementById('area_middle_right_page_products_details_tabs_'+show_pane+'_off').style.display = 'none'; } catch (e) { }
	try { document.getElementById('area_middle_right_page_products_details_tabs_'+show_pane+'_on').style.display = 'inline'; } catch (e) { }
	
	// Update pane.
	try { document.getElementById('area_middle_right_page_products_details_pane_description').style.display = 'none'; } catch (e) { }
	try { document.getElementById('area_middle_right_page_products_details_pane_reviews').style.display = 'none'; } catch (e) { }
	try { document.getElementById('area_middle_right_page_products_details_pane_more_info').style.display = 'none'; } catch (e) { }
	try { document.getElementById('area_middle_right_page_products_details_pane_packaging').style.display = 'none'; } catch (e) { }
	try { document.getElementById('area_middle_right_page_products_details_pane_'+show_pane).style.display = 'block';  } catch (e) { }
	
	return false;
}


/*
	Sends an HTTP request and returns the resulting XML object.
*/
var request = null;
function wshop_request(url, parameters)
{
	// Send the HTTP request.
	if (window.XMLHttpRequest) 
	{
		request = new XMLHttpRequest();
		request.open("POST", url, false);
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		request.send(parameters);
	}
	else if (window.ActiveXObject) 
	{
		request = new ActiveXObject("Microsoft.XMLHTTP");
		request.open("POST", url, false);
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		request.send(parameters);
	}

	// Process response on a successful return.
	if (request.status == 200)
	{
		var xml_response = '';
		if (window.ActiveXObject) 
		{
			xml_response = new ActiveXObject("Microsoft.XMLDOM");
			xml_response.loadXML(request.responseText);
		}
		else
		{
			xml_response = (new DOMParser()).parseFromString(request.responseText, "text/xml");
		}
		
		//alert ((new XMLSerializer()).serializeToString(xml_response));
		return xml_response;
	}
}


/*
	Called whenever the billing type is changed on the checkout form.
	
	Has one effect: shows/hides the billing address form.
*/
function wshop_checkout_billing_set()
{
	// Update the billing form.
	if (document.getElementById('area_middle_right_checkout_form_billing_id').value == 'new')
	{
		document.getElementById('area_middle_right_checkout_form_billing_form').style.display = 'block';
	}
	else
	{
		document.getElementById('area_middle_right_checkout_form_billing_form').style.display = 'none';
	}
}


/*
	Called whenever the delivery type or country is changed on the checkout form.
	This occurs either by changing the delivery address or directly selecting a country.
	
	Has two effects: shows/hides the delivery address form and updates the basket.
*/
function wshop_checkout_delivery_set()
{
	// First, update the country in the basket.
	var delivery_id = '';
	var delivery_country_id = '';
	if (document.getElementById('area_middle_right_checkout_form_delivery_id').value == 'new')
	{
		delivery_country_id = document.getElementById('area_middle_right_checkout_form_delivery_country_id').value;
	}
	else
	{
		delivery_id = document.getElementById('area_middle_right_checkout_form_delivery_id').value;
	}
	
	// Display the new basket.
	var xml_response = wshop_request(wshop_url_root_ssl+'interface/basket_delivery.do', 'address_id='+delivery_id+'&country_id='+delivery_country_id);
	
	// Get information from the XML response.
	var response_amount_currency = '';
	var response_delivery_country = '';
	var response_html_contents = '';
	try
	{
		var error_xml = xml_response.getElementsByTagName('WshopError');
		if (error_xml.length == 0)
		{
			var xml_response_amount_currency = xml_response.getElementsByTagName('amount_currency');
			var xml_response_delivery_country = xml_response.getElementsByTagName('delivery_country');
			var xml_response_html_contents = xml_response.getElementsByTagName('html_contents');
			response_amount_currency = xml_response_amount_currency[0].firstChild.data;
			response_delivery_country = xml_response_delivery_country[0].firstChild.data;
			response_html_contents = xml_response_html_contents[0].firstChild.data;
		}
	}
	catch (e)
	{
		alert('Sorry, there has been an error with your basket.\n\nPlease try starting the checkout process again.\n\nIf this problem persists, please contact us.');
	}
	
	// Tell the customer if the amount has changed.
	if (response_amount_currency != wshop_basket_amount_currency)
	{
		alert('Please note that the cost of your basket has been recalculated based on delivery to '+response_delivery_country+'.');
	}

	// Update the amount_currency variable.
	wshop_basket_amount_currency = response_amount_currency;
	
	// Update the basket area.
	document.getElementById('area_middle_right_checkout_form_basket').innerHTML = response_html_contents;
	
	// Update the delivery form.
	if (document.getElementById('area_middle_right_checkout_form_delivery_id').value == 'new')
	{
		document.getElementById('area_middle_right_checkout_form_delivery_form').style.display = 'block';
	}
	else
	{
		document.getElementById('area_middle_right_checkout_form_delivery_form').style.display = 'none';
	}
	
	// Make sure payment details are up to date.
	wshop_checkout_payment_updated();
	
	// Finished.
	return false;
}


/*
	Processes a gift voucher submission.
*/
function wshop_checkout_voucher_submit()
{
	// Check the voucher.
	var xml_response = wshop_request(wshop_url_root_ssl+'interface/voucher_balance.do', 'code_1='+document.getElementById('area_middle_right_checkout_form_voucher_code_1').value+'&code_2='+document.getElementById('area_middle_right_checkout_form_voucher_code_2').value);
	
	// Will be used below.
	var warning_message = '';
	
	// Get information from the XML response.
	var response_voucher_balance = 0;
	try
	{
		var error_xml = xml_response.getElementsByTagName('WshopError');
		if (error_xml.length == 0)
		{
			var xml_response_voucher_balance = xml_response.getElementsByTagName('balance_gbp');
			response_voucher_balance = xml_response_voucher_balance[0].firstChild.data;
		}
		else
		{
			response_voucher_balance = 0;
			warning_message = 'Sorry, your voucher code does not appear to be valid\n\nPlease try again.';
		}
	}
	catch (e)
	{
		response_voucher_balance = 0;
		warning_message = 'Sorry, your voucher code does not appear to be valid\n\nPlease try again.';
	}
	
	if (warning_message != '')
	{
		// There was an error.
		alert(warning_message);
	}
	else if (response_voucher_balance == 0)
	{
		// Make sure that the voucher has not been used.
		alert('Sorry, your voucher has been used.\n\nPlease try another voucher code or use an alternate payment method.');
	}

	// Determine the most that can be spent.
	var max_gbp = Math.min(response_voucher_balance, Math.ceil(wshop_basket_amount_currency / wshop_basket_gbp_currency));
	
	// Update the voucher form.
	if (response_voucher_balance == 0)
	{
		document.getElementById('area_middle_right_checkout_form_voucher_amount').value = 0;
		document.getElementById('area_middle_right_checkout_form_voucher_remaining').value = 0;
		document.getElementById('area_middle_right_checkout_form_voucher_form').style.display = 'none';
	}
	else
	{
		document.getElementById('area_middle_right_checkout_form_voucher_amount').value = wshop_format_pounds_pence(response_voucher_balance);
		document.getElementById('area_middle_right_checkout_form_voucher_remaining').value = response_voucher_balance;
		document.getElementById('area_middle_right_checkout_form_voucher_maxgbp').innerHTML = wshop_format_pounds_pence(max_gbp);
		document.getElementById('area_middle_right_checkout_form_voucher_form').style.display = 'block';
	}
	
	// Make sure payment details are up to date.
	wshop_checkout_payment_updated();
	
	// Finished.
	return false;
}


/*
	Called whenever important payment details are updated.
*/
function wshop_checkout_payment_updated()
{
	// Check that the amount of VIP points is legal and get the currency value.
	var vips_amount = parseFloat(String(document.getElementById('area_middle_right_checkout_form_vips_amount').value).replace(/,/g, '')).toFixed(0);
	var vips_currency = Math.ceil(Math.floor(vips_amount * wshop_redeemable_pence_of_a_point) * wshop_basket_gbp_currency);
	if (vips_currency < 0)
	{
		vips_amount = 0;
		vips_currency = 0;
	}
	if (vips_currency > wshop_basket_amount_currency)
	{
		vips_amount = Math.floor(Math.floor(wshop_basket_amount_currency / wshop_basket_gbp_currency) / wshop_redeemable_pence_of_a_point);
		vips_currency = wshop_basket_amount_currency;
	}
	if (vips_amount > wshop_customer_vip_balance)
	{
		vips_amount = wshop_customer_vip_balance;
		vips_currency = Math.ceil(Math.floor(vips_amount * wshop_redeemable_pence_of_a_point) * wshop_basket_gbp_currency);
	}
	
	// Check that the GBP amount of vouchers is legal and get the currency value.
	// Also make sure that the currency amount of VIP points plus the currency amount of vouchers does not exceed the basket price.
	var voucher_amount = wshop_format_pence(document.getElementById('area_middle_right_checkout_form_voucher_amount').value);
	var voucher_currency = Math.ceil(voucher_amount * wshop_basket_gbp_currency);
	if (voucher_currency < 0)
	{
		voucher_amount = 0;
		voucher_currency = 0;
	}
	if (voucher_currency+vips_currency > wshop_basket_amount_currency)
	{
		voucher_currency = wshop_basket_amount_currency - vips_currency;
		voucher_amount = Math.floor(voucher_currency / wshop_basket_gbp_currency);
	}
	if (voucher_amount > document.getElementById('area_middle_right_checkout_form_voucher_remaining').value)
	{
		voucher_amount = document.getElementById('area_middle_right_checkout_form_voucher_remaining').value;
		voucher_currency = Math.ceil(voucher_amount * wshop_basket_gbp_currency);
	}
	
	// Determine the amount that needs to be spent on card.
	var card_amount = wshop_basket_amount_currency - (vips_currency + voucher_currency);
	
	// Update the form amounts.
	document.getElementById('area_middle_right_checkout_form_vips_amount').value = vips_amount;
	document.getElementById('area_middle_right_checkout_form_voucher_amount').value = wshop_format_pounds_pence(voucher_amount);
	document.getElementById('area_middle_right_checkout_form_card_amount').value = wshop_format_pounds_pence(card_amount);
	
	// Update the form summaries.
	if (vips_amount > 0)
	{
		try { document.getElementById('area_middle_right_checkout_form_vips_summary').innerHTML = 'Value: '+wshop_basket_currency_unicode+wshop_format_pounds_pence(vips_currency); } catch (e) {}
	}
	else
	{
		try { document.getElementById('area_middle_right_checkout_form_vips_summary').innerHTML = ''; } catch (e) {}
	}
	if (voucher_amount != voucher_currency)
	{
		document.getElementById('area_middle_right_checkout_form_voucher_summary').innerHTML = 'This is equivalent to '+wshop_basket_currency_unicode+wshop_format_pounds_pence(voucher_currency);
	}
	document.getElementById('area_middle_right_checkout_form_card_summary').innerHTML = wshop_basket_currency_unicode+wshop_format_pounds_pence(card_amount);
	
	// If a card payment needs to be made, enable the form.
	if (card_amount > 0)
	{
		document.getElementById('area_middle_right_checkout_form_card_form').style.display = 'block';
	}
	else
	{
		document.getElementById('area_middle_right_checkout_form_card_form').style.display = 'none';
	}
	
	// Finished.
	return true;
}


/*
	Called when PayPal is selected/unselected.
*/
var wshop_checkout_payment_use_paypal = false;
function wshop_checkout_payment_paypal(use_paypal)
{
	wshop_checkout_payment_use_paypal = use_paypal;
	
	if (use_paypal)
	{
		document.getElementById('area_middle_right_checkout_form_card_form_nopaypal').style.display = 'none';
		document.getElementById('area_middle_right_checkout_form_card_form_cards').style.display = 'none';
	}
	else
	{
		document.getElementById('area_middle_right_checkout_form_card_form_nopaypal').style.display = 'block';
		document.getElementById('area_middle_right_checkout_form_card_form_cards').style.display = 'block';
	}
	
	return true;
}


/*
	Called when a form is submitted for client side checking.
*/
function wshop_form_submit(form_name, form_ref)
{
	var warning_message = '';
	
	if (form_name == 'checkout')
	{
		if (!form_ref.accept_terms.checked)
			warning_message = 'You must accept the terms and conditions before checking out.';
		else if (form_ref.payment_voucher_amount.value > 0 && (form_ref.payment_voucher_code_1.value == '' || form_ref.payment_voucher_code_2.value == ''))
			warning_message = 'If you are using a gift voucher, please ensure that the code is filled in';
		else if (form_ref.payment_card_amount.value > 0 && !wshop_checkout_payment_use_paypal && form_ref.payment_card_number.value == '')
			warning_message = 'Please enter your card number.';
		else if (form_ref.payment_card_amount.value > 0 && !wshop_checkout_payment_use_paypal && form_ref.payment_card_name.value == '')
			warning_message = 'Please enter the cardholder name.';
		else if (form_ref.payment_card_amount.value > 0 && !wshop_checkout_payment_use_paypal && form_ref.payment_card_cvv.value == '')
		{
			warning_message = 'Please enter the security code for your card.  This is the last three digits on the reverse of your card.';
			//warning_message = 'Please enter the security code for your card.  For American Express, this is the four digit code on the front of your card.  For all other card types, please enter the last three digits on the reverse of your card.';
		}
		else if (form_ref.delivery_id.value == 'new' && form_ref.delivery_address_1.value == '')
			warning_message = 'Please enter the first line of your delivery address.';
		else if (form_ref.delivery_id.value == 'new' && form_ref.delivery_town.value == '')
			warning_message = 'Please enter the town of your delivery address.';
		else if (form_ref.delivery_id.value == 'new' && form_ref.delivery_county.value == '')
			warning_message = 'Please enter the county of your delivery address.';
		else if (form_ref.delivery_id.value == 'new' && form_ref.delivery_postcode.value == '')
			warning_message = 'Please enter the postcode of your delivery address.';
		else if (form_ref.delivery_id.value == 'new' && form_ref.delivery_phone_day.value == '')
			warning_message = 'Please enter the phone number associated with your delivery address.';
		else if (form_ref.billing_id.value == 'new' && form_ref.billing_address_1.value == '')
			warning_message = 'Please enter the first line of your billing address.';
		else if (form_ref.billing_id.value == 'new' && form_ref.billing_town.value == '')
			warning_message = 'Please enter the town of your billing address.';
		else if (form_ref.billing_id.value == 'new' && form_ref.billing_county.value == '')
			warning_message = 'Please enter the county of your billing address.';
		else if (form_ref.billing_id.value == 'new' && form_ref.billing_postcode.value == '')
			warning_message = 'Please enter the postcode of your billing address.';
		else if (form_ref.billing_id.value == 'new' && form_ref.billing_phone_day.value == '')
			warning_message = 'Please enter the phone number associated with your billing address.';
	}
	if (form_name == 'details')
	{
		if (form_ref.email.value == '')
			warning_message = 'Please enter your e-mail address.';
		else if (form_ref.pass_1.value != form_ref.pass_2.value)
			warning_message = 'Sorry, your passwords do not match.';
		else if (form_ref.firstname.value == '')
			warning_message = 'Please enter your firstname.';
		else if (form_ref.surname.value == '')
			warning_message = 'Please enter your surname.';
	}
	if (form_name == 'login')
	{
		if (form_ref.email.value == '')
			warning_message = 'Please enter your e-mail address.';
		else if (form_ref.password.value == '')
			warning_message = 'Please enter your password.';
	}
	if (form_name == 'reminder')
	{
		if (form_ref.email.value == '')
			warning_message = 'Please enter your e-mail address.';
	}
	if (form_name == 'review')
	{
		if (form_ref.title.value == '')
			warning_message = 'Please enter a title for your review.';
		else if (form_ref.content.value == '')
			warning_message = 'Please fill in the review box.';
	}
	if (form_name == 'signup')
	{
		if (!form_ref.do_accept.checked)
			warning_message = 'You must accept the terms and conditions in order to sign up.';
		else if (form_ref.email.value == '')
			warning_message = 'Please enter your e-mail address.';
		else if (form_ref.pass_1.value == '')
			warning_message = 'Please enter a password.';
		else if (form_ref.pass_2.value == '')
			warning_message = 'Please confirm your password .';
		else if (form_ref.pass_1.value != form_ref.pass_2.value)
			warning_message = 'Sorry, your passwords do not match.';
		else if (form_ref.firstname.value == '')
			warning_message = 'Please enter your firstname.';
		else if (form_ref.surname.value == '')
			warning_message = 'Please enter your surname.';
		else if (form_ref.address_1.value == '')
			warning_message = 'Please enter the first line of your address.';
		else if (form_ref.town.value == '')
			warning_message = 'Please enter your town.';
		else if (form_ref.county.value == '')
			warning_message = 'Please enter your county.';
		else if (form_ref.postcode.value == '')
			warning_message = 'Please enter your postcode.';
		else if (form_ref.phone_day.value == '')
			warning_message = 'Please enter your phone number.';
	}
	
	
	if (warning_message == '')
	{
		return true;
	}
	else
	{
		alert(warning_message);
		return false;
	}
}
