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(formName,i)
{
	if (arguments[0]==theUndefined)	formName = document.forms[0].name;

	eval('document.'+formName+'.QTY' + i).value = "0";
	eval('document.'+formName).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(formName)
{
	if (arguments[0]==theUndefined)	formName = document.forms[0].name;

	var	productCount	= eval('document.' + formName + '.productcount');

	var	opt1Label		= eval('document.' + formName + '.opt1Label');
	var	opt2Label		= eval('document.' + formName + '.opt2Label');
	var	opt3Label		= eval('document.' + formName + '.opt3Label');
	var	opt4Label		= eval('document.' + formName + '.opt4Label');
	var	opt5Label		= eval('document.' + formName + '.opt5Label');
	var	opt6Label		= eval('document.' + formName + '.opt6Label');

	var CountUp			= 0;
	
	var qty 			= 0;

	for (var n = 0; n < productCount.value; n++)
	{
		var hasInput = false;
		var qty		= eval('document.' + formName + '.QTY' + n);

		var	opt1	= eval('document.' + formName + '.OPT1' + n);
		var	opt2	= eval('document.' + formName + '.OPT2' + n);
		var	opt3	= eval('document.' + formName + '.OPT3' + n);
		var	opt4	= eval('document.' + formName + '.OPT4' + n);
		var	opt5	= eval('document.' + formName + '.OPT5' + n);
		var	opt6	= eval('document.' + formName + '.OPT6' + n);

		var	prod	= eval('document.' + formName + '.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('document.' + formName + '.QTY' + n);
			if (qtyTagType.tagName == "SELECT")  	qty = eval('document.' + formName + '.QTY' + n +'.options[document.' + formName + '.QTY' + n +'.selectedIndex]');
			/*
			alert(qtyTagType.tagName);
			
alert(qty.value);
*/
		}

		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');
//alert(productCount.value);
	for (var n = 0; n < productCount.value; n++)
	{
		var id		= eval('document.' + formName + '.PROD' + n);
		var qty		= eval('document.' + formName + '.QTY' + n);

  //		alert(id.value);
  //		alert(qty.value);
		if (qty.value == 0)
		{
			alert("Please remove "+id.value+" before proceeding to the checkout");
			goToCheckout = false;
			break;
		}
	}
  //		alert(goToCheckout);
	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);
}