
function poistaMerkit(){
map.clearOverlays();
}

// This function picks up the click and opens the corresponding info window
      function myclick(i) {
        var center = marker[i].getPoint();
        map.setCenter(center,15);
        markerB[i].openInfoWindowHtml(htmls[i]);
        document.getElementById("tiedot").innerHTML = sishtmls[i];
      }

// functions that open the directions forms
      function tohere(i) {
        markerB[i].openInfoWindowHtml(to_htmls[i]);
      }
      function fromhere(i) {
        markerB[i].openInfoWindowHtml(from_htmls[i]);
      }


function sovita(tieto) {
bounds = new GLatLngBounds();
for (var i = 0; i < aidt.length; i++) {
 if (''+ aidt[i] == ''+tieto){
    n=1;
    bounds.extend(markerB[i].getPoint());
  } // if ...
 } // for i...

fit();
} // function(...



   function getDirections() {
        saddr = document.getElementById("saddr").value
        daddr = document.getElementById("daddr").value
        gdir.load("from: "+saddr+" to: "+daddr,{"getPolyline": true});
		
        document.getElementById('popUpDir').style.display = 'block'
      }


function skaalaaIkonit(){
  var zoomlev= map.getZoom();
  if (zoomlev>6 && pienikuv==1) {
  pienikuv =0;
  map.clearOverlays();

  for (i=0;i<markerB.length;i++){
     try {
       map.addOverlay(markerB[i]);
     }
     catch(e){}
   }
  }
  if (zoomlev<=6) {
  pienikuv =1;
  map.clearOverlays();
  }
}

///fit the markers in viewport

function fit(){
if (markerB.length > 0 || !bounds.isEmpty() ){
  var center = bounds.getCenter();
  map.closeInfoWindow();
  if(n>=0){
   var zoomi=map.getBoundsZoomLevel(bounds);
   if (zoomi>12) zoomi=12;
   map.setZoom(zoomi);
  }
  map.setCenter(center);
 } // if ...
 else {
   location.reload(true);
 }
}

