var siteZones = {
	"" : 
	{   
				"Belgique" : {"lang" : "fr", "country" : "be", "zone" :"belgium"},
				"België" : {"lang" : "nl", "country" : "be", "zone" :"belgium"},
				"Deutschland" : {"lang" : "de", "country" : "de", "zone" :"deutschland"},
				"España": {"lang" : "es", "country" : "es", "zone" :"espana"},
				"France" : {"lang" : "fr", "country" : "fr", "zone" :"france"},
				"Italia" : {"lang" : "it", "country" : "it", "zone" :"italia"}, 		 
				"Nederland" : {"lang" : "nl", "country" : "nl", "zone" :"nederland"},
				"Österreich" : {"lang" : "de", "country" : "at", "zone" :"oesterreich"},
				"Portugal" : {"lang" : "pt", "country" : "pt", "zone" :"portugal"},
				"Suisse" : {"lang" : "fr", "country" : "ch", "zone" :"switzerland"},
				"Schweiz" : {"lang" : "de", "country" : "ch", "zone" :"switzerland"},		
				"United Kingdom" : {"lang" : "gb", "country" : "gb", "zone" :"united-kingdom"},
				"Brasil" : {"lang" : "pt-br", "country" : "br", "zone" :"brasil"},
				"Asia" : {"lang" : "gb", "country" : "th", "zone" :"asia"},
				"Australia" : {"lang" : "gb", "country" : "au", "zone" :"australia"},
				"New Zealand & Fiji" : {"lang" : "gb", "country" : "nz", "zone" :"new-zealand-fidji"},
				"Africa" : {"lang" : "gb", "country" : "dz" , "zone" :"africa"},
				"Afrique" : {"lang" : "fr", "country" : "dz", "zone" :"africa"},
				"Other countries" : {"lang" : "gb", "country" : "", "zone" :"home"},
				"Autres pays" : {"lang" : "fr", "country" : "", "zone" :"home"},
				"Sonstige Länder" : {"lang" : "de", "country" : "", "zone" :"home"},
				"Outros países" : {"lang" : "pt", "country" : "", "zone" :"home"},
				"Andere landen" : {"lang" : "nl", "country" : "", "zone" :"home"},
				"Altri paesi" : {"lang" : "it", "country" : "", "zone" :"home"},
				"Otros países" : {"lang" : "es", "country" : "", "zone" :"home"}
	}
};


 function getCookieCountry(){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
	  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
	  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
	  x=x.replace(/^\s+|\s+$/g,"");
	  if (x=='userBrowsingZoneLocalization')
		{
		return unescape(y);
		}
	  }
}
 
function createSiteZonesOptions(selectId){
 if(document.getElementById(selectId) && siteZones){
	var zone ='';
	var currentLang ='';
	var langContent = document.getElementById('languages');
   
	/* Default = get geoloc from cookie */
	var countrySelected = getCookieCountry();
	if (countrySelected != "" && countrySelected != undefined) { 
		if (countrySelected=="asia-china-japan-india-singapore-malaysia-indonesia") countrySelected="asia"; 
		zone = countrySelected;
		var url = window.location.pathname;
		currentLang = url.substring(1,url.indexOf("/",1));
		if(currentLang == 'hotel-cms'){	var currentLang = url.substring(11,url.indexOf("/",11));}//case hotel-cms
	}
	/* If direct access (no cookie) on homepage,  get geoloc from HP URL */
	else if (document.getElementById('tplHome')) {
		var langZoneExp = /\/([a-z]{2}(?:-[a-z]{2})?)\/([a-z\-]+)\/index\.shtml/;
		langZoneExp.exec(document.location);
		zone = RegExp.$2;
		currentLang = RegExp.$1;
	}
	/* If direct access (no cookie) on any other page, consider default geoloc */
	else {
		zone = "home";
		currentLang = (jQuery("html").attr("lang")=="en") ? "gb" : jQuery("html").attr("lang");;
	}

	for(var zones in siteZones){
		var oOptgroup = document.createElement('optgroup');
		oOptgroup.label = zones;
		
   	if(siteZones[zones]){
   		for(var countryName in siteZones[zones]){
	   		if(siteZones[zones][countryName]){
				var oOption = document.createElement('option'); 
		 
				oOption.setAttribute("class", siteZones[zones][countryName].zone);
				
               if(siteZones[zones][countryName].lang == currentLang){
					if (zone != '' && siteZones[zones][countryName].zone == zone){oOption.setAttribute("selected","selected");} 
					else if ( zone=='' && siteZones[zones][countryName].zone == 'home'){
								oOption.setAttribute("selected","selected");
								zone='home';} 		
              } 
             
             oOption.innerHTML = countryName
		     oOption.value = "/geo/setZone.jsp?lang="+siteZones[zones][countryName].lang+"&country="+siteZones[zones][countryName].country;
		     
			   oOptgroup.appendChild(oOption);
		   }
	 	 }
		   document.getElementById(selectId).appendChild(oOptgroup);
		  
   	}
	langContent.setAttribute("class", zone);
	langContent.setAttribute("className", zone); //ie
  }
 }
}   
