function ValidateDefault(theForm)
{
	var CountryList = document.getElementById("rcountry");
	var SubscriptionNumber = document.getElementById("SubscriptionNumber");

	if (CountryList.value == 0)
	{
		alert("Please select a country");
		CountryList.focus();
		return false;
	}	
		
	if (SubscriptionNumber.value.length != 0)	
	{	
		if (SubscriptionNumber.value.length != 8)
		{
			alert("Please enter 8 characters")
			SubscriptionNumber.focus();
			return false;			
		}
		//alert(!NumericCheck(SubscriptionNumber.value))
		if (!NumericCheck(SubscriptionNumber.value))
		{			
			alert("Please enter numbers only");
			SubscriptionNumber.focus();
			return false;
		}
	}
	return true;	
}

function ValidateAddressForm(theForm)
{      
	if (theForm.title.value == "")
	{
		alert("Please enter a value for the \"Title\" field.");
		theForm.title.focus();
		return (false);
	}

	if (theForm.christianname.value == "")
	{
		alert("Please enter a value for the \"First Name\" field.");
		theForm.christianname.focus();
		return (false);
	}

	if (theForm.surname.value == "")
	{
		alert("Please enter a value for the \"Last Name\" field.");
		theForm.surname.focus();
		return (false);
	}

	if (theForm.addressline1.value == "")
	{
		alert("Please enter a value for the \"Address Line 1\" field.");
		theForm.addressline1.focus();
		return (false);
	}
	 
	if (theForm.addressline3.value == "")
	{
		alert("Please enter a value for the \"Town / City\" field.");
		theForm.addressline3.focus();
		return (false);
	}
	  
	if (theForm.country.selectedIndex == 0)
	{
		alert("Please select a value for the \"Country\" field.");
		theForm.country.focus();
		return (false);
	}	  
	  
	if (theForm.postcode.value == "")
	{
		alert("Please enter a value for the \"Postcode / ZipCode\" field.");
		theForm.postcode.focus();
		return (false);
	}
	  
	if (theForm.emailaddress.value == "")
	{
		alert("please enter a value for the \"Email Address\" field.")
		theForm.emailaddress.focus();
		return (false);
	}
	else
	{
		if (!emailCheck(theForm.emailaddress.value))
		{
			theForm.emailaddress.focus();
    			return (false);
		}
	}
		
	if (theForm.telephonenumber.value == "")
	{
		alert("Please enter a value for the \"Telephone Number\" field.");
		theForm.telephonenumber.focus();
		return (false);
	}	
		  
	if (theForm.rtitle.value == "")
	{
		alert("Please enter a value for the \"Title\" field.");
		theForm.rtitle.focus();
		return (false);
	}

	if (theForm.rchristianname.value == "")
	{
		alert("Please enter a value for the \"First Name\" field.");
		theForm.rchristianname.focus();
		return (false);
	}

	if (theForm.rsurname.value == "")
	{
		alert("Please enter a value for the \"Last Name\" field.");
		theForm.rsurname.focus();
		return (false);
	}	  

	if (theForm.raddressline1.value == "")
	{
		alert("Please enter a value for the \"Address Line 1\" field.");
    		theForm.raddressline1.focus();
    		return (false);
  	}
	  	  
   	if (theForm.raddressline3.value == "")
  	{
    		alert("Please enter a value for the \"Town / City\" field.");
    		theForm.raddressline3.focus();
    		return (false);
  	}

	if (theForm.rpostcode.value == "")
  	{
    		alert("Please enter a value for the \"postcode\" field.");
    		theForm.rpostcode.focus();
    		return (false);
  	}  

	return true;
}

function ValidateOrderForm(theForm)
{
	  var payment_mthd;

          payment_mthd = theForm.paymentmthd.value;
	  
	  //only validate direct debit data, if payment method selected
	  if (payment_mthd == "D")
	  {
  		if (theForm.SortCode.value == "")
  		{
   			alert("Please enter a value for the \"Bank Sort Code\" field.");
   			theForm.SortCode.focus();
    			return (false);
  		}

		if (theForm.SortCode.value.length < 6)
		{
  			alert("Please enter at least 6 digits in the \"Bank Sort Code\" field.");
  			theForm.SortCode.focus();
  			return (false);
		}
		
		if (!NumericCheck(theForm.SortCode.value))
		{
			alert("Please enter only digit characters in the \"Bank Sort Code\" field.");
			theForm.SortCode.focus();
			return (false);
		}

		if (theForm.AccountNumber.value == "")
		{
 			alert("Please enter a value for the \"Bank Account No\" field.");
 			theForm.AccountNumber.focus();
  			return (false);
		}

		if (!NumericCheck(theForm.AccountNumber.value))
		{
			alert("Please enter only digit characters in the \"Bank Account No\" field.");
			theForm.AccountNumber.focus();
			return (false);
		}

		if (theForm.AccountName.value == "")
  		{
  	 		alert("Please enter a value for the \"Bank Account Name\" field.");
  	 		theForm.AccountName.focus();
  	  		return (false);
  		}

		if (theForm.ddmandate.value < "y")
		{
			openMandate();
			return (false);
		}
	}
	  
	return (true);
}

function openMandate()
{
	var theForm = document.getElementById("theForm");
	var sUrl = "ddmandate.asp?name=" + 		
			escape(theForm.AccountName.value) + "&acno=" + theForm.AccountNumber.value + 
			"&acsc=" + theForm.SortCode.value;
	window.open(sUrl,"ddmandate_page","width=600,height=500,resize=1");
}

function NumericCheck(InField)
{
	var checkOK = "0123456789";
  	var checkStr = InField;
		
	for (i = 0;  i < checkStr.length;  i++)
  	{
    	ch = checkStr.charAt(i);
    	for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
   			break;
		if (j == checkOK.length)
		{
			return (false);
			break;
		}
	}
	return (true);
}

function PopulateDelivery()
{	
	var theForm = document.getElementById("theForm");
	var CountryLen = theForm.rcountry.value.length;

	if (theForm.UseBilling.checked)
	{
		theForm.rtitle.value = theForm.title.value;
		theForm.rchristianname.value = theForm.christianname.value;
		theForm.rsurname.value = theForm.surname.value;		
		theForm.raddressline1.value = theForm.addressline1.value;
		theForm.raddressline2.value = theForm.addressline2.value;
		theForm.raddressline3.value = theForm.addressline3.value;
		theForm.raddressline4.value = theForm.addressline4.value;
		//theForm.rcountry.value = theForm.country.value;
		theForm.rpostcode.value = theForm.postcode.value;
	}
	else
	{
		theForm.rtitle.value = "";
		theForm.rchristianname.value = "";
		theForm.rsurname.value = "";
		theForm.raddressline1.value = "";
		theForm.raddressline2.value = "";
		theForm.raddressline3.value = "";
		theForm.raddressline4.value = "";
		theForm.rpostcode.value = "";
	}
}

function returnToParent()
{
    opener.document.theForm.ddmandate.value = "y";
    opener.document.theForm.B1.click();
    window.close();
}