var sent = "on";
var vestiging = "";

function addSlashes(string) {
  return string.replace("'", "").replace("\"", "");
}

function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("googleMaps"));
    var point = new GLatLng(51.562932, 4.617562);
    
    map.setCenter(point, 13);
    var marker = new GMarker(point);
    map.addOverlay(marker);
    
    marker.openInfoWindowHtml("<span style=\"color: #666666; font-family: arial, sans-serif; font-size: 11px;\">Gardisette Textiles B.V.<br />Dukaatstraat 15<br />4870 AD Etten-Leur</span>");
    
    geocoder = new GClientGeocoder();
    gdir = new GDirections(map, document.getElementById("directions"));
    
    GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml("<span style=\"color: #666666; font-family: arial, sans-serif; font-size: 11px;\">Gardisette Textiles B.V.<br />Dukaatstraat 15<br />4870 AD Etten-Leur</span>");
    });
  }
}

function initializeGeneral() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("googleMaps"));
    var point = new GLatLng(51.5, 5);
    
    map.setCenter(point, 6);
    
    geocoder = new GClientGeocoder();
    gdir = new GDirections(map, document.getElementById("directions"));
  }
  return map;
}

function planRoute(lang, printLabel, type) {
  routeData = document.getElementById("routeForm");
  
  startAddress = routeData.frmAddress.value;
  startCity = routeData.frmCity.value;
  startCountry = routeData.frmCountry.value;
  
  if (GBrowserIsCompatible()) {
    if(sent == "on"){ 
      var map = new GMap2(document.getElementById("googleMaps"));
      directionsPanel = document.getElementById("googleMapsDirections");
      directions = new GDirections(map, directionsPanel);

      directions.load("from: " + startAddress + ", " + startCity + ", " + startCountry + " to: Dukaatstraat 15, Etten-Leur, Nederland");
      sent = "off";
      map.zoomOut();
    }
    else{
      directions.load("from: " + startAddress + ", " + startCity + ", " + startCountry + " to: Dukaatstraat 15, Etten-Leur, Nederland");
    }
  }
  
  //printButton = document.getElementById("googleMapsPrint");
  //printButton.style.display = "block";
  //printButton.innerHTML = "<input type=\"button\" class=\"googleMapsButton\" value=\"" + printLabel + "\" onclick=\"window.open('/gardisette/route.php?&lang=" + lang + "&fromaddress=" + addSlashes(startAddress + ", " + startCity + ", " + startCountry) + "&toaddress=Dukaatstraat+15%2C+Etten-Leur%2C+Nederland');\" />";
}

function planDealerRoute(fromAddress, toAddress, lang, printLabel, encFromAddress, encToAddress) {
  if (GBrowserIsCompatible()) {
    if(sent == "on"){ 
      var map = new GMap2(document.getElementById("googleMaps"));
      directionsPanel = document.getElementById("googleMapsDirections");
      directions = new GDirections(map, directionsPanel);

      directions.load("from: " + fromAddress + " to: " + toAddress);
      sent = "off";
      map.zoomOut();
    }
    else{
      directions.load("from: " + fromAddress + " to: " + toAddress);
    }
  }
  
  //printButton = document.getElementById("googleMapsPrint");
  //printButton.style.display = "block";
  //printButton.innerHTML = "<input type=\"button\" class=\"googleMapsButton\" value=\"" + printLabel + "\" onclick=\"window.open('/gardisette/route.php?&lang=" + lang + "&fromaddress=" + encFromAddress + "&toaddress=" + encToAddress + "');\" />";
}
