var theUndefined;

function testOpt(theOpt,theName) {
	if (theOpt.selectedIndex == 0 && theOpt.options[theOpt.selectedIndex].text.indexOf('Choose')!=-1) {
		alert('Please choose a '+theName);
		return false;
	}
}

function removeItemFromBasket(f,i)
{
	with (f)
	{
		var qty = eval('f.QTY' + i);

	}
	qty.value = "0";
	f.submit();
}
function removeItemFromQuote(f,i)
{
	with (f)
	{
		var qty = eval('f.QQTY' + i);

	}
	qty.value = "0";
	f.submit();
}
function emptyBasket(formName)
{
	if (arguments[0]==theUndefined)	formName = document.forms[0].name;

	var	productCount	= eval('document.' + formName + '.productcount');
	for (var i = 0; i < productCount.value; i++) {
		var inputName = "QTY"+i;
		var inputValue = eval('document.' + formName + '.' + inputName);
		inputValue.value = "0";
	}

	eval('document.'+formName).submit();
}

function CheckForm(f)
{
	with (f)
	{
		var CountUp			= 0;
		var qty 			= 0;

		for (var n = 0; n < productcount.value; n++)
		{
			var hasInput	= false;
			var qty 		= eval('f.QTY' + n);
			var	opt1 		= eval('f.OPT1' + n);
			var	opt2 		= eval('f.OPT2' + n);
			var	opt3 		= eval('f.OPT3' + n);
			var	opt4 		= eval('f.OPT4' + n);
			var	opt5 		= eval('f.OPT5' + n);
			var	opt6 		= eval('f.OPT6' + n);

			var	prod 		= eval('f.PROD' + n);
			var qtyTagType  = document.getElementById("QTY" + n);
			
			if (opt1) {if (testOpt(opt1, opt1Label.value) == false) return false;}
			if (opt2) {if (testOpt(opt2, opt2Label.value) == false) return false;}
			if (opt3) {if (testOpt(opt3, opt3Label.value) == false) return false;}
			if (opt4) {if (testOpt(opt4, opt4Label.value) == false) return false;}
			if (opt5) {if (testOpt(opt5, opt5Label.value) == false) return false;}
			if (opt6) {if (testOpt(opt6, opt6Label.value) == false) return false;}

			if (qtyTagType)
			{
				if (qtyTagType.tagName == "INPUT")  	qty = eval('f.QTY' + n);
				if (qtyTagType.tagName == "SELECT")  	qty = eval('f.QTY' + n +'.options[f.QTY' + n +'.selectedIndex]');
			}

			if (qty.value.length > 0)
			{
				if (isNaN(qty.value/2))
				{
					window.alert('One or more of the fields contains invalid characters');
					return false;
				}
			}
			else
			{
				alert('Please choose a quantity for product ID:'+prod.value);
				return false;
			}

			CountUp += (qty.value - 0);
	
			if (qty.value < 0)
			{
				alert('Surprisingly you cannot purchase a negative number of items');
				return false;
			}
		}
		if (CountUp == 0)
		{
			window.alert('You must select more than 0 items');
			return false;
		}
	}
}
function checkCart(formName)
{
	var goToCheckout	= true;
	
	var	productCount	= eval('document.' + formName + '.productcount');

	for (var n = 0; n < productCount.value; n++)
	{
		var id		= eval('document.' + formName + '.PROD' + n);
		var qty		= eval('document.' + formName + '.QTY' + n);
		
		if (qty.value == 0)
		{
			alert("Please remove "+id.value+" before proceeding to the checkout");
			goToCheckout = false;
			break;
		}
	}
	return goToCheckout;
}
function CurrencyConvert(theURL) {
	var features="scrollbars=yes,resizable=yes,width=540,height=132,left=100,top=100,screenX=100,screenY=100";
	window.open(theURL,"",features);
}