function validateShip() {
	var a = new Array();
	a[0] = document.forms.checkout.ship_name.value;
	a[1] = document.forms.checkout.ship_address1.value;
	a[2] = document.forms.checkout.ship_city.value;
	a[3] = document.forms.checkout.ship_county.value;
	a[4] = document.forms.checkout.ship_country.value;
	a[5] = document.forms.checkout.ship_postcode.value;
	a[6] = document.forms.checkout.ship_telephone.value;
	
	var msg = new Array();
	msg[0] = "Check Name\n";
	msg[1] = "Check Address 1\n";
	msg[2] = "Check City\n";
	msg[3] = "Check County\n";
	msg[4] = "Check Country\n";
	msg[5] = "Check Post Code\n";
	msg[6] = "Check Telephone\n";	

	txt = "";
	for (i=0;i<a.length;i++){
		if (a[i] == "") {
			txt += msg[i];
		}
	}
	
	var email = document.forms.checkout.ship_email.value
	if((email == "")||(email == null)||(email.indexOf("@") == -1)||(email.indexOf(".") == -1)||(email.indexOf(" ") != -1)){
		txt += "Check Email\n";
	}	

	if (txt != "") {
		alert(txt);
		return false;		
	} else {	
		return true;
	}
}

function validateBill() {
	var a = new Array();
	a[0] = document.forms.checkout.bill_name.value;
	a[1] = document.forms.checkout.bill_address1.value;
	a[2] = document.forms.checkout.bill_city.value;
	a[3] = document.forms.checkout.bill_county.value;
	a[4] = document.forms.checkout.bill_country.value;
	a[5] = document.forms.checkout.bill_postcode.value;
	a[6] = document.forms.checkout.bill_telephone.value;

	var msg = new Array();
	msg[0] = "Check Name\n";
	msg[1] = "Check Address 1\n";
	msg[2] = "Check City\n";
	msg[3] = "Check County\n";
	msg[4] = "Check Country\n";
	msg[5] = "Check Post Code\n";
	msg[6] = "Check Telephone\n";
	
	txt = "";
	for (i=0;i<a.length;i++){
		if (a[i] == "") {
			txt += msg[i];
		}
	}

	var email = document.forms.checkout.bill_email.value
	if((email == "")||(email == null)||(email.indexOf("@") == -1)||(email.indexOf(".") == -1)||(email.indexOf(" ") != -1)){
		txt += "Check Email\n";
	}
	
	if (txt != "") {
		alert(txt);
		return false;		
	} else {	
		return true;
	}
}

function goToNextStepValidateShip() {
	if (validateShip()) {
		document.forms.checkout.submit();
	}
}

function goToNextStepValidateBill() {
	if (validateBill()) {
		document.forms.checkout.submit();
	}
}

function goToPayment(page) {
	popup("about:blank", "PaymentWindow",800,600);
	document.forms.payment.submit();
}

function goToNextStep() {
	document.forms.checkout.submit();
}

function goToCheckout(num,items) {
	if (num > 0) {
		//location.href = "checkout_1.php";
		document.forms.goto_checkout.items.value = items;
		document.forms.goto_checkout.refresh.value = 1;
		
		var itemsString = items;
		var listItems = itemsString.split(",");
		document.forms.goto_checkout.quantities.value = "";
		for (i=0; i<listItems.length; i++ ) {
			var item = listItems[i];
			eval("num = document.forms.items_basket.quantity_" + item + ".value");
			if (document.forms.goto_checkout.quantities.value == "") {
				document.forms.goto_checkout.quantities.value = num;
			} else {
				document.forms.goto_checkout.quantities.value = document.forms.goto_checkout.quantities.value + "," + num;
			}
		}
		document.forms.goto_checkout.submit();		
	} else {
		alert("Your Shopping Basket is empty.");	
	}
}

function removeItem(item) {
	document.forms.items_basket.remove.value = item;
	document.forms.items_basket.include.value = "";
	document.forms.items_basket.submit();
}

function includeItem(item) {
	document.forms.items_basket.remove.value = "";
	document.forms.items_basket.include.value = item;
	document.forms.items_basket.refresh.value = 0;
	document.forms.items_basket.quantities.value = "";
	document.forms.items_basket.submit();
}

function refreshItems(items) {
	document.forms.items_basket.remove.value = "";
	document.forms.items_basket.include.value = items;
	document.forms.items_basket.refresh.value = 1;
	
	var itemsString = items;
	var listItems = itemsString.split(",");
	document.forms.items_basket.quantities.value = "";
	for (i=0; i<listItems.length; i++ ) {
		var item = listItems[i];
		
		eval("num = document.forms.items_basket.quantity_" + item + ".value");
		if (document.forms.items_basket.quantities.value == "") {
			document.forms.items_basket.quantities.value = num;
		} else {
			document.forms.items_basket.quantities.value = document.forms.items_basket.quantities.value + "," + num;
		}
	}
	document.forms.items_basket.submit();
}

function confirmAdd(formNumber) {
	eval("desc = document.forms.shopForm"+formNumber+".title.value");
	eval("price = document.forms.shopForm"+formNumber+".price.value");
	eval("quantity = document.forms.shopForm"+formNumber+".quantity.value");
	
	msg = "You have chosen:\n\n";
	msg += desc + "\n\n";
	msg += "Price: " + price + "\n";
	msg += "Quantity: " + quantity + "\n\n";
	msg += "Click ok to add this to your basket and continue shopping.";	
	if (confirm(msg)) {
		eval("document.forms.shopForm"+formNumber+".submit()");
	}
}

function popup(url,winName,w,h)
{

	/*
  	var sWid = screen.width;
  	var sHi = screen.height;
	
	var tp = (sHi/2)-(hi/2)
	var lft = (sWid/2)-(wid/2)
	*/
	var wid = w+10;
	var hi = h+10;
	var tp = 10;
	var lft = 10;
	
	if (scroll && document.all && (navigator.userAgent.indexOf("Mac") > -1))
	{
		 wid = wid+17;
		 newwin=window.open(url,winName,"WIDTH=" + wid + ",HEIGHT=" + hi + ",scrollBars=yes,resizable=yes");
	}
	else
	{
		newwin=window.open(url,winName,"WIDTH=" + wid + ",HEIGHT=" + hi + ",scrollBars=yes,resizable=yes, top = "+ tp +", left ="+ lft + ", screenX=" + lft +", screenY= "+tp);
		newwin.focus();
	}
	
}

function back()
{
	history.back();
}

function printPage() {
	window.print();	
}