function productDetailsUpdateOptions(optionBox) {
	//cycel through options
	//alert('working');
	//alert(optionBox.options[optionBox.selectedIndex].value);

	for(i = 0; i < optionBox.options.length; i++) {
		//alert(optionBox.options[i].value);
		
		if(optionLinks[optionBox.options[i].value]) {
			document.getElementById('productSubOption'+optionBox.options[i].value).style.display = 'none';
		}
	}
	//alert(optionBox.options[optionBox.selectedIndex].value);
	if(optionLinks[optionBox.options[optionBox.selectedIndex].value]) {
		document.getElementById('productSubOption'+optionBox.options[optionBox.selectedIndex].value).style.display = 'block';
	}
}

function productDetailsAddToCartVal(form) {
	var valid = true;
	var requiredFields = '';
	//Validate the product before we add to cart.
	if(typeof allProductOptions == "undefined") {
		return true;	
	}
	if(allProductOptions.length) {
		//Product has options, lets validate them.
		for(var i = 0; i < allProductOptions.length; i++) {
			if(document.getElementById('option' + allProductOptions[i]).type === 'text') {
				//Now that we know this is an input lets check if required.
				if(optionInputNames[allProductOptions[i]] && document.getElementById('option' + allProductOptions[i]).value == "") {
					//Required Field
					valid = false;
					requiredFields += optionInputNames[allProductOptions[i]] + "\n";
				}
			} else {
				if(document.getElementById('option' + allProductOptions[i]).options[document.getElementById('option' + allProductOptions[i]).selectedIndex].value ==="0") {
					valid = false;
					requiredFields += optionNames[allProductOptions[i]] + "\n";
				}
				if(optionLinks[document.getElementById('option' + allProductOptions[i]).options[document.getElementById('option' + allProductOptions[i]).selectedIndex].value]) {
					if(optionLinks[document.getElementById('option' + allProductOptions[i]).options[document.getElementById('option' + allProductOptions[i]).selectedIndex].value].length) {
						results = productDetailsAddToCartValCheckSubOptions(document.getElementById('option' + allProductOptions[i]).options[document.getElementById('option' + allProductOptions[i]).selectedIndex].value);
						// 0 true or false for valid.
						// 1 contains Name fields of required options
						if(!results[0]) {
							valid = false;
							requiredFields += results[1];
						}
					}
				}
			}
			//check if it has subs
			
			
			
		}
	}
	if(valid == false) {
		alert("Options below are required: \n"+requiredFields);
	}
	if(!IsNumeric(form.qnty.value)) {
		form.qnty.value = 1;
		alert("Qnty can only contain numbers.");
		valid = false;
	}
	if(!form.agree.checked) {
		alert('Please review and agree to our Terms of Service.');
		valid = false;
	}
	return valid;
}
function productDetailsAddToCartValCheckSubOptions(valueID) {
	var valid = 1;
	var requiredFields = '';
	//We have suboptions, let check them.
	for(var i = 0; i < optionLinks[valueID].length; i++) {
		if(document.getElementById('option' + optionLinks[valueID][i]).type === 'text') {
			//Now that we know this is an input lets check if required.
			if(optionInputNames[optionLinks[valueID][i]] && document.getElementById('option' + optionLinks[valueID][i]).value == "") {
				//Required Field
				valid = false;
				requiredFields += optionInputNames[optionLinks[valueID][i]] + "\n";
			}
		} else {
			if(document.getElementById('option' + optionLinks[valueID][i]).options[document.getElementById('option' + optionLinks[valueID][i]).selectedIndex].value ==="0") {
				valid = 0;
				requiredFields += optionNames[optionLinks[valueID][i]] + "\n";
			}
			//check if it has subs
			if(optionLinks[document.getElementById('option' + optionLinks[valueID][i]).options[document.getElementById('option' + optionLinks[valueID][i]).selectedIndex].value]) {
				if(optionLinks[document.getElementById('option' + optionLinks[valueID][i]).options[document.getElementById('option' + optionLinks[valueID][i]).selectedIndex].value].length) {
					results = productDetailsAddToCartValCheckSubOptions(document.getElementById('option' + optionLinks[valueID][i]).options[document.getElementById('option' + optionLinks[valueID][i]).selectedIndex].value);
					// 0 true or false for valid.
					// 1 contains Name fields of required options
					if(!results[0]) {
						valid = 0;
						requiredFields += results[1];
					}
					results = '';
				}
			}
		}
	}
	ourResults = new Array(valid, requiredFields);
	return ourResults;
}
function valCartShippingQuote(form) {
	if(!form.zipcode.value) {
		form.zipcode.focus();
		alert("Your Zipcode is required for a shipping quote");
		return false;
	}
	return true;
}
function IsNumeric(sText)  {
	var ValidChars = "0123456789.";
	var Char;
	for (i = 0; i < sText.length; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			return false;
		}
	}
	return true;
}