
// calls insertBanner if it determines that a browser locale string indicates that we are from
// europe, africa, or the middle east
function checkLocale(){
  var countries = [
		    // europe
		    "am", // armenia
		    "by", // belarus
		    "cz", // czech republic
		    "hu", // hungary
		    "ie", // ireland
		    "md", // moldova
		    "pl", // poland
		    "ro", // romania
		    "ru", // russia
		    "sk", // slovakia
		    "ua", // ukraine
		    "fi", // finland
		    "dk", // denmark
		    "ee", // estonia
		    "gg", // guernsey
		    "is", // iceland
		    "im", // isle of man
		    "je", // jersey
		    "lv", // latvia
		    "lt", // lithuania
		    "no", // norway
		    "se", // sweden
		    "gb", // united kingdom
		    "al", // albania
		    "ad", // andorra
		    "ba", // bosnia and herzegovina
		    "hr", // croatia
		    "gi", // gibraltar
		    "gr", // greece
		    "it", // italy
		    "mk", // macedonia
		    "mt", // malta
		    "me", // montenegro
		    "pt", // portugal
		    "sm", // san marino
		    "rs", // serbia
		    "si", // slovenia
		    "es", // spain
		    "at", // austria
		    "be", // belgium
		    "fr", // france
		    "dl", // germany
		    "lu", // luxembourg
		    "mc", // monaco
		    "nl", // netherlands
		    "ch", // switzerland
		    "kz", // kazakhstan
		    "az", // azerbaijan
		    "ge", // georgia
		    "tr", // turkey
		    

		    // africa
		    "bi", // burundi
		    "km", // comoros
		    "dj", // djibouti
		    "er", // eritrea
		    "et", // ethiopia
		    "ke", // kenya
		    "mg", // madagascar
		    "mw", // malawi
		    "mu", // mauritius
		    "yt", // mayotte
		    "mz", // mozambique
		    "re", // reunion
		    "rw", // rwanda
		    "sc", // seychelles
		    "so", // somalia
		    "tz", // tanzania
		    "ug", // uganda
		    "zm", // zambia
		    "zw", // zimbabwe
		    "ao", // angola
		    "cm", // cameroon
		    "cf", // central african republic
		    "td", // chad
		    "cg", // congo
		    "cd", // democratic republic of the congo
		    "gq", // equatorial guinea
		    "ga", // gabon
		    "st", // sao tome and principe
		    "dz", // algeria
		    "eg", // egypt
		    "ma", // morocco
		    "sd", // sudan
		    "tn", // tunisia
		    "eh", // western sahara
		    "bw", // botswana
		    "ls", // lesotho
		    "na", // namibia
		    "za", // south africa
		    "bj", // benin
		    "bf", // burkina faso
		    "cv", // cape verde
		    "ci", // cote d'ivoire
		    "gm", // gambia
		    "gh", // ghana
		    "gn", // guinea
		    "gw", // guinea-bissau
		    "lr", // liberia
		    "ml", // mali
		    "mr", // mauritania
		    "ne", // niger
		    "ng", // nigeria
		    "sh", // saint helens
		    "sn", // senegal
		    "sl", // sierra leone
		    "tg", // togo

		    // middle east
		    "ir", // iran
		    "iq", // iraq
		    "kw", // kuwait
		    "bh", // bahrain
		    "om", // oman
		    "qa", // qatar
		    "sa", // saudi arabia
		    "ae", // united arab emirates
		    "ye", // yemen
		    "il", // israel
		    "jo", // jordan
		    "lb", // lebanon
		    "sy", // syria
		    ];
		    
  var match_fields = [ navigator.systemLanguage,
		       navigator.browserLanguage,
		       navigator.userLanguage,
		       navigator.language ];

  var match_regex = ".*-(";
  for( var i = 0; i < countries.length - 1; i++ ){
    match_regex += countries[i] + "|";
  }
  match_regex += ")$";
  match_regex = new RegExp( match_regex );

  for( var i = 0; i < countries.length; i++ ){
    for( var j = 0; j < match_fields.length; j++ ){
      if( countries[i] != undefined &&
	  match_fields[j] != undefined &&
	  match_fields[j].toLowerCase().match( match_regex ) ){
	insertBanner();
	return match_fields[j];
      }
    }
  }
}

// appends a couple of paragraph nodes with text linking to the WWN UK site to the document element
// with the id "international_banner"
function insertBanner(){
  var parent_element = document.getElementById( "international_banner" );
  var p = document.createElement( "p");
  var h = document.createElement( "h3" );
  h.appendChild( document.createTextNode( "Are you connecting from the UK, Ireland, Africa, Europe, or the Middle East? " ) );
  p.appendChild( h );
  parent_element.appendChild( p );

  p = document.createElement( "p" );
  h = document.createElement( "h3" );
  var anchor = document.createElement( "a" );
  anchor.href = "http://www.wwnorton.co.uk/";
  anchor.appendChild( document.createTextNode( "Click here to go to the W. W. Norton UK site." ) );
  h.appendChild( anchor );
  p.appendChild( h );
  parent_element.appendChild( p );
}
