var pagename;

function validate(theForm) {
	var checkedFound = false;
	if (theForm.itemCount.value > 0) {
		if (theForm.itemCount.value > 1) {
			for (i = 0; i < theForm.items.length; i++) {
				if (theForm.items[i].checked == true) {
					checkedFound = true;
					itemID = "qty_" + theForm.items[i].value;
					if ((parseInt(theForm[itemID].value) < 1) || (isNaN(theForm[itemID].value)) || (theForm[itemID].value == "")) {
						alert("You must order at least 1 set.");
						theForm[itemID].focus();
						theForm[itemID].select();
						return false;
						break;
					}
					if (pagename == "shafts.asp") {
						lengthID = "length_" + theForm.items[i].value;
						colourID = "colour_" + theForm.items[i].value;
						if (theForm[lengthID].options[theForm[lengthID].selectedIndex].value == "") {
							alert("Please select a length.");
							theForm[lengthID].focus();
							//theForm[lengthID].select();
							return false;
							break;
						}
						if (theForm[colourID].options[theForm[colourID].selectedIndex].value == "") {
							alert("Please select a colour.");
							theForm[colourID].focus();
							//theForm[colourID].select();
							return false;
							break;
						}
					}
				}
			}
			if (checkedFound == false) {
				alert("Please click on the checkbox of the item you would like to add.");
				return false;
			}
		} else {
			if (theForm.items.checked == false) {
				alert("Please click on the checkbox of the item you would like to add.");
				return false;
			} else {
				itemID = "qty_" + theForm.items.value;
				if ((parseInt(theForm[itemID].value) < 1) || (isNaN(theForm[itemID].value)) || (theForm[itemID].value == "")) {
					alert("You must order at least 1 set.");
					theForm[itemID].focus();
					theForm[itemID].select();
					return false;
				}
				if (pagename == "shafts.asp") {
					lengthID = "length_" + theForm.items.value;
					colourID = "colour_" + theForm.items.value;
					if (theForm[lengthID].options[theForm[lengthID].selectedIndex].value == "") {
						alert("Please select a length.");
						theForm[lengthID].focus();
						//theForm[lengthID].select();
						return false;
					}
					if (theForm[colourID].options[theForm[colourID].selectedIndex].value == "") {
						alert("Please select a colour.");
						theForm[colourID].focus();
						//theForm[colourID].select();
						return false;
					}
				}
			}
		}
	} else {
		alert("Item temporarily out of stock");
		return false;
	}
	return true;
}

function changeColor(theCheckbox,cell,qty) {
	if ((document.darts[qty].value == "") || (isNaN(document.darts[qty].value))) {
		document.darts[qty].value = 1;
	}

	if (!theCheckbox.checked) {
		document.all[cell].style.backgroundColor = "#ffffff";
	} else {
		document.all[cell].style.backgroundColor = "#ffff00";
	}
}