//document.write("<sc"+"ript type='text/javascript' src='http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6&mkt=fr-fr'><"+"/sc"+"ript>");

// Recup variables
var a_adresse="";
var a_cp="";
var a_ville="";
var a_pays="";

var _arrivee="";

var tmp = window.location.search.substring(1).split("&");
var tabvaleur;
for (var i=0; i<tmp.length; i++) 
{
	tabvaleur = tmp[i].split("=");
	if (tabvaleur[1]!="") 
	{
		if (tabvaleur[0]=="a_adresse") { _arrivee =  tabvaleur[1]; a_adresse = tabvaleur[1]; }
		if (tabvaleur[0]=="a_cp") { _arrivee +=  ", " + tabvaleur[1]; a_cp = tabvaleur[1]; }
		if (tabvaleur[0]=="a_ville") { _arrivee +=  ", " + tabvaleur[1]; a_ville = tabvaleur[1]; }
		if (tabvaleur[0]=="a_pays") { _arrivee +=  ", " + tabvaleur[1]; a_pays = tabvaleur[1]; }
	}
}
//alert(_depart);
		
//-----------------------------------

         var map = null;
		 var CarteFrance;
		 
         // Initial map view
         //var SeattleEastside = new VELatLong(47.65, -122.24, 0, VEAltitudeMode.Default);

         function GetMap()
         {
            map = new VEMap('mymap');
			map.LoadMap(CarteFrance, 8);
			map.AttachEvent('onmodenotavailable', No3DInstalled);
			map.SetZoomLevel('5');
			map.ShowMiniMap(10, 210);
			map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
			
			
			if (_arrivee!="") { TrouvePlan2(); }
			if(a_pays=="") { document.formcarte.a_pays[10].selected = "selected"; }
			traductionfr();
			
			//map.AttachEvent("onclick", ShapeLayerAlert);
         }
		
		function traductionfr() 
		{
			
			document.getElementById("Compass").title = "Deplacer";	

			document.getElementById("MSVE_navAction_container").style.width = "465px";	
			document.getElementById("MSVE_navAction_container").className = "MSVE_Dashboard_V6 MSVE_OrthoView";	
			
			
			document.getElementById("MSVE_navAction_tinyZoomBar_plus").title = "Zoomer +";	
			document.getElementById("MSVE_navAction_tinyZoomBar_minus").title = "Zoomer -";	
			
			
			document.getElementById("MSVE_navAction_FlatlandMapMode").title = "Voir la carte en mode 2D";	
			document.getElementById("MSVE_navAction_View3DMapMode").title = "Voir la carte en mode 3D";
			
			document.getElementById("MSVE_navAction_ObliqueMapView").style.width = "80px";	
			document.getElementById("MSVE_navAction_ObliqueMapView").innerHTML = "Oeil d'oiseau";	
			document.getElementById("MSVE_navAction_ObliqueMapView").title = "Oeil d'oiseau";	
			
			document.getElementById("MSVE_navAction_RoadMapStyle").innerHTML = "Route";	
			document.getElementById("MSVE_navAction_RoadMapStyle").title = "Route";	
			
			document.getElementById("MSVE_navAction_AerialMapStyle").style.width = "80px";	
			document.getElementById("MSVE_navAction_AerialMapStyle").innerHTML = "Vue a&#233;rienne";	
			document.getElementById("MSVE_navAction_AerialMapStyle").title = "Vue aerienne";
			
			document.getElementById("MSVE_navAction_HybridMapStyle").style.width = "80px";	
			document.getElementById("MSVE_navAction_HybridMapStyle").innerHTML = "Vue hybride";	
			document.getElementById("MSVE_navAction_HybridMapStyle").title = "Vue hybride";	
			
			document.getElementById("MSVE_navAction_toggleGlyphWrapper").title = "Cacher la barre de controle";	

		}
		
		function No3DInstalled ()
		{
			alert('pour afficher les cartes en mode 3D, '+
			  'vous devez installer Virtual Earth 3D sur votre ordinateur.' +
			  '\npour installer le logiciel, visitez : ' +
			  'http://go.microsoft.com/fwlink/?LinkId=72623.');
		}
		
		function ShapeLayerAlert(e)
         {
            if(e.elementID != null)
            {
               shape = map.GetShapeByID(e.elementID);
               layer = shape.GetShapeLayer();
               alert("Shape ID " + shape.GetID() + "\nbelongs to shape layer '" + layer.GetTitle() + "'.");
            }
         }
		
		function TrouvePlan2()
		{
			var locations;
			locations = new Array(_arrivee, _arrivee);
			
			if (a_adresse!="") a_adresse = decodeURI(a_adresse.replace(/\+/g," "));
			if (a_cp!="") a_cp = decodeURI(a_cp.replace(/\+/g," "));
			if (a_ville!="") a_ville = decodeURI(a_ville.replace(/\+/g," "));
			if (a_pays!="") a_pays = decodeURI(a_pays.replace(/\+/g," "));
			
			var options = new VERouteOptions;
			options.DrawRoute      = true;
			options.SetBestMapView = true;
			options.ShowDisambiguation = true;
			options.UseMWS   = false;
			options.RouteCallback  = TrouverPushpin;


			map.GetDirections(locations, options);
			//map.SetZoomLevel('8');

			/*
			// Ajout pushpin
				var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());          
				shape.SetTitle('Arriv&eacute;e');          
				shape.SetDescription(a_adresse +" "+ a_cp +" "+ a_ville.toUpperCase() + " (" + a_pays.toUpperCase() + ")");          
				//pinid++;          
				map.AddShape(shape);      
			// FIN Ajout pushpin
			*/
			
			document.formcarte.a_adresse.value = a_adresse;
			document.formcarte.a_cp.value = a_cp;
			document.formcarte.a_ville.value = a_ville.toUpperCase();
			for(i=0; i<document.formcarte.a_pays.length; i++) 
			{ 
				if(document.formcarte.a_pays[i].value==a_pays) { document.formcarte.a_pays[i].selected = "selected";  }
			}
			
		}
		
		function TrouverPushpin(route)
		{
			
            var shape = map.GetShapeByID("msftve_1001_200000_10000");
			shape.SetTitle("Votre r&eacute;sultat :");
			shape.SetDescription(a_adresse + "<br />" + a_cp + " " + a_ville + "<br />" + a_pays);
			//alert("Title: " + shape.GetTitle() );
			
			//var layer = map.GetShapeLayerByIndex(1);
            //var count = layer.GetShapeCount();
			//layer.SetTitle("test titre");
			//layer.SetDescription("test description");
            /*
			alert("Title: " + layer.GetTitle() + "\nIndex: " + 
               1 + "\nDescription: " + layer.GetDescription() + 
               "\nShape Count: " + count);
			*/
			/*
			var etapes = route.RouteLegs;
			for(var i = 0; i < etapes.length; i++)
			{
				
			

				etape = etapes[i];
				for(var j = 0; j < etape.Itinerary.Items.length; j++)
				{
					turn = etape.Itinerary.Items[j];
					//turn.Text = "toto";
					etape.EndLocation = _arrivee;
					//alert(etape.EndLocation);
				}
			}

			
			// Ajout pushpin
				var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());          
				shape.SetTitle('Arriv&eacute;e');          
				shape.SetDescription(a_adresse +" "+ a_cp +" "+ a_ville.toUpperCase() + " (" + a_pays.toUpperCase() + ")");          
				//pinid++;          
				map.AddShape(shape);      
			// FIN Ajout pushpin

*/
/*
			var elements = document.getElementsByTagName("a");
			for(var a=0; a<elements.length; a++)
			{
				//alert(elements[a].id);
				if(elements[a].id=="msftve_1001_200001_10001") 
				{
					elements[a].getElementsByTagName("div")[0].onmouseover = elements[a].getElementsByTagName("div")[0].onmouseover+"changePushpinContenu();";
					alert(elements[a].getElementsByTagName("div")[0].onmouseover);
				}
			}
			*/
		}
		
		function changePushpinContenu()
		{
			alert("ok");
			var ero = document.getElementsByTagName("div");
			
			for(var i=0; i<ero.length; i++)
			{
				if(ero[i].className.indexOf("VE_Pushpin_Popup_Title")!=-1) { elements[i].innerHTML = "Votre r&eacute;sultat :"; }
				if(ero[i].className.indexOf("VE_Pushpin_Popup_Body")!=-1) { elements[i].innerHTML = a_adresse + "<br />" + a_cp + " " + a_ville + "<br />" + a_pays; }
			}
		}
		
		function TrouvePlan()      
		{
			try         
			{            
				//map.Find(null, _arrivee, null, null, 0, 10, true, true, true, true, addpushpin);
				map.Find(null, _arrivee, null, null, null, null, null, null, null, null, addpushpin);
				
				if (a_adresse!="") a_adresse = decodeURI(a_adresse.replace(/\+/g," "));
				if (a_cp!="") a_cp = decodeURI(a_cp.replace(/\+/g," "));
				if (a_ville!="") a_ville = decodeURI(a_ville.replace(/\+/g," "));
				if (a_pays!="") a_pays = decodeURI(a_pays.replace(/\+/g," "));
				
				document.formcarte.a_adresse.value = a_adresse;
				document.formcarte.a_cp.value = a_cp;
				document.formcarte.a_ville.value = a_ville.toUpperCase();
				for(i=0; i<document.formcarte.a_pays.length; i++) 
				{ 
					if(document.formcarte.a_pays[i].value==a_pays) { document.formcarte.a_pays[i].selected = "selected";  }
				}
				
			}         
			catch(e)         
			{            
				alert(e.message);         
			}      
		}
        
      	function addpushpin(layer, resultsArray, places, hasMore, veErrorMessage)      
		{          
			var temoin = "layer:\n"+ layer +"\n\nresultsArray:\n"+ resultsArray +"\n\nplaces:\n"+ places +"\n\nhasMore:\n"+ hasMore +"\n\nveErrorMessage:\n"+ veErrorMessage
			alert(temoin);
			
				var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());          
				shape.SetTitle('Arriv&eacute;e');          
				shape.SetDescription(a_adresse +" "+ a_cp +" "+ a_ville.toUpperCase() + " (" + a_pays.toUpperCase() + ")");          
				//pinid++;          
				map.AddShape(shape);      
            
			
			if(hasMore)
            {
            }
            else
            {
				//alert("Pas de r&eacute;sultat !");
			}
		}

setTimeout("CarteFrance = new VELatLong(46.316584181822186, 2.636718749999995, 0, VEAltitudeMode.Default);", 1000);
setTimeout("GetMap();", 1500);

