// JavaScript Document
//--> Load de la page
function load(){
	
	var html = document.getElementById("root").innerHTML;
	if (document.getElementById("root").hasChildNodes()){
		parseMap();
		html += "<div id=\"msgAlert\" align=\"center\"><br/>Cliquez sur le logo Ipsos-Dell";
		html += " de la ville dont vous souhaitez consulter les r&eacute;sultats.</div>";
	}else{
		html += "<div id=\"msgAlert\" align=\"center\"><br/>";
		html += " 20H00 : Amiens, Angers, Caen, Metz Pau, Périgeux, Reims, Saint-Etienne.</div>";
	}
	document.getElementById("root").innerHTML = html;
}
//--< Load de la page 
//--> Supprime tt les villes
function resetpages(){
	if(document.getElementById("Villes").firstChild){
		while(document.getElementById("Villes").hasChildNodes()){
			var noeud=document.getElementById("Villes").firstChild;
			document.getElementById("Villes").removeChild(noeud);
		}
	}
}
//--<

function parseMap(){
	if(document.getElementById("root").firstChild){
		var i = 0;
		var j = 0;
		
		while(document.getElementById("root").childNodes[j]){
			j +=1;
		}
		//alert (j);
		for (i=0; i <= j-1 ; i++) {
			var noeud=document.getElementById("root").childNodes[i];
			if ((noeud.id ) && (noeud.id != "msgAlert")){
				var noeudTab = document.getElementById(noeud.id).firstChild;
				var urlimg = noeudTab.className;
				//alert (urlimg);
				urlimg = urlimg.substr(3,urlimg.length);
				//ajtownMap(noeud.id,"img/"+urlimg);
				ajtownMap(noeud.id,"img/IpsosDell.gif");
			}
		}
	}
}

//--> Sauvegarde de l'url consulté ds la div correspondante
function ajtownMap(town,img){
	if(town != ""){
		//--> Div de la ville 
		/*var divtown = document.createElement("div");
		divtown.setAttribute("class",town);
		//--<
		//--> Lien ville
		var urltown = document.createElement("a");
		urltown.setAttribute("href","javascript:showtown('" + town + "')");
		//--<
		//--> Img force
		var imgtown = document.createElement("img");
		imgtown.setAttribute("src", img + ".gif");
		imgtown.setAttribute("border","0");
		//--< Img force
		//--> Imbrigation des elem
		urltown.appendChild(imgtown);
		divtown.appendChild(urltown);
		//--< Imbrigation des elem
		document.getElementById("Map").appendChild(divtown);*/
		var subtown = town.substr(3,town.length);
		var html = document.getElementById("Map").innerHTML;
		html += "<div class=\""+subtown+"\"><a href=\"#anc\" onClick=\"javascript:showtown('" + town + "')\">";
		html += "<img src=\""+img+"\" border=\"0\"></a></div>";
		//alert (html);
		document.getElementById("Map").innerHTML = html;
	}
}
//--<
//--> Affiche uniquement la ville en param
function showtown(town){
	//alltown();
	if(document.getElementById("root").firstChild){
		var i = 0;
		var j = 0;
		
		while(document.getElementById("root").childNodes[j]){
			j +=1;
		}
		//alert (j);
		
		for (i=0; i <= j-1 ; i++) {
			var noeud=document.getElementById("root").childNodes[i];
			//alert (noeud.id+"-"+i);
			if (noeud.id){
				if (town == noeud.id){ 
					document.getElementById(noeud.id).style.display="block"
					//document.getElementById("root").removeChild(noeud);
					//i = i - 1;
					//j = j - 1;
				}else{
				 	document.getElementById(noeud.id).style.display="none"
				}
			}
		}		
	}
}
//--<
//--> Affiche uniquement la ville en param
function hidetown(town){
	//alltown();
	if(document.getElementById("root").firstChild){
		var i = 0;
		var j = 0;
		
		while(document.getElementById("root").childNodes[j]){
			j +=1;
		}
		//alert (j);
		
		for (i=0; i <= j-1 ; i++) {
			var noeud=document.getElementById("root").childNodes[i];
			//alert (noeud.id+"-"+i);
			if (noeud.id){
				if (town != noeud.id){ 
					document.getElementById(noeud.id).style.display="none"
					//document.getElementById("root").removeChild(noeud);
					//i = i - 1;
					//j = j - 1;
				}
			}
		}		
	}
}
//--<

//--> Reload de la page = Affiche tt les villes
function alltown(){
	window.location.reload();
}
//--<
// End JavaScript Document