var xhr;

var currentArea;
var numArea = 1;

var currentCountry;
var numCountry = 1;

var numSite = 1;

var areas = new Array();
var countrys = new Array();
var sites = new Array();

function getXhr()
{
    	if(window.XMLHttpRequest) // Firefox et autres
    	{
		xhr = new XMLHttpRequest(); 
    	}
	else if(window.ActiveXObject)// Internet Explorer 
	{ 
		try 
		{
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
        	catch (e)
        	{
        		try 
			{
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
        		{
   		         	alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");      		
        		}
		}
	}
	else 
	{
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		xhr = false; 
	} 
}

function getOptionLocation()
{
    	getXhr();

   	var url = 'fileadmin/location.xml';
    
    	xhr.onreadystatechange = setOptionLocation;
	xhr.open("GET",url,true);
	xhr.send(null);
}

function go(c)
{
    if(!c.data.replace(/\s/g,''))
        c.parentNode.removeChild(c);
}

function clean(d)
{
	var bal = d.getElementsByTagName('*');

	for(i=0;i < bal.length;i++)
	{
		a = bal[i].previousSibling;
		if(a && a.nodeType==3)
		    go(a);
		    
		b=bal[i].nextSibling;
		if(b && b.nodeType==3)
			go(b);
	}
	return d;
}

function area(id,name)
{
	this.id = id;
	this.name = name;
}

function country(id,areaId,name)
{
	this.id = id;
	this.areaId = areaId;
	this.name = name;
}

function site(id,countryId,name,link)
{
	this.id = id;
	this.countryId = countryId;
	this.name = name;
	this.link = link;
}

function setOptionLocation()
{
	var code;
	
	if(xhr.readyState == 4)
  	{
		getLocationData();
		setLocationCode();
		
	}

}

function getLocationData()
{

	reponse = clean(xhr.responseXML.documentElement);
	i = 0;
	while(reponse.getElementsByTagName('*')[i] != undefined)
	{
			
		if(reponse.getElementsByTagName('*')[i].tagName == "AREA")
		{

			areas[numArea] = new area(numArea,reponse.getElementsByTagName('*')[i].getAttribute("NAME"));
			currentArea = areas[numArea].id;
			numArea++;
		}
			
		if(reponse.getElementsByTagName('*')[i].tagName == "COUNTRY")
		{
			var countryName;

			countryName = reponse.getElementsByTagName('*')[i].getAttribute("NAME");
			
			countrys[numCountry] = new country(numCountry,currentArea,countryName);
			currentCountry = countrys[numCountry].id;
			numCountry++;
		}
		
		if(reponse.getElementsByTagName('*')[i].tagName == "SITE")
		{
			var siteName;
			siteName = reponse.getElementsByTagName('*')[i].getAttribute("NAME");
			siteLink = reponse.getElementsByTagName('*')[i].getAttribute("LINK");
			sites[numSite] = new site(numSite,currentCountry,siteName,siteLink);
			numSite++;
		}
		
		i++;
	}
	
}

function setLocationCode()
{
	var i = 1;
	var c = 1;
	var j;
	var k;
	var code = "";
	
	while(areas[i] != undefined)
	{

		document.getElementById('selectLocation').options[c] = new Option(areas[i].name,'');
		document.getElementById('selectLocation').options[c].style.float = "left";
		c++;
		j = 1;
		while(countrys[j] != undefined)
		{
			if(countrys[j].areaId == areas[i].id)
			{
				document.getElementById('selectLocation').options[c] = new Option("        "+countrys[j].name,'');
				if (navigator.appName != "Microsoft Internet Explorer")
			        {
					document.getElementById('selectLocation').options[c].style.paddingLeft = "25px";
				}
				c++;
				k = 1;
				while(sites[k] != undefined)
				{
					if(sites[k].countryId == countrys[j].id)
					{

						document.getElementById('selectLocation').options[c] = new Option('                '+sites[k].name,sites[k].link);
						if (navigator.appName != "Microsoft Internet Explorer")
			        		{
							document.getElementById('selectLocation').options[c].style.paddingLeft = "50px";
						}
                                                c++;
					}	
					
					k++;
				}
			}
			j++;
		}
		i++;
	}
	document.getElementById('selectLocation').onchange = changeLocation;
}

function changeLocation()
{
	if(document.getElementById('selectLocation').value != "")
	{
		document.location = document.getElementById('selectLocation').value;
	}
}



function value(e)
{
	document.getElementById(e).value= "";
}
function valueSearch(e)
{
	document.getElementById(e).value= "";
}