function isEurozoneCountry(strCountry) 
{
   var strUC = strCountry.toUpperCase();
   
   return ((strUC == "AUSTRIA")    || (strUC == "BELGIUM")     || (strUC == "GERMANY")  || (strUC == "SPAIN")   ||
           (strUC == "FRANCE")     || (strUC == "FINLAND")     || (strUC == "GREECE")   || (strUC == "IRELAND") ||
		   (strUC == "LUXEMBOURG") || (strUC == "NETHERLANDS") || (strUC == "PORTUGAL"))
}


function validateFormData(form) 
{
  //alert('Checking form...');
  var errorMsg = '';
  
  // Test that all the required fields are filled out ok
  	
  if (form.firstname.value == "")
    errorMsg += 'Your first name is required.\n';
	
  if (form.tel.value == "")
    errorMsg += 'Your telephone number is required.\n';
	
  if (form.Email.value == "" )
  {
    errorMsg += 'An Email address is required\n';
	form.Email.focus();
  }
  else
  {
	x = form.Email.value.indexOf('@');
	y = form.Email.value.indexOf('.');

    if (x < 1 || x == (form.Email.value.length-1) || y < 1 ) 
	{
	  errorMsg += 'You must give a valid email address.\n';
	  form.Email.focus();
	  form.Email.select();
	}
	  
    s = form.Email.value.indexOf(' ');
    if (s != -1)
	{
	  errorMsg += 'Please check your email address. It should not contain or have leading/trailing spaces \n';
	  form.Email.focus();
	  form.Email.select();
	}
  }	
   if (errorMsg) 
	alert('Required form fields:\n'+errorMsg);
  document.returnValue = (errorMsg == '');
}


function validateOrderForm(form) 
{
   //alert('Checking form...');
  var errorMsg = '';
  
  // Test that all the required fields are filled out ok
  
  if (form.pspCustomerEmail.value == "" )
  {
    errorMsg += 'An email address is required\n';
	form.pspCustomerEmail.focus();
  }
  else
  {
	x = form.pspCustomerEmail.value.indexOf('@');
	y = form.pspCustomerEmail.value.indexOf('.');

    if (x < 1 || x == (form.pspCustomerEmail.value.length-1) || y < 1 ) 
	{
	  errorMsg += 'You must give a valid email address.\n';
	  form.pspCustomerEmail.focus();
	  form.pspCustomerEmail.select();
	}
	  
    s = form.pspCustomerEmail.value.indexOf(' ');
    if (s != -1)
	{
	  errorMsg += 'Please check the email address. It should not contain spaces\n';
	  form.pspCustomerEmail.focus();
	  form.pspCustomerEmail.select();
	}
  }
  	
  if (form.pspCustomerFirstName.value == "" )
  {
    errorMsg += 'Your forename is required\n';
	form.pspCustomerFirstName.focus();
	form.pspCustomerFirstName.select();
   }
	
  if (form.pspCustomerLastName.value == "" )
  {
    errorMsg += 'Your surname is required\n';
	form.pspCustomerLastName.focus();
	form.pspCustomerLastName.select();
  }
	
 if (form.pspCustomerAddress.value == "" )
 {
    errorMsg += 'A delivery address is required\n';
	form.pspCustomerAddress.focus();
	form.pspCustomerAddress.select();
 }
 
  if (form.pspCustomerPostcode.value == "" )
 {
    errorMsg += 'A Postcode or Zipcode is required\n';
	form.pspCustomerPostcode.focus();
	form.pspCustomerPostcode.select();
 }	
	

  if (form.eurozone.value == "Y" )
  {
    // Eurozone overseas delivery selected.
    if (((form.country.options[form.country.selectedIndex].value).toUpperCase()) == "UK")
    {
       errorMsg += 'You have selected a Eurozone delivery to a UK address\n';
	   form.country.focus();
	}
	else if (!isEurozoneCountry(form.country.options[form.country.selectedIndex].value))
	{
       errorMsg += 'You have selected a Eurozone delivery to a non-Eurozone overseas address\n';
	   form.country.focus();
	}
  }
  else if (form.overseas.value == "Y" )
  {
    // Non-Eurozone overseas delivery selected.
    if (((form.country.options[form.country.selectedIndex].value).toUpperCase()) == "UK")
    {
       errorMsg += 'You have selected an international delivery to a UK address\n';
	   form.country.focus();
	}
	else if (isEurozoneCountry(form.country.options[form.country.selectedIndex].value))
    {
       errorMsg += 'You have selected a non-Eurozone international delivery to a Eurozone address\n';
	   form.country.focus();
	}
  }
  else
  {
    // UK delivery selected.
	if (isEurozoneCountry(form.country.options[form.country.selectedIndex].value))
    {
       errorMsg += 'You have selected UK delivery to a Eurozone address\n';
	   form.country.focus();
	}
    else if (((form.country.options[form.country.selectedIndex].value).toUpperCase()) != "UK")
    {
       errorMsg += 'You have selected UK delivery to a non-Eurozone overseas address\n';
	   form.country.focus();
	}
  }
	
	if (form.Tel.value == "" )
    {
    errorMsg += 'Please give a telephone number where we can reach you\n';
	form.Tel.focus();
	form.Tel.select();
    }
	
   if (!form.termsconditions.checked)
  	errorMsg += 'Please indicate that you are in agreement with our Terms & Conditions\n';

	
  if (errorMsg) 
	alert('Required form fields:\n'+errorMsg);
	
  document.returnValue = (errorMsg == '');
}



function validateBuyersData(form) 
// Used with ProTX forms
{
  //alert('Checking form...');
  var errorMsg = '';
  
  // Test that all the required fields are filled out ok
  
  if (form.Customeremail.value == "" )
  {
    errorMsg += 'Your Email Address is required\n';
	form.Customeremail.focus();
  }
  else
  {
	x = form.Customeremail.value.indexOf('@');
	y = form.Customeremail.value.indexOf('.');

    if (x < 1 || x == (form.Customeremail.value.length-1) || y < 1 ) 
	{
	  errorMsg += 'You must give a valid Email Address.\n';
	  form.Customeremail.focus();
	  form.Customeremail.select();
	}
	  
    s = form.Customeremail.value.indexOf(' ');
    if (s != -1)
	{
	  errorMsg += 'Please check your Email Address. It should not contain or have leading/trailing spaces\n';
	  form.Customeremail.focus();
	  form.Customeremail.select();
	}
  }
  	
  if (form.CustomerName.value == "" )
    errorMsg += 'Your Name is required\n';


  if (form.BillingAddress.value == "" )
  	errorMsg += 'Please enter the Card Holders Billing Address\n';

  
  if ( ! form.termsconditions.checked )
  	errorMsg += 'Please indicate that you agree to our Terms & Conditions\n';
	
   if (errorMsg) 
	alert('Required form fields:\n'+errorMsg);
  document.returnValue = (errorMsg == '');
}

function validateFormWholesaleData(form) 
{
  //alert('Checking form...');
  var errorMsg = '';
  
  // Test that all the required fields are filled out ok
  
  if (form.email.value == "" )
  {
    errorMsg += 'Your email address is required\n';
	form.email.focus();
  }
  else
  {
	x = form.email.value.indexOf('@');
	y = form.email.value.indexOf('.');

    if (x < 1 || x == (form.email.value.length-1) || y < 1 ) 
	{
	  errorMsg += 'You must give a valid email address.\n';
	  form.email.focus();
	  form.email.select();
	}
	  
    s = form.email.value.indexOf(' ');
    if (s != -1)
	{
	  errorMsg += 'Please check your email address. It should not contain or have leading/trailing spaces\n';
	  form.email.focus();
	  form.email.select();
	}
  }
  	
  if (form.coname.value == "" )
    errorMsg += 'A Company name is required\n';
	
  if (form.name.value == "" )
    errorMsg += 'A contact name is required\n';
	
  if (form.tel.value == "" )
    errorMsg += 'Your telephone number is required\n';
	
   if (errorMsg) 
	alert('Required form fields:\n'+errorMsg);
  document.returnValue = (errorMsg == '');
}
 // Below is for recommend form data checking
function validateFormData2(form) 
{
  //alert('Checking form...');
  var errorMsg = '';
  
  // Test that all the required fields are filled out ok
  	
  if (form.To.value == "" )
    errorMsg += 'A Recipients first name (Dear ...) is required\n';
  	
  if (form.From.value == "" )
    errorMsg += 'Your own first name (From...)  is required\n';

  if (form.Email.value == "" )
  {
    errorMsg += 'An email (To...) address is required\n';
	form.Email.focus();
  }
  else
  {
	x = form.Email.value.indexOf('@');
	y = form.Email.value.indexOf('.');

    if (x < 1 || x == (form.Email.value.length-1) || y < 1 ) 
	{
	  errorMsg += 'You must give a valid email address.\n';
	  form.Email.focus();
	  form.Email.select();
	}
	  
    s = form.Email.value.indexOf(' ');
    if (s != -1)
	{
	  errorMsg += 'Please check your email address. It should not contain or have leading/trailing spaces\n';
	  form.Email.focus();
	  form.Email.select();
	}
  }	
   if (errorMsg) 
	alert('Required form fields:\n'+errorMsg);
  document.returnValue = (errorMsg == '');
}

