
function selectFabric() {

	var img_href = $("lightboxImage").src;
	if(!img_href) return false;

	// Work out class name:
	var code = img_href.substring(img_href.indexOf("#")+1);
	var div_class = ".fabric_color_div_"+code;

	$$(div_class+' a[rel]').each(function(a) {

		if(a.href == img_href) {

			// Update select value on form:
			var img = a.select("img")[0];
			$(code).value = img.id;

			// Change all fabric thumbnails to "not selected":
			$$(div_class+' a[rel] img').each(function(e) {
				var not_selected_class = "not-selected";
				if(e.className != not_selected_class) e.className = not_selected_class;
			});

			// Change thumbnail image to have the "selected" class so it stands out from the others:
			img.className = "selected";

			// Animate thumbnail emphasise selection has been made:
			Effect.Pulsate(img, { pulses: 1, duration: 0.5 });

			throw $break;
		}
	});
}


function checkForm() {

	// Check fabric(s) selection has been made:
	var divs = $$('div.swatch');
	
	for(var d=0; d<divs.length; d++) {

		var field_name = divs[d].id.toLowerCase();

		var inputs = divs[d].getElementsByTagName("input");
		for(var i=0; i<inputs.length; i++) {
			if(inputs[i].type == "hidden") {
				if(inputs[i].value == "") {
					alert("Please select a "+field_name);
					return false;
				}
			}
		}
	};
	return true;
}