function productCheckOptions()
{
	var stock_message = '';
	var price = product_price;
	
	// process variants
	for(x = 0; x < variants.length; x++) 
	{
		if(variants[x][1].length == 0)
		{
			continue;
		}
		flag = true;
		
		for(c in variants[x][1])
		{
			if(document.getElementById('v_option_'+c)) 
			{
				if(document.getElementById('v_option_'+c).value != variants[x][1][c]) 
				{
					flag = false;
					break;
				}
			}
		}
		// If variant found ...
		if(flag) 
		{
			price = variants[x][0][1];
			if(variants[x][0][2] == 0)
			{
				// no stock messaging for now
				//stock_message = "<strong>Please Note:</strong> This item will take approximately 28 days to deliver";
			}
			break;
		}
	}
	
	// process modifiers
	elements = document.getElementsByTagName('select');
	
 	for(var i=0;i<elements.length;i++)
	{
		var name = elements[i].name;
		if(/m_option_/.test(name))
		{
			select_box = document.getElementById(name);

			selected_value = select_box.options[select_box.selectedIndex].value;
			if(selected_value != "")
			{
				selected_value = selected_value.replace(/^[0-9]+_/, '');
				price = format_currency(parseFloat(selected_value) + parseFloat(price));
			}
		}
	}
	
	document.getElementById('product_price').innerHTML = price;
	
	document.getElementById('product_stock_message').innerHTML = stock_message;
}


function productAddRequiredOption(field, text)
{
		requiredOptions.push(new Array(field, text));
}

function productAddLinkedOption(option1, option2)
{
		linkedOptions.push(new Array(option1, option2));
}

function productCheckForm()
{
	var errors = "";
	var linkedErrors = "";
	for(i=0;i<requiredOptions.length;i++)
	{
		var value = "";
		element = document.getElementById(requiredOptions[i][0]);
		
		switch(element.type)
		{
			case "select-one":
				value = element.options[element.selectedIndex].value;
				break;
			case "text":
				value = element.value;
				break;
		}
		
		if(value == "")
		{
			errors += requiredOptions[i][1];
		}
	}
	
	var optionsWarned = Array();
	for(i=0;i<linkedOptions.length;i++)
	{
		var option1 = linkedOptions[i][0];
		var option2 = linkedOptions[i][1];
		
		var optionFound = 0;
		for(x=0;x<optionsWarned.length;x++)
		{
			if(option1[0] == optionsWarned[x] || option2[0] == optionsWarned[x])
			{
				optionFound++;
			}
		}
		
		if(optionFound == 0)
		{
			var option1_value = "";
			var option2_value = "";
	
			var ele_opt1 = document.getElementById(option1[0]);
			var ele_opt2 = document.getElementById(option2[0]);
			
			switch(ele_opt1.type)
			{
				case "select-one":
					option1_value = ele_opt1.options[ele_opt1.selectedIndex].value;
					option1_required_action = "select";
					break;
				case "text":
					option1_value = ele_opt1.value;
					option1_required_action = "enter a value for ";
					break;
			}
			
			switch(ele_opt2.type)
			{
				case "select-one":
					option2_value = ele_opt2.options[ele_opt2.selectedIndex].value;
					option2_required_action = "select";
					break;
				case "text":
					option2_value = ele_opt2.value;
					option2_required_action = "enter a value for ";
					break;
			}
			
			if(option1_value != "" && option2_value == "")
			{
				linkedErrors += "If you "+option1_required_action+" '"+option1[1]+"' you must "+option2_required_action+" '"+option2[1]+"'\n";
				optionsWarned.push(option1[0]);
				optionsWarned.push(option2[0]);
			}
			
			if(option2_value != "" && option1_value == "")
			{
				linkedErrors += "If you "+option2_required_action+" '"+option2[1]+"' you must "+option1_required_action+" '"+option1[1]+"'\n";
				optionsWarned.push(option1[0]);
				optionsWarned.push(option2[0]);
			}		
		}
	}
	
	if(errors || linkedErrors)
	{
		var errorMessage = "You must select the following fields:\n "+errors
		if(linkedErrors)
		{
			errorMessage += "\n"+linkedErrors;
		}
		alert(errorMessage);
		return false;
	}
	else
	{
			return true;
	}
}

function productCheckFormMulti(thisForm)
{	
	var errors = "";
	var linkedErrors = "";

	for(i=0;i<requiredOptions.length;i++)
	{
		var value = "";

		element = document.forms[thisForm][requiredOptions[i][0]];
			
		if(element != null)
		{
			switch(element.type)
			{
				case "select-one":
					value = element.options[element.selectedIndex].value;
					break;
				case "text":
					value = element.value;
					break;
			}
			
			if(value == "")
			{
				errors += requiredOptions[i][1];
			}
		}
	}
	
	if(errors)
	{
		var errorMessage = "You must select the following fields:\n "+errors

		alert(errorMessage);
		return false;
	}
	else
	{
			return true;
	}
}