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();
	location.href='?s=6&p=2&step=checkout5';
}

function goToPaymentCredit(page) {
	if (confirm("Please note that there is an additional fee of £4.00 added to all credit card payments (debit card payments are free), do you wish to continue?")) {
		popup("about:blank", "PaymentWindow",800,600);
		document.forms.paymentcredit.submit();
		location.href='?s=6&p=2&step=checkout5';
	}
}

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 cart 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 shopping cart";	
	if (confirm(msg)) {
		eval("document.forms.shopForm"+formNumber+".submit()");
	}
}

function validatecontact()
{

	var a = new Array();
	a[0] = document.forms.userform.newfname.value;
	a[1] = document.forms.userform.newlname.value;
	a[2] = document.forms.userform.newsubject.value;
	a[3] = document.forms.userform.newmessage.value;
	
	var msg = new Array();
	msg[0] = "First Name\n";
	msg[1] = "Last Name\n";
	msg[2] = "Subject\n";
	msg[3] = "Message\n";

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

	if (txt != "")
	{
		txt = "The following fields are required :\n\n" + txt;
		alert(txt);
		event.returnValue=false;		
	}
	else
	{	
	//	alert("hello");
		sendprofile();
		return true;
	}
}

function validatemaillist()
{

	var a = new Array();
	a[0] = document.forms.userform.newfname.value;
	a[1] = document.forms.userform.newlname.value;
	
	var msg = new Array();
	msg[0] = "First Name\n";
	msg[1] = "Last Name\n";

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

	if (txt != "")
	{
		txt = "The following fields are required :\n\n" + txt;
		alert(txt);
		event.returnValue=false;		
	}
	else
	{	
	//	alert("hello");
		sendprofile();
		return true;
	}
}

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 menuHover(id) 
{
	id.className='colour1colour2 fs11px mt1 p33315';
	if(id.children) 
	{
		id.children.tags("a")[0].className='colour1colour2 tdnone'; 	
	}
}

function menuOff(id)
{
	id.className='whitecolour1 fs11px mt1 p33315';
	if(id.children) 
	{
		id.children.tags("a")[0].className='whitecolour1 tdnone'; 	
	}
}

function submenuHover(id) 
{
	id.className='colour1colour2 fs11px mt1 p33325';
	if(id.children) 
	{
		id.children.tags("a")[0].className='colour1colour2 tdnone'; 	
	}
}

function submenuOff(id)
{
	id.className='colour1colour3 fs11px mt1 p33325';
	if(id.children) 
	{
		id.children.tags("a")[0].className='colour1colour3 tdnone'; 	
	}
}

function reloadPage()
{
	document.forms["continue"].submit();
}

function setTimer(delay)
{
	setTimeout("reloadPage();",delay);
}

function setaction(_action)
{
	document.forms['contactsform'].action2 = _action;
}

function setid(_id)
{
	document.forms['contactsform'].the_id.value = _id;
}

function changeAllIdsSelection(checked)
{
	if (document.forms['contactsform'].ids.length)
	{
		num = document.forms['contactsform'].ids.length;	
		for (i=0; i<num; i++)
		{
			document.forms['contactsform'].ids[i].checked = checked;
		}
	}
	else
	{
		document.forms['contactsform'].ids.checked = checked;
	}
}

function getAllIdsSelected()
{
	document.forms['contactsform'].idslist.value = "";
	if (document.forms['contactsform'].ids.length)
	{
		num = document.forms['contactsform'].ids.length;
		var list = "";
		for (i=0; i<num; i++)
		{
			if (document.forms['contactsform'].ids[i].checked)
			{
				if (list == "")
				{
					list = document.forms['contactsform'].ids[i].value;
				}
				else
				{
					list += "," + document.forms['contactsform'].ids[i].value;
				}
			}
		}
		document.forms['contactsform'].idslist.value = list;
	}
	else
	{
		if (document.forms['contactsform'].ids.checked)
		{
			document.forms['contactsform'].idslist.value = document.forms['contactsform'].ids.value;
		}
	}	
}

function getDetailsSelectedUsers()
{
	getAllIdsSelected();
	if (document.forms['contactsform'].idslist.value == "")
	{
		alert("No users selected");
	}
	else
	{
		//alert(document.forms['contactsform'].idslist.value);
		document.forms['contactsform'].action = "xls.php";
		document.forms['contactsform'].idslist.value = document.forms['contactsform'].idslist.value;
		document.forms['contactsform'].submit();
	}
}

function deleteSelectedUsers()
{
	getAllIdsSelected();
	if (document.forms['contactsform'].idslist.value == "")
	{
		alert("No users selected");
	}
	else
	{
		//alert(document.forms['contactsform'].idslist.value);
		document.forms['contactsform'].dodelete.value = "Y";
		document.forms['contactsform'].idslist.value = document.forms['contactsform'].idslist.value;
		document.forms['contactsform'].submit();
	}
}

function sendemailSelectedUsers()
{
	getAllIdsSelected();
	if (document.forms['contactsform'].idslist.value == "")
	{
		alert("No users selected");
	}
	else
	{
		//alert(document.forms['contactsform'].idslist.value);
		document.forms['contactsform'].action = "index.php?p=2&s=3";
		document.forms['contactsform'].idslist.value = document.forms['contactsform'].idslist.value;
		document.forms['contactsform'].submit();
	}
}