function newWindow(theUrl){
	window.open(theUrl,"_blank","toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=600");
}

function updateQty(itemID,i)
{
	var qty = document.getElementById("quantity_"+i).value
	document.location.href = "ShopUpdate.asp?CartItemID="+itemID+"&Quantity="+qty
}

function submitCartRoyal()
{
	//check the total quantity of royalty items (iRoyaltyQty)
	//against the total quantity of pupils (iPupilQty) recorded for the royalty payments.
	//if iRoyaltyQty is more than iPupils, prevent the checkout from being accessed.
	var xRoyaltyQty= document.getElementById("iRoyaltyQty");
	var xPupilQty = document.getElementById("iPupilQty");
	if (xRoyaltyQty.value !='' && xPupilQty.value !='')
	{
		value1 = parseFloat(xRoyaltyQty.value);
		value2 = parseFloat(xPupilQty .value);
		if (document.frmUpdate.royaltypay.checked == false)
		{
			if (value1 > value2)
			{
			alert ("You must pay royalties against the highlighted products.\nThe number of pupils you are paying royalties for must be equal to or more than the total quantity of royalty products in your shopping basket.\n\nIf you have already paid royalties on these products, check the box displayed under the basket items.");
			return false;
			}
		}
		else
		{
		return true;
		}
	}
	else
	{
	return false;
	}	
}

function submitCart()
{
	document.location.href = "checkout.asp"
}

//function submitCartPromo()
//{
//   var errorMsg = "";
//   
//	if (document.getElementById("Count").value == '' && !document.getElementById("Count").value == 0)
//    {
//    errorMsg += "You must enter a contact phone number.\n"
//    }
//	if (!errorMsg == '')
//	{
//		alert (errorMsg)
//		return false
//	}
//	return true
//}

function choosePayment(paymentType)
{
	  if (paymentType == 1)
	  {
	  document.getElementById("payMethod").value = 1;
	  document.getElementById("accountPayment").style.height='0px';
	  document.getElementById("accountPayment").style.display='none';
	  document.getElementById("accountPayment").style.visibility='hidden';
	  document.getElementById("cardPayment").style.height='280px';
	  document.getElementById("cardPayment").style.display='block';
	  document.getElementById("cardPayment").style.visibility='visible';
	  }
	  if (paymentType == 2)
	  {
	  document.getElementById("payMethod").value = 2;
	  document.getElementById("accountPayment").style.height='60px';
	  document.getElementById("accountPayment").style.display='block';
	  document.getElementById("accountPayment").style.visibility='visible';
	  document.getElementById("cardPayment").style.height='0px';
	  document.getElementById("cardPayment").style.display='none';
	  document.getElementById("cardPayment").style.visibility='hidden';
	  }
}

function validateForm()
{
	if (document.getElementById("payMethod").value == 1)
	{
		return validateCC()
	}
	if (document.getElementById("payMethod").value == 2)
	{
		return validatePO()
	}
}

function validateCC()
{
   var errorMsg = "";
   
   if (document.getElementById("cardholdername").value == "")
   {
   errorMsg += "You must enter the card holders name.\n"
   }
   if (document.getElementById("cardAddress1").value == "")
   {
   errorMsg += "You must enter your billing address.\n"
   }
   if (document.getElementById("cardCity").value == "")
   {
   errorMsg += "You must enter your billing city.\n"
   }
   if (document.getElementById("cardPostcode").value == "")
   {
   errorMsg += "You must enter your billing postcode.\n"
   }
   if (document.getElementById("cardPhone").value == "")
   {
   errorMsg += "You must enter a contact phone number.\n"
   }
   if (document.getElementById("dName").value == "")
   {
   errorMsg += "You must enter your name.\n"
   }
   if (document.getElementById("dAddress1").value == "")
   {
   errorMsg += "You must enter your delivery address.\n"
   }
   if (document.getElementById("dCity").value == "")
   {
   errorMsg += "You must enter your delivery town/city.\n"
   }
   if (document.getElementById("dPostcode").value == "")
   {
   errorMsg += "You must enter your delivery postcode.\n"
   }
   if (document.getElementById("dPhone").value == "")
   {
   errorMsg += "You must enter your delivery phone number.\n"
   }
   if (document.getElementById("dCustomerEmail").value == "")
   {
   errorMsg += "You must enter your email address.\n"
   }
	if (!errorMsg == '')
	{
		alert (errorMsg)
		return false
	}
}

function validatePO()
{
   //var blnError = false;
   var errorMsg = "";

	if (document.getElementById("orderNumber").value == '')
   {
   errorMsg += "You must provide us with your company purchase order number.\n"
   }
	if (!errorMsg == '')
	{
		alert (errorMsg)
		document.getElementById("orderNumber").focus()
		return false
	}
}

function changeAddress() 
{
	document.getElementById("modifyDelivery").style.display='inline';
	document.getElementById("changeAddressBtn").style.display='none';
	document.getElementById("updateAddressBtn").style.display='inline';
}

function updateAddress() 
{

   //var blnError = false;
   var errorMsg = "";
   var AddressPanel = "";

	if (document.getElementById("cardholdername").value == '')
    {
    errorMsg += "You must enter the card holders Name.\n"
    }
	if (document.getElementById("cardAddress1").value == '')
    {
    errorMsg += "You must enter your billing Address.\n"
    }
	if (document.getElementById("cardCity").value == '')
    {
    errorMsg += "You must enter your billing City.\n"
    }
	if (document.getElementById("cardPostcode").value == '')
    {
    errorMsg += "You must enter your billing Post Code.\n"
    }
	if (document.getElementById("cardPhone").value == '')
    {
    errorMsg += "You must enter a contact phone number.\n"
    }
	if (!errorMsg == '')
	{
		alert (errorMsg)
		return false
	}

	if (document.getElementById("dCopyCardHolder").checked)
	{
		if (!document.getElementById("cardholdername").value == ''){document.getElementById("dName").value=document.getElementById("cardholdername").value}
		if (!document.getElementById("cardAddress1").value == ''){document.getElementById("dAddress1").value=document.getElementById("cardAddress1").value}
		if (!document.getElementById("cardAddress2").value == ''){document.getElementById("dAddress2").value=document.getElementById("cardAddress2").value}
		if (!document.getElementById("cardAddress3").value == ''){document.getElementById("dAddress3").value=document.getElementById("cardAddress3").value}
		if (!document.getElementById("cardCity").value == ''){document.getElementById("dCity").value=document.getElementById("cardCity").value}
		if (!document.getElementById("cardPostcode").value == ''){document.getElementById("dPostcode").value=document.getElementById("cardPostcode").value}
		if (!document.getElementById("cardCountry").value == ''){document.getElementById("dCountry").value=document.getElementById("cardCountry").value}
		if (!document.getElementById("cardPhone").value == ''){document.getElementById("dPhone").value=document.getElementById("cardPhone").value}
		if (!document.getElementById("cardMobile").value == ''){document.getElementById("dMobile").value=document.getElementById("cardMobile").value}
	}
	
	document.getElementById('form2').action = "checkout.asp?action=SaveCheckout&goto=checkout.asp"
	document.getElementById('form2').submit();
	
	return true
}