var map = null;
         var nord = new Array();
	var est = new Array();
         var denum = new Array();
denum[0]="ARPIEM - Servicii de Aviatie";	 est[0]="26.09324812";	 nord[0]="44.57229531";

 //         var id = "<?php echo $id; ?>";
    
var map = null;
 			var plecare = ""; 
			var lat = 0;
			var lon = 0;
			var click = 0;
			var distanta = 0;
			
						
			function mouse ()
		{
if (click == 1) {
			   map.AttachEvent("onclick", PixelClickp);
			}
		}

      function GetInfo2()
         {  
// var t=setTimeout("GetInfo();",1000);
//var z=setTimeout("alert(GetInfo())",1000);  
 }



 function Deleteshape()
      {
         if(shape != null)
         {
            map.DeleteShape(shape);
            shape = null;
         }
      }

  function GetMapn()
         {
         click = 0;  
         var harta  = new String(GetInfo());
        
         var centrul = new String(harta.split("#")[0]);
         var zoomul = new Number(harta.split("#")[1]);
         var tipul = new String(harta.split("#")[2]);
         var nord_c = new Number(centrul.split (",")[0]);
         var est_c = new Number(centrul.split (" ")[1]);
             map = new VEMap('myMap');
map.SetDashboardSize(VEDashboardSize.Small);
if (tipul == 'r') {
             map.LoadMap(new VELatLong(nord_c, est_c), zoomul , 'r' ,false);
}
if (tipul == 'h') {
             map.LoadMap(new VELatLong(nord_c, est_c), zoomul , 'h' ,false);
}
   for (w=0; w<1; w++)          
      {// var icon ="<img src='calugareni.gif'>";
         var icoana = new VEShape(VEShapeType.Pushpin, [new VELatLong(nord[w], est[w])]);
 
         //Set the icon
         icoana.SetCustomIcon("<img src='test.png'>");
         
         //Set the info box
         map.ClearInfoBoxStyles();
         icoana.SetTitle("<center><a href='http://www.arpiem.ro/' title='Site ' target='_blank'>ARPIEM - Servicii de aviatie</a></center>");
//         icoana.SetDescription("<a href='http://www.gpsmaps.ro/test/index.php?id="+w+"' title='Satellite Zoom' target='_blank'>Satellite Zoom");
         
         //Add the shape the the map
         map.AddShape(icoana);
		}             
 }
      
function Marcare ()
{
var harta  = new String(GetInfo());
var tipul = new String(harta.split("#")[2]);
if (tipul != 'b') {
             GetMapp();
	}
else {
             alert("Va rugam sa selectati modul de vizualizare Road sau Aerial!");

	}
}

         
         function GetMapp()
         {
         var harta  = new String(GetInfo());
         var centrul = new String(harta.split("#")[0]);
         var zoomul = new Number(harta.split("#")[1]);
         var tipul = new String(harta.split("#")[2]);
         var nord_c = new Number(centrul.split (",")[0]);
         var est_c = new Number(centrul.split (" ")[1]);
             map = new VEMap('myMap');
map.SetDashboardSize(VEDashboardSize.Small);
if (tipul == 'r') {
             map.LoadMap(new VELatLong(nord_c, est_c), zoomul , 'r' ,false);
}
if (tipul == 'h') {
             map.LoadMap(new VELatLong(nord_c, est_c), zoomul , 'h' ,false);
}
             for (w=0; w<1; w++)          
      {
         var icoana = new VEShape(VEShapeType.Pushpin, [new VELatLong(nord[w], est[w])]);
 
         //Set the icon
         icoana.SetCustomIcon("<img src='test.png'>");
         
         //Set the info box
         map.ClearInfoBoxStyles();
         icoana.SetTitle("<center><a href='http://www.arpiem.ro/'  title='Site ' target='_blank'>ARPIEM - Servicii de aviatie</a></center>");
//         icoana.SetDescription("<a href='http://www.gpsmaps.ro/test/index.php?id="+w+"' title='Satellite Zoom' target='_blank'>Satellite Zoom");
         
         //Add the shape the the map
         map.AddShape(icoana);
         
		} 
           click = 1;
           mouse();

                      }
      
      function GetInfo()
         {  
             var caract = map.GetCenter() +"#"+map.GetZoomLevel()+"#"+ map.GetMapStyle();
//alert (caract);
         return caract;

         }
      
      
           function PixelClickp(e)
         {
            var x = e.mapX;
            var y = e.mapY;
            pixel = new VEPixel(x, y);
            var LL = map.PixelToLatLong(pixel);
//            info.innerHTML = "Coordonatele sunt:" + LL;
             var plec=new String(LL);
            
            var nord_p = new Number(plec.split (",")[0]);
             var est_p = new Number(plec.split (" ")[1]);
//            alert(est);
if (click == 1) 
{
            Pushpinp (nord_p, est_p)
  }                       

         }    

function Pushpinp (nord, est)
          {
   map.DeleteAllShapes();      
 GetMapn();    
var shape = new VEShape(VEShapeType.Pushpin, [new VELatLong(nord, est)]);
//          shape.SetTitle('Plecare');
//          shape.SetDescription('This is shape number '+pinid);
//          pinid++;
          map.AddShape(shape);  
lat = nord;
lon = est;         
		}             


function distante ()
{
var distan = Number(999);
//alert(distan);
  for (w=0; w<1; w++)          
      {
      
var x = 69.1*(nord[w] - lat);
x= x.toFixed(4);
x=x*x;
x= x.toFixed(4);
//alert (x);
var y = 69.1*(est[w] - lon)*Math.cos(lat/57.3);
y= y.toFixed(4);
y=y*y;
y= y.toFixed(4);
//alert(y);
var sum= Number (x) + Number (y);
var suma = Number (sum);
//alert('suma este'+suma);
var d = Math.sqrt(suma);
d= Number (d);
d= d.toFixed(6);
d= Number (d);
//alert('d este '+d);	         
if (distan > d)
		{
lat2 = nord[w];
lon2= est[w];
distan = d;
distan = Number (distan);
		}
//alert('distanta este '+distan);		
	}
}


function test()
{
distante ();
GetMapr(lat, lon, lat2, lon2);
     
}


function GetMapr(n, e, s, v)
      {
    	   var harta  = new String(GetInfo());
         var tipul = new String(harta.split("#")[2]);
//alert(tipul);
map = new VEMap('myMap');
map.SetDashboardSize(VEDashboardSize.Small);
if (tipul == 'r') {
             map.LoadMap(new VELatLong(44.42716, 26.10437), 12 ,'r' ,false);
}
else if (tipul == 'h') {
             map.LoadMap(new VELatLong(44.42716, 26.10437), 12 ,'h' ,false);
}
else {
   alert("Va rugam sa selectati modul de vizualizare Road sau Aerial!");
}

      var options = new VERouteOptions();
         options.RouteCallback = onGotRoute;
         options.RouteOptimize = VERouteOptimize.MinimizeDistance;
//        options.DistanceUnit = VERouteDistanceUnit.Kilometer;
        map.GetDirections([new VELatLong(n, e), new VELatLong(s, v)], 
                               options);
click = 0;             
         }

         function onGotRoute(route)
         {
           // Unroll route
           var legs     = route.RouteLegs;
           route.Distance = route.Distance*1.609;
           var turns    = "Distanta totala: " + route.Distance.toFixed(1) + " Km\n";
           var numTurns = -1;
           var leg      = "null";

           // Get intermediate legs
            for(var i = 0; i < legs.length; i++)
            {
               // Get this leg so we don't have to derefernce multiple times
               leg = legs[i];  // Leg is a VERouteLeg object
                  
               // Unroll each intermediate leg
               var turn = null;  // The itinerary leg
                  
               for(var j = 0; j < leg.Itinerary.Items.length; j ++)
               {
                  turn = leg.Itinerary.Items[j];  // turn is a VERouteItineraryItem object
                  numTurns++;
                  turn.Distance=turn.Distance*1.609;
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Arrive/,"Sosire");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/left/,"la stanga");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/right/,"la dreapta");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/LEFT/,"la stanga");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/RIGHT/,"la dreapta");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/STRAIGHT/,"direct");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Entering/,"Intrare");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Local road/,"drumul local");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/(South)/,"Sud");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/(North)/,"Nord");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/(West)/,"Vest");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/(East)/,"Est");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/de pe   pe/,"de pe");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Turn/,"Schimba directia");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/turn/,"schimba directia");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/ and /," si ");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Keep straight onto/,"Mergi inainte pe");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/keep straight onto/,"mergi inainte pe");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/onto/,"pe");
                  txt_aux=turn.Text;
		  turn.Text=txt_aux.replace(/Enter roundabout/,"Intra in sensul giratoriu");
                  txt_aux=turn.Text;
		  turn.Text=txt_aux.replace(/Exit roundabout/,"Paraseste sensul giratoriu");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/At roundabout/,"La sensul giratoriu");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/at roundabout/,"la sensul giratoriu");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/immediately/,"imediat");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/then/,"apoi");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/to stay on/,"pentru a ramane pe");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Road name changes to/,"Numele strazii se schimba in");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Bear/,"Vireaza");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/bear/,"vireaza");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Merge/,"Continua");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/merge/,"continua");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Take ramp/,"Mergi pe rampa");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/take ramp/,"mergi pe rampa");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/take 1st exit/,"alege prima iesire");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Take 1st exit/,"Alege prima iesire");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/take 2nd exit/,"alege a doua iesire");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Take 2nd exit/,"Alege a doua iesire");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/take 3rd exit/,"alege a treia iesire");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Take 3rd exit/,"Alege a treia iesire");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/take 4th exit/,"alege a patra iesire");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Take 4th exit/,"Alege a patra iesire");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/take 5th exit/,"alege a cincea iesire");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Take 5th exit/,"Alege a cincea iesire");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/ ramp /," rampa ");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Ramp /,"Rampa ");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Depart/,"Porneste de pe");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/depart/,"porneste de pe");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/toward/,"spre");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/ for /," pentru ");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/roundabouts/,"sensuri giratorii");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Keep/,"Continua");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/keep/,"continua");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Pass through/,"Treci de");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/pass through/,"treci de");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Take/,"Mergi pe");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/take/,"mergi pe");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/back on/,"inapoi pe");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/Make a U-/,"In forma de U, ");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/make a U-/,"in forma de U, ");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/ at /," spre ");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/ straight /," direct ");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/At exit/,"La iesirea ");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/at exit/,"la iesirea ");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/left onto/,"la stanga pe");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/left right/,"la dreapta pe");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/ on /," pe ");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/ the la dreapta/," partea dreapta");
                  txt_aux=turn.Text;
                  turn.Text=txt_aux.replace(/ the la stanga/," partea stanga");
                  txt_aux=turn.Text;
                  turns += numTurns + ".\t" + turn.Text + " (" + turn.Distance.toFixed(1) + " Km)\n";
                  
               }
            }
//			alert(turns);
document.getElementById('text_ruta_auto').value=turns;

   for (w=0; w<1; w++)          
      {
         var icoana = new VEShape(VEShapeType.Pushpin, [new VELatLong(nord[w], est[w])]);
 
         //Set the icon
         icoana.SetCustomIcon("<img src='test.png'>");
         
         //Set the info box
         map.ClearInfoBoxStyles();
         icoana.SetTitle("<center><a href='http://www.arpiem.ro/' title='Site ' target='_blank'>ARPIEM - Servicii de aviatie</a></center>");
//         icoana.SetDescription("<a href='http://www.gpsmaps.ro/test/index.php?id="+w+"' title='Satellite Zoom' target='_blank'>Satellite Zoom");
         
         //Add the shape the the map
         map.AddShape(icoana);
		}             
 }
  
         
         function GetMap()
         {
            map = new VEMap('myMap');
map.SetDashboardSize(VEDashboardSize.Small);
             map.LoadMap(new VELatLong(44.44162, 26.10351), 10 ,'r' ,false);
   for (w=0; w<1; w++)          
      {// var icon ="<img src='calugareni.gif'>";
         var icoana = new VEShape(VEShapeType.Pushpin, [new VELatLong(nord[w], est[w])]);
 
         //Set the icon
         icoana.SetCustomIcon("<img src='test.png'>");
         
         //Set the info box
         map.ClearInfoBoxStyles();
         icoana.SetTitle("<center><a href='http://www.arpiem.ro/' title='Site ' target='_blank'>ARPIEM - Servicii de aviatie </a></center>");
//         icoana.SetDescription("<a href='http://www.gpsmaps.ro/test/index.php?id="+w+"' title='Satellite Zoom' target='_blank'>Satellite Zoom");
         
         //Add the shape the the map
         map.AddShape(icoana);
         
		}  
map.AttachEvent("ondoubleclick", GetInfo2); 
map.AttachEvent("onmousewheel", GetInfo2);         
}

