// We want to determine which country the user is in, so that we can show them 
// country defined content (all right, so we can showw them the right ads!)
// If we cant work it out, then we assume the US.
// Possible returns are 
//    us
//    uk
// The value is in the country variable once this script has been included.
var country = undefined;

// First we try the user or system language if available
var language = navigator.userLanguage;
if (!language)
{
  language = navigator.systemLanguage;
}

if (language)
{
  ////document.write("<p>Language given: " + language);
  // If we have a language then we use that to determine the country
  language = language.toLowerCase();
  if (language == "en-gb" || language == "en-ie" || language == "ga" || language == "cy")
  {
    // GB or Irish English, Irish, or Welsh are all treated as the UK
    country = "uk";
  }
  else if (language == "en-ca" || language == "fr-ca")
  {
    // If they have gone to the trouble of claiming to be Canadian, then they will be treated as American!
    country = "us";
  }
  else
  {
    // All other settings are ambiguous; including "en"
    // We will distinguish things based on timezone
  }
}

if (!country)
{
  // We have not determined the country, so try the timezone
  var now = new Date();
  var tzo = now.getTimezoneOffset();
  ////document.write("<p>Date " + now + " Timezone offset: " + tzo);
  if ((tzo >= -120) && (tzo <= 120))
  {
    // Within 2 hours of GMT is assumed to be the UK, or within Europe at least
    // so direct them to the UK
    country = "uk";
  }
  else
  {
    // Outside the likely UK timezomes
    country = "us";
  }
}

// There are other things we could consider, but do not do so at the moment
//  document.referrer  - did we arrive here from google.co.uk for example?
//  navigator.language - may only tell us where the software was produced - many countries use US builds!
//  navigator.browserLanguage - may only tell us where the software was produced - many countries use US builds!
//  navigator.userAgent - may only tell us where the software was produced - many countries use US builds!
//  navigator.userVersion - may only tell us where the software was produced - many countries use US builds!
