function Pharmacies(gmap, srvURL, imgURL) {
  this.PHARMACY_YELLOW_THRESHOLD = 30; //minutes
  this.PHARMACY_CHANGES_MINUTES_THRESHOLD = 10; //minutes
  this.PHARMACY_OPENS_HOURS_THRESHOLD = 60; //minutes
  this.PHARMACY_HOURS_ROUNDING_THRESHOLD = 15; //minutes
  this.PHARMACY_UPDATE_INTERVAL = 5*60; //seconds

  this.map = gmap;
  this.serverURL = srvURL;
  this.imageURL = imgURL;
  
  this.coa_poly = new GPolygon(p_latlng_array);
  
  this.pharmaciesOnCall = {};
  this.pharmacyRequestBounds = null;
  this.pharmacyRequestDuration = null;
  this.pharmacyServerDate = null;
  this.pharmacyRequestDate = null;
  this.pharmacyUpdateTimer = null;
  this.pharmaciesVisible = false;
  this.id = Pharmacies.instanceIdx++;
  Pharmacies.instance[this.id] = this;
  
 /* this.pharmacyIcon = function(){
    var m = new GIcon();
      m.shadow = this.imageURL+'/shadow50.png';
      m.iconSize = new GSize(26, 40);
      m.shadowSize = new GSize(37, 34);
      m.iconAnchor = new GPoint(12, 39);
      m.infoWindowAnchor = new GPoint(13, 2);
      m.infoShadowAnchor = new GPoint(18, 35);
      m.image = this.imageURL+'/Scaled_Pharmacy.png';
      return m;
  }
 */
  this.setIcon = function(ic) {
    this.icon = ic;
  }
  this.parsePharmacyDate = function(dt) {
    //Format: 02-02-2009 08:00
    var i1 = dt.indexOf('-',0);
    var i2 = dt.indexOf('-',i1+1);
    var i3 = dt.indexOf(' ',i2+1);
    var i4 = dt.indexOf(':',i3+1);
    var res = new Date();
    res.setMilliseconds(0);
    res.setSeconds(0);
    res.setMinutes(dt.substring(i4+1));
    res.setHours(dt.substring(i3+1,i4));
    res.setDate(dt.substring(0,i1));
    res.setMonth(dt.substring(i1+1,i2)-1);
    res.setFullYear(dt.substring(i2+1,i3));
    return res; 
  }

  this.getPharmacyInfo = function(ph) {
    var res = '<div align="left">';
    res += '<b>'+ph.name+'</b><br />';
    res += ph.area+'<br />';
    res += ph.address+'<br />';
    res += '<b>Ανοίγει:</b> '+ph.opensAt+'<br />';
    res += '<b>Κλείνει:</b> '+ph.closesAt+'<br />';
    res += '<b>Τηλ:</b> '+ph.phone+'<br />';
    res += '<b>Εφημερία:</b> '+ph.efimeria+'<br />';
    res += '</div>';
    res += '<a href="javascript:setRoutePointFrom(\''+ph.lat+'\',\''+ph.lng+'\')">';
    res += '<img src="'+svrUrl+'/images/start_hex.png" style="border:0px; margin-right:3px;" title="Διαδρομή από" alt="Διαδρομή από" /> &nbsp;<u>Διαδρομή Από</u></a> &nbsp;&nbsp;';
    res += '<a href="javascript:setRoutePointTo(\''+ph.lat+'\',\''+ph.lng+'\')">';
    res += '<img src="'+svrUrl+'/images/stop_hex.png" style="border:0px; margin-right:3px;" title="Διαδρομή έως" alt="Διαδρομή έως" />&nbsp;<u>Διαδρομή Προς</u></a>';
    return res;
  }

  this.trueRound = function(num) {
    num = String(num);
    var t = num.indexOf('.');
    if (t>=0) num = num.substring(0,t);
    if (num.length==0) num = '0';
    return num;
  }

  this.getPharmacyTip = function(ph) {
    var txt, style;
    var local_now = new Date();
    var server_now = this.pharmacyServerDate.getTime()+(local_now.getTime()-this.pharmacyRequestDate.getTime());    
    var openTime = this.parsePharmacyDate(ph.opensAt).getTime();
    var closeTime = this.parsePharmacyDate(ph.closesAt).getTime();
    if ((openTime<=server_now)&&(server_now<closeTime)) {
      if ((closeTime-server_now<this.PHARMACY_YELLOW_THRESHOLD*60*1000)) {
        // Open but will close in a while
        txt = 'Κλείνει σε ';
        var mins = Math.round((closeTime-server_now)/(60*1000));
        if (mins<=this.PHARMACY_CHANGES_MINUTES_THRESHOLD) {
          txt += this.trueRound(mins) + ' λεπτά';
        } else {
          mins = Math.round(mins/5)*5;  
          txt += this.trueRound(mins) + ' λεπτά';
        }
        style = 'yellow50.png';
      } else {
        // Open
        txt = 'Ανοιχτό';
        style = 'green50.png';
      }
    } else {
      // Closed
      style = 'red50.png';
      var txt = 'Ανοίγει σε ';
      var mins = Math.round((openTime-server_now)/(60*1000));
      if (mins>=this.PHARMACY_OPENS_HOURS_THRESHOLD) {
        var gap = mins-Math.floor(mins/60)*60;
        var hours = (mins-gap)/60;
        if (gap>=60-this.PHARMACY_HOURS_ROUNDING_THRESHOLD) {hours++; gap -= 60;}
        txt += this.trueRound(hours);
        if (gap>=this.PHARMACY_HOURS_ROUNDING_THRESHOLD) txt += '+';
        if ((hours==1)&&(gap<this.PHARMACY_HOURS_ROUNDING_THRESHOLD)) {
          txt += ' ώρα';
        } else {
          txt += ' ώρες';
        }
      } else {
        if (mins<=this.PHARMACY_CHANGES_MINUTES_THRESHOLD) {
          txt += this.trueRound(mins) + ' λεπτά';
        } else {
          mins = Math.round(mins/5)*5;  
          txt += this.trueRound(mins) + ' λεπτά';
        }
      }
    }
    return {'style':style, 'text':txt}; 
  }

  this.addPharmacy = function(ph) {
/*    this.pharmaciesOnCall[ph.id] = ph;
    var m = new GMarker(new GLatLng(ph.lat,ph.lng),this.pharmacyIcon());
    //var m = new GMarker(new GLatLng(ph.lat,ph.lng));
    //m.bindInfoWindowHtml(getPharmacyInfo(ph));
    m.pharmacydata = ph;
    m.obj = this;
    
    markersOnMap.push({'lat':ph.lat,'lng':ph.lng,'name':ph.name});
    
    GEvent.addListener(m,'click',function(){ this.openInfoWindow(m.obj.getPharmacyInfo(this.pharmacydata)); });
    var tip = this.getPharmacyTip(ph);
    var statstyle = 'background-image: url("'+this.imageURL+'/'+tip.style+'"); color:black; padding:1px; white-space: nowrap;';
    var txt = new MarkerText(m,13,-45,statstyle,tip.text);
    this.map.addOverlay(m);
    this.map.addOverlay(txt);
    this.pharmaciesOnCall[ph.id].marker = m;
    this.pharmaciesOnCall[ph.id].markertext = txt;
    this.pharmaciesOnCall[ph.id].touched = true;*/
          this.pharmaciesOnCall[ph.id] = ph;
    var m;
    if (this.icon) {
      m = new GMarker(new GLatLng(ph.lat,ph.lng),{'icon':this.icon});
    } else {
      m = new GMarker(new GLatLng(ph.lat,ph.lng));
    }
    m.bindInfoWindowHtml(this.getPharmacyInfo(ph));
    //m.pharmacydata = ph;
    //m.obj = this;
    //GEvent.addListener(m,'click',function(){ this.openInfoWindow(m.obj.getPharmacyInfo(this.pharmacydata)); });
    markersOnMap.push({'lat':ph.lat,'lng':ph.lng,'name':ph.name});
    var tip = this.getPharmacyTip(ph);
    var statstyle = 'background-image: url("'+this.imageURL+'/'+tip.style+'"); color:black; padding:1px; white-space: nowrap;';
    var txt = new MarkerText(m,13,-45,statstyle,tip.text);
    this.map.addOverlay(m);
    this.map.addOverlay(txt);
    this.pharmaciesOnCall[ph.id].marker = m;
    this.pharmaciesOnCall[ph.id].markertext = txt;
    this.pharmaciesOnCall[ph.id].touched = true;
  }

  this.getNewPharmacies = function(bounds,dur) {
    RemoteAjax.call({
      url: this.serverURL+'/fsa.jsp',
      data: {
          "sw_lat": bounds.southwest.lat,
          "sw_lng": bounds.southwest.lng,
          "ne_lat": bounds.northeast.lat,
          "ne_lng": bounds.northeast.lng,
          "dur": dur},
      instance: this,
      success: 'getNewPharmacies1'
    });
  }

  this.getNewPharmacies1 = function(data) {
    if (data.status==0) {
      this.pharmacyServerDate = this.parsePharmacyDate(data.serverdate);
      this.pharmacyRequestDate = new Date();
      var pharmacies = data.pharmacies;
      for (var i in pharmacies) {
        var ph = pharmacies[i];
        var ph_latlng = new GLatLng(ph.lat,ph.lng);
        if (poly_contains_poi(ph_latlng,this.coa_poly)){
          if (this.pharmaciesOnCall[ph.id]===undefined) this.addPharmacy(ph);
        }
      }
    } else {
      alert('Error getting pharmacies: '+data.message);
    }
  }

  this.clearPharmacies = function() {
    for (var i in this.pharmaciesOnCall) {
      var ph = this.pharmaciesOnCall[i];
      this.map.removeOverlay(ph.marker);
      this.map.removeOverlay(ph.markertext);
    }
    this.pharmaciesOnCall = {};
    this.pharmacyRequestBounds = null;
  }

  this.togglePharmaciesOnCall = function(show,dur) {
    if (show) {
      //Load pharmacies
      var b = this.map.getBounds();
      var bounds = {'southwest':{'lat':b.getSouthWest().lat(), 'lng':b.getSouthWest().lng()}, 
                    'northeast':{'lat':b.getNorthEast().lat(), 'lng':b.getNorthEast().lng()}};
      this.pharmacyRequestDuration = dur;
      this.pharmacyRequestBounds = bounds;
      this.pharmaciesVisible = true;
      this.getNewPharmacies(bounds,dur);
      this.startPharmacyUpdateTimer();
    } else {
      //Clear pharmacies
      this.clearPharmacies();
      this.pharmaciesVisible = false;
    }
  }

  //Called when the visible area of the map is changed
  //Load new areas as needed
  this.updatePharmacies = function(dur) {
    if (this.pharmaciesVisible) {
      if (dur===undefined) dur = this.pharmacyRequestDuration;
      if (dur==null) dur = 1;
      if (dur!=this.pharmacyRequestDuration) this.clearPharmacies();
      var b = this.map.getBounds();
      var bounds = {'southwest':{'lat':b.getSouthWest().lat(), 'lng':b.getSouthWest().lng()}, 
                    'northeast':{'lat':b.getNorthEast().lat(), 'lng':b.getNorthEast().lng()}};
      var t;
      if (this.pharmacyRequestBounds!=null) {
        t = getRectangleDiff(this.pharmacyRequestBounds,bounds);
      } else {
        t = [bounds];
      }
      for (var i in t) this.getNewPharmacies(t[i],dur);
      this.pharmacyRequestBounds = bounds;
      this.pharmacyRequestDuration = dur;
      this.startPharmacyUpdateTimer();
    }
  }

  this.startPharmacyUpdateTimer = function() {
    if (this.pharmacyUpdateTimer!=null) clearTimeout(this.pharmacyUpdateTimer);
    this.pharmacyUpdateTimer = setTimeout('Pharmacies.instance['+this.id+'].updatePharmacies1();',this.PHARMACY_UPDATE_INTERVAL*1000);
  }

  this.updatePharmacies1 = function() {
    if (this.pharmaciesVisible) {
      RemoteAjax.call({
        url: this.serverURL+'/fsa.jsp',
        data: {
          "sw_lat": this.pharmacyRequestBounds.southwest.lat,
          "sw_lng": this.pharmacyRequestBounds.southwest.lng,
          "ne_lat": this.pharmacyRequestBounds.northeast.lat,
          "ne_lng": this.pharmacyRequestBounds.northeast.lng,
          "dur": this.pharmacyRequestDuration
        },
        instance: this,
        success: 'updatePharmacies2'
      });
    }
  }

  this.updatePharmacies2 = function(data) {
    this.pharmacyServerDate = this.parsePharmacyDate(data[0]);
    this.pharmacyRequestDate = new Date();
    var pharmacies = data[1];
    for (var i in this.pharmaciesOnCall) this.pharmaciesOnCall[i].touched = false;
    for (var i in data[1]) {
      var ph = data[1][i];
      if (this.pharmaciesOnCall[ph.id]===undefined) {
        //This is a new pharmacy, just add it
        this.addPharmacy(ph);
      } else {
        //We have an existing pharmacy, just update the text to be displayed
        var ph2 = this.pharmaciesOnCall[ph.id];
        ph.marker = ph2.marker;
        ph.marker.pharmacyinfo = this.getPharmacyInfo(ph);
        var tip = this.getPharmacyTip(ph);
        var statstyle = 'background-image: url("'+this.imageURL+'/'+tip.style+'"); color:black; padding:1px; white-space: nowrap;';
        var txt = new MarkerText(ph.marker,13,-45,statstyle,tip.text);
        this.map.addOverlay(txt);
        this.map.removeOverlay(ph2.markertext);
        ph.markertext = txt;
        this.pharmaciesOnCall[ph.id] = ph;
        this.pharmaciesOnCall[ph.id].touched = true;
      }
    }
    //Now clear all pharmacies that are no longer displayed, to reduce client burder
    var toremove = [];
    for (var i in this.pharmaciesOnCall) if (!this.pharmaciesOnCall[i].touched) toremove.push(i);
    for (var i in toremove) {
      var idx = toremove[i];
      this.map.removeOverlay(this.pharmaciesOnCall[idx].marker);
      this.map.removeOverlay(this.pharmaciesOnCall[idx].markertext);
      delete(this.pharmaciesOnCall[idx]);
    }
    this.startPharmacyUpdateTimer();
  }
}

Pharmacies.instanceIdx = 0;
Pharmacies.instance = {};


//*************************************************APO MARKERTEXT.JS*****************************************************************

function MarkerText(marker, dx, dy, style, text) {
  this._marker = marker;
  this._dx = dx || 0;
  this._dy = dy || 0;
  this._style = style || '';
  this._text = text || '';
}
MarkerText.prototype = new GOverlay();

MarkerText.prototype.initialize = function(map) {
  var div = document.createElement('div');
  this._div = div;
  this._map = map;
  
  this._div.innerHTML = this._text;
  this._div.setAttribute('style', this._style);
  if (this._div.style.setAttribute) this._div.style.setAttribute('cssText', this._style); //IE hack
  this._div.style.position = 'absolute';
  this._map.getPane(G_MAP_MARKER_PANE).appendChild(this._div);
}

MarkerText.prototype.remove = function() {
  this._div.parentNode.removeChild(this._div);
}

MarkerText.prototype.copy = function() {
  return new MarkerText(this._marker, this._dx, this._dy, this._style, this._text);
}

MarkerText.prototype.redraw = function(force) {
  if (!force) return;
  var pos = this._map.fromLatLngToDivPixel(this._marker.getLatLng());
  this._div.style.top = (pos.y+this._dy) + 'px';
  this._div.style.left = (pos.x+this._dx) + 'px';
}

MarkerText.prototype.element = function() {
  return this._div;
}

//******************* APO routingentryNGI.js *******************************************************************

function flashOverlay(ovl,period,times) {
  var obj = flashOverlay.ovlreg;
  if (obj!=null) {
    if (obj.timer!=null) {
      clearTimeout(obj.timer);
      obj.overlay.hide();
    }
  }
  flashOverlay.ovlreg = {'overlay':ovl, 'times':times, 'period':period, 'timer':null};
  flashOverlay.main();
}

flashOverlay.main = function() {
  var obj = flashOverlay.ovlreg;
  if (obj.times>0) {
    if (obj.overlay.isHidden()) {
      obj.overlay.show();
    } else {
      obj.overlay.hide();
    }
    obj.times--;
    obj.timer = setTimeout('flashOverlay.main();',obj.period);
  } else {
    obj.overlay.hide();
    flashOverlay.ovlreg = null;
  }
}

flashOverlay.stop = function() {
  var obj = flashRouteOverlay.ovlreg;
  obj.times = 0;
}

flashOverlay.ovlreg = null;

/**
 * 
 * @param gmap - A pointer to a google maps object (mandatory)
 * @param iconfrom, iconto - marker icons for showing points (mandatory)
 * @param infoelemid - The id of the div element where text info is to be displayed (mandatory)
 * @param pointfrom, pointto - Object (optional, may come from deserialization) 
 *     name - A textual description of the point 
 *     lat, lng -  coords 
 * @param opts - Object (optional, may come from deserialization)
 *     pedestrian==1;
 *     avoid_attiki==1
 *     avoid_aktoploikes==1
 *     avoid_tolls==1
 *     avoid_daktilios==1
 *     avoid_periferiaki==1
 *     avoid_homatodromoi==1
 * @return
 */
function RoutingEntryNGI(gmap, srvURL, imgURL, iconfrom,iconto,infoelemid,pointfrom,pointto,opts) {
  this.map = gmap;
  this.serverURL = srvURL;
  this.imageURL = imgURL;

  this.iconfrom = iconfrom;
  this.iconto = iconto;
  this.infoid = infoelemid;
  this.pointfrom = pointfrom;
  this.pointto = pointto;
  this.opts = opts;
  this.directions = null;
  this.pline = null;
  this.frommarker = null;
  this.tomarker = null;
  this.plineSegment = null;
  this.SEARCH_RESULTS_PER_PAGE = 10;

  this.id = RoutingEntryNGI.idx++;
  RoutingEntryNGI.obj[this.id] = this;

  this.showRoutingSegmentNGI = function(idx) {
    var route = this.directions;
    if((idx!=0)&&idx!=route.length-1) {
      if (idx==route.length-1) return;
      var nl = [];
      this.getStepsArray(nl,route[idx].RouteSegment.segments,0,9);
      if (this.plineSegment!=null) this.map.removeOverlay(this.plineSegment);
      this.plineSegment = new GPolyline(nl,'#00ff00',12);
      this.map.addOverlay(this.plineSegment);
      var pb = this.plineSegment.getBounds();
      if (!this.map.getBounds().containsBounds(pb)) this.map.panTo(pb.getCenter());
      flashOverlay(this.plineSegment,300,30);
    }
  }

  this.getResultsPager_Routing = function(totalcount,idx) {
    var j = idx+this.SEARCH_RESULTS_PER_PAGE;
    if (j > totalcount) j = totalcount;
    var pager = '';
    if ((idx-1>0)||(j<totalcount)) {      
      pager += '<table align="center" width="100%">';
      pager += '<tr><td align="center">';
      if (idx-1>0) {
        var prev = idx-this.SEARCH_RESULTS_PER_PAGE;
        if (prev<0) prev = 0;
        pager += '<a href="javascript:RoutingEntryNGI.showInfo('+this.id+','+prev+')">';
        pager += '<img src="'+this.imageURL+'/velaki_aristera.png" style="border:0px;" title="Προηγούμενη σελίδα" alt="Προηγούμενη σελίδα" />';
        pager += '</a>';
      } else {
        pager += '<img src="'+this.imageURL+'/velaki_aristera_gray.png" style="border:0px;" />';
      }
      pager += '</td><td align="center" width="70%">';
      pager += '<b>Βήματα:</b> '+idx+'-'+(j-1)+'/'+(totalcount-1);
      pager += '</td><td align="center">';
      if (j<totalcount) {
        pager += '<a href="javascript:RoutingEntryNGI.showInfo('+this.id+','+j+')">';
        pager += '<img src="'+this.imageURL+'/velaki_deksia.png" style="border:0px;" title="Επόμενη σελίδα" alt="Επόμενη σελίδα" />';
        pager += '</a>';
      } else {
        pager += '<img src="'+this.imageURL+'/velaki_deksia_gray.png" style="border:0px;" />';
      }
      pager += '</td></tr>';
      pager += '</table>';
    } else {
      pager += '<table align="center" width="100%">';
      pager += '<tr><td align="center">';
      pager += '<b>Βήματα:</b> '+(totalcount-1);
      pager += '</td></tr>';
      pager += '</table>';
    }
    return pager;
  }

  this.panTo = function() {
    var z = this.map.getBoundsZoomLevel(this.pline.getBounds());
    if (z!=this.map.getZoom()) this.map.setZoom(z);
    this.map.panTo(this.pline.getBounds().getCenter());
  }
  
  this.showInfo = function(idx) {
    if (idx===undefined) idx = 0;
    var st = '<br />';
    var route = this.directions;
    var m = route.length-1;
    if (m<=0) {
      st += '<div align="center">Δεν βρέθηκαν αποτελέσματα</div>';
    } else {
      var j = idx+this.SEARCH_RESULTS_PER_PAGE;
      if (j > m) j = m;
      st += '<table  border="0"><tr>';
      st += '<td>'+this.getHtml()+'&nbsp;&nbsp;<a href="javascript:removeRoute()"><img src="'+svrUrl+'/images/delete_hex.png" style="border:0px; margin-right:3px;" /></a></td>';
      st += '</tr>'
      st += '<td>Συνολική Απόσταση:&nbsp; ';
      st += route[route.length-1].RouteSegment.totalDistance+' km.</td>';
      st += '</tr></table>';            
      st += this.getResultsPager_Routing(m,idx);
      st += '<table>';
      for (var i = idx; i < j; i++) {
        var step = route[i].RouteSegment;
        st += '<tr>';
        st += '<td valign="top">'+i+'.</td>';
        st += '<td>';
        st += '<a href="javascript:RoutingEntryNGI.showRoutingSegmentNGI('+this.id+','+i+')">';
        st += step.drivingDirection
        st += '</a>';
        var d = step.distance *1000; 
        if (d > 0) st += ' ('+d+'m)';
        st += '</td>';
        st += '</tr>';
      }
      st += '</table>';
    }
    st += '<br />';
    jQuery('#'+this.infoid).empty().append(st);
  }

  this.remove = function() {
    jQuery('#'+this.infoid).empty();
    if (this.frommarker) this.map.removeOverlay(this.frommarker);
    if (this.tomarker) this.map.removeOverlay(this.tomarker);
    this.map.removeOverlay(this.pline);
  }

  this.getHtml = function() {
    var st = '<b>Από:</b> ';
    st += this.pointfrom.name;
    st += '&nbsp; <b>Προς:</b> ';
    st += this.pointto.name;
    return st;
  }

  this.getText = function() {    
    var st = 'Από: ';
    st += this.pointfrom.name;
    st += ' Προς: ';
    st += this.pointto.name;
    return st;
  }

  //map, pointfrom, pointto, pline, directions must be defined
  this.init = function() {
    var pf_latlng = new GLatLng(this.pointfrom.lat,this.pointfrom.lng);
    var pt_latlng = new GLatLng(this.pointto.lat,this.pointto.lng);

    if (this.iconfrom) this.frommarker = new GMarker(pf_latlng,this.iconfrom);
    if (this.iconto) this.tomarker = new GMarker(pt_latlng,this.iconto);

    this.map.addOverlay(this.pline);
    if (this.frommarker) this.map.addOverlay(this.frommarker);
    if (this.tomarker) this.map.addOverlay(this.tomarker);
    this.panTo();
    this.showInfo(1);
  }

  this.serialize = function() {
    var st = {};
    st.type = 'routingNGIv1';
    st.pointfrom = this.pointfrom;
    st.pointto = this.pointto;
    st.options = this.opts;
    return JSON.stringify(st);
  }

  this.deserialize = function(data) {
    var st = JSON.parse(data);
    if (st.type=='routingNGIv1') {
      this.pointfrom = st.pointfrom;
      this.pointto = st.pointto;
      this.opts = st.options;
      this.getNGIRoute();
    }
  }

  //opts, pointfrom, pointto must be defined
  this.getNGIRoute = function() {
    var ped_mode = 0;
    if (this.opts.pedestrian==1) ped_mode = 1;
    var avoid_flags =0;
    if (this.opts.avoid_attiki==1) avoid_flags +=1;
    if (this.opts.avoid_aktoploikes==1) avoid_flags +=2;
    if (this.opts.avoid_tolls==1) avoid_flags +=4;
    if (this.opts.avoid_daktilios==1) avoid_flags +=8;
    if (this.opts.avoid_periferiaki==1) avoid_flags +=16;
    if (this.opts.avoid_homatodromoi==1) avoid_flags +=128;
    var resultDiv = jQuery('#'+this.infoid);
    resultDiv.empty();
    resultDiv.append('<br />');    
    resultDiv.append('<div align="center">Παρακαλώ περιμένετε...<img src="'+this.imageURL+'/loader.gif" style="border:0px;" /> </div>');

    RemoteAjax.call({
        url: this.serverURL+'/getRoute.jsp',
        data: {"avoidFlags": avoid_flags,
               "pedestrialMode":ped_mode,
               "routeSortest":0,
               "pointfrom_lng":this.pointfrom.lng,"pointfrom_lat":this.pointfrom.lat,
               "pointto_lng":this.pointto.lng,"pointto_lat":this.pointto.lat},
        instance: this,
        success: 'getNGIRoute_cont'
    });
  }

  this.getNGIRoute_cont = function(data) {
    if (data.status==0) {
      this.directions = data.results.RouteResponse.RouteSegments;
      var pl = [];
      for (i=1; i<this.directions.length-1; i++) {
        var start = 0;
        var end = 9;
        this.getStepsArray(pl,this.directions[i].RouteSegment.segments,start,end);
      }
      this.pline = new GPolyline(pl);
      this.init();
    } else {
      var st = '<hr />';
      st += '<br />';
      st += '<div align="center">';
      st += '<span style="font-color:red;">Δε βρέθηκαν αποτελέσματα</span><br />';
      st += 'Δοκιμάστε με άλλες επιλογές...<br />';
      st += '</div>';
      st += '<br />';
      jQuery('#'+this.infoid).empty().append(st);
    }
  }

  this.getStepsArray = function(pl,st,start,end) {
    while (end<st.length) { 
      var x = st.substring(start,end);
      start = end +1;
      end=start+9;
      var y = st.substring(start,end);
      start = end+1;
      end = start+9;          
      var latlng = new GLatLng(y,x);
      pl.push(latlng);
    }
  }

}

RoutingEntryNGI.showInfo = function(id,pageidx) {
  RoutingEntryNGI.obj[id].showInfo(pageidx);
}

RoutingEntryNGI.showRoutingSegmentNGI = function(id,idx) {
  RoutingEntryNGI.obj[id].showRoutingSegmentNGI(idx);
}

RoutingEntryNGI.obj = {};
RoutingEntryNGI.idx = 0;



