var siteZones = {
	"" : 
	{   
				"Français" : {"lang" : "fr", "country" : "", "zone" :"france", "selectedtxt" :"Langues"},	
				"English" : {"lang" : "gb", "country" : "", "zone" :"united-kingdom", "selectedtxt" :"Languages"},
				"Deutsch" : {"lang" : "de", "country" : "", "zone" :"deutschland", "selectedtxt" :"Sprache"},
				"Español": {"lang" : "es", "country" : "", "zone" :"espana", "selectedtxt" :"Idiomas"},	 	
				"Italiano" : {"lang" : "it", "country" : "", "zone" :"italia", "selectedtxt" :"Lingue"},
				"Nederlands" : {"lang" : "nl", "country" : "", "zone" :"nederland", "selectedtxt" :"Talen"},
				"Português" : {"lang" : "pt", "country" : "", "zone" :"portugal", "selectedtxt" :"Idioma"},
				"Português (BR)" : {"lang" : "pt-br", "country" : "", "zone" :"", "selectedtxt" :"Idioma"},
				"中文(简体)" : {"lang" : "zh", "country" : "", "zone" :"home", "selectedtxt" :"语言"},				
				"Other" : {"lang" : "gb", "country" : "", "zone" :"home", "selectedtxt" :"Languages"}
	}
};

 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 at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child );

  var top  = (c["at_position"] == "y") ? p.offsetHeight : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;

  for (; p; p = p.offsetParent)
  {
    top  += 0 ;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  //c.style.left       = left+'px';
  c.style.visibility = "visible";
}

// ***** at_show *****

function at_show()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  at_show_aux(p.id, c.id);
  clearTimeout(c["at_timeout"]);
}

// ***** at_hide *****

function at_hide()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 333);
}

// ***** at_click *****

function at_click()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id); else c.style.visibility = "hidden";
  return false;
}

// ***** at_attach *****

function at_attach(parent, child, showtype, position, cursor)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = at_click;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
    case "hover":

      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      //c.onmouseout  = at_hide;
      break;
  }
}

function getCookie(sName) {
	var cookContent = document.cookie, cookEnd, i, j;
	var sName = sName + "=";

	for (i=0, c=cookContent.length; i<c; i++) {
			j = i + sName.length;
			if (cookContent.substring(i, j) == sName) {
					cookEnd = cookContent.indexOf(";", j);
					if (cookEnd == -1) {
							cookEnd = cookContent.length;
					}
					return decodeURIComponent(cookContent.substring(j, cookEnd));
			}
	}       
	return null;
}

 
function createSiteZonesOptions(selectId){
 if(document.getElementById(selectId) && siteZones){
	var zone ='';
	var currentLang ='';
	var langContent = document.getElementById('itemLang');
   
   /* case home tplHome */
	if (document.getElementById('tplHome')) {
	var langZoneExp = /\/([a-z]{2}(?:-[a-z]{2})?)\/([a-z\-]+)\/index\.shtml/;
	langZoneExp.exec(document.location);
	var zone = RegExp.$2;
	var currentLang = RegExp.$1;

	}
	 /* other case */
	else { 
	var countrySelected = getCookieCountry();
	if (countrySelected != undefined) { var zone = countrySelected; }
	var url = window.location.pathname;
	var currentLang = url.substring(1,url.indexOf("/",1));
	}

	for(var zones in siteZones){
		
   	if(siteZones[zones]){

		
   		for(var countryName in siteZones[zones]){
			
	   		if(siteZones[zones][countryName]){
				var oOption = document.createElement('li'); 
		 
				oOption.setAttribute("class", siteZones[zones][countryName].lang);
				oOption.setAttribute("className", siteZones[zones][countryName].lang);//ie
				
				var link = document.createElement('a'); 			
				if (countryName !=  "Other"){
					link.setAttribute("href","/geo/setZone.jsp?lang="+siteZones[zones][countryName].lang+"&country="+siteZones[zones][countryName].country);
					
				}else {
					link.setAttribute("href","/gb/country/index.shtml");
				}
				
				if (siteZones[zones][countryName].country != '')	{	
				
					link.setAttribute("class", siteZones[zones][countryName].zone+' '+siteZones[zones][countryName].lang);
					
					link.setAttribute("className", siteZones[zones][countryName].zone+' '+siteZones[zones][countryName].lang);//ie		
					
				}else{
					link.setAttribute("class", 'otherCountries');
					link.setAttribute("className", 'otherCountries');//ie	
					
				}				
				
				link.innerHTML = countryName.toString();
				oOption.appendChild(link);
				
				var userZoneSaved = getCookie('userBrowsingZoneLocalization');
				var userLocalSaved = getCookie('userLocalization');
				
				if(userZoneSaved && userLocalSaved ){
				siteZones[zones][countryName].selectedtxt
				
					if(userZoneSaved != "home" && siteZones[zones][countryName].country == userLocalSaved &&  siteZones[zones][countryName].zone ==  userZoneSaved && siteZones[zones][countryName].lang == currentLang){
						document.getElementById('currentLanguage').innerHTML =  siteZones[zones][countryName].selectedtxt;
					}else if(userZoneSaved == "home" && siteZones[zones][countryName].country == userLocalSaved && siteZones[zones][countryName].lang == currentLang){
						document.getElementById('currentLanguage').innerHTML =  siteZones[zones][countryName].selectedtxt;
					}
					
				}				
				else if(siteZones[zones][countryName].country =="" && siteZones[zones][countryName].lang == currentLang ){
					document.getElementById('currentLanguage').innerHTML =  siteZones[zones][countryName].selectedtxt;
				} 
				
				document.getElementById('listLang').setAttribute("class", siteZones[zones][countryName].lang);					
				document.getElementById('currentLanguage').setAttribute("selected","selected");
	     
			   langContent.appendChild(oOption);
		   }
		   
		   	
	 	}		  
   	}
	langContent.setAttribute("class", zone);
	langContent.setAttribute("className", zone); //ie
	
	if(navigator.userAgent.toLowerCase().indexOf('msie 6') != -1){//ie	
		at_attach("listLang", "itemLang", "hover", "y", "pointer");
	}
  }
 }
}   
