var map = null;
var locations = null;
var pixel = null;
var clickEvent = null;
var LL = null;
var pinid = 0;
var mapposS = 55.1;
var mapposD = 14.1;
var mapzom = 4;

function GetMap()
{
   map = new VEMap('myMap');
   map.SetDashboardSize(VEDashboardSize.Small);
   map.LoadMap();
   map.LoadMap(new VELatLong(mapposS, mapposD), mapzom, 'road', false);
   map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
   
   map.AttachEvent("onclick", PixelClick);
}

function ShowMap()
{
   map = new VEMap('myMap');
   map.SetDashboardSize(VEDashboardSize.Small);
   map.LoadMap();
   map.LoadMap(new VELatLong(mapposS, mapposD), mapzom, 'road', false);
   map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
}

function PixelClick(e)
{
   var x = e.mapX;
   var y = e.mapY;
   pixel = new VEPixel(x, y);
   LL = map.PixelToLatLong(pixel);
 
   if(document.getElementById('gpsNs')){ 
     stringLL = LL.toString();
     arrLL = stringLL.split(', ');
  
     var gpsNs = Math.floor(arrLL[0]);
     var gpsNmNonRound = (arrLL[0] - gpsNs) * 60;
     var gpsNm = Math.floor(gpsNmNonRound);
     var gpsNv = (gpsNmNonRound - gpsNm) * 60;
      
     var gpsEs = Math.floor(arrLL[1]);
     var gpsEmNonRound = (arrLL[1] - gpsEs) * 60;
     var gpsEm = Math.floor(gpsEmNonRound);
     var gpsEv = (gpsEmNonRound - gpsEm) * 60;
     
     document.getElementById('gpsNs').value = gpsNs;
     document.getElementById('gpsNm').value = gpsNm;
     document.getElementById('gpsNv').value = gpsNv;
     
     document.getElementById('gpsEs').value = gpsEs;
     document.getElementById('gpsEm').value = gpsEm;
     document.getElementById('gpsEv').value = gpsEv;
   } else {
     alert(LL);
   }
   
   AddPushpin();

}

function AddPushpin(gpsN, gpsE){
  if(map == null){
    setTimeout("AddPushpin('" + gpsN + "', '" + gpsE + "')", 300);
  } else {
    //var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(LL));
    //var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(30.67, 44.82));
    DeleteAllShape();
    if((gpsN != 0) && (isNaN(gpsN) == false) && (gpsE != 0) && (isNaN(gpsE) == false)){
      var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(gpsN, gpsE));
    } else {
      var shape = new VEShape(VEShapeType.Pushpin, LL);
    }
//    shape.SetTitle('My pushpin');
//    shape.SetDescription('This is shape number '+pinid);
    pinid++;
    map.AddShape(shape);
  }
}

function DeleteAllShape()
{
  map.DeleteAllShapes();
}

   
function FindLoc()
{
   try
   {
      map.Find(null, document.getElementById('txtWhere').value);
   }
   catch(e)
   {
      alert(e.message);
   }
}

// Nase mapy

  






