/*
  Javascript routines for the Website Baker module: YellowPages
  Copyright (C) 2009, Burkhard Hekers
  Contact me: bhe1(at)gmx.net

  The Javascript routines are free software. You can redistribute it and/or modify it 
  under the terms of the GNU General Public License  - version 2 or later, 
  as published by the Free Software Foundation: http://www.gnu.org/licenses/gpl.html.

  The Javascript routines are distributed in the hope that it will be useful, 
  but WITHOUT ANY WARRANTY; without even the implied warranty of 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  GNU General Public License for more details.
*/

/*

  // var gmap2 = new mod_contactlist_jsGmap("GoogleMapOfficeId");
                                               
              
              gmap2.ShowAdress('<?php echo $adr_land ?>,<?php echo $adr_street ?>, <?php echo $adr_postalcode ?>, <?php echo $adr_city ?>',
                              <?php echo GOOGLE_MAP_ZOOM_OFFICE ?>,
                              '<?php echo GOOGLE_MAP_FALLBACK_ADRESS ?>',
                              <?php echo GOOGLE_MAP_FALLBACK_ZOOM; ?>);
                              
 
  
              var gmap = new mod_contactlist_jsGmap("GoogleMapPrivateId");
         
              gmap.ShowAdress('<?php echo $adr_land ?>,<?php echo $adr_street ?>, <?php echo $adr_postalcode ?>, <?php echo $adr_city ?>',
                              <?php echo GOOGLE_MAP_ZOOM_PRIVATE ?>,
                              '<?php echo GOOGLE_MAP_FALLBACK_ADRESS ?>',
                              <?php echo GOOGLE_MAP_FALLBACK_ZOOM; ?>);

             */           


function mod_yellowpages_jstest_f($msg) 
{
  alert($msg);
}

//###############################################################
function mod_yellowpages_jsGmap
(
  div_id
)
//#
//#
//#
//#
//###############################################################
{
  Map                 = new GMap2(document.getElementById(div_id));
  geocoder            = new GClientGeocoder();
  
   DivId         = div_id;
   ZoomFaktor         = 0;
   FallBackAdress     = "Germany";
   FallbackZoomValue  = 5;
  
  alert( "Konstruktor:\nDivId: "   + DivId );
   
}
//###############################################################
mod_yellowpages_jsGmap.prototype.ShowAdress = 
function 
(
  address,
  zoom,
  AdressFallBack,
  ZoomFallback
)
//#
//#
//#
//#
//###############################################################  
{
  FallBackAdress     = AdressFallBack;
  FallbackZoomValue  = ZoomFallback;
  
  /*
  alert( "ShowAdress\nAdress: " + address            + "\n"  + 
         "ZoomValue: "            + zoom               + "\n"  +
         "FallBackAdress: "       + FallBackAdress     + "\n"  +
         "FallBackZoom: "         + FallbackZoomValue);
  */
  
  this.GmapStartRequest(address,zoom);
}

//###############################################################
mod_yellowpages_jsGmap.prototype.GmapStartRequest = 
function
(
  address,
  zoom
)
//#
//#
//#
//#
//############################################################### 
{
  if (geocoder) 
  {
    //GEvent.addListener(Map, "load", OnLoad); 
    geocoder.reset();
    //alert( "GmapStartRequest\nAdress: "  + address  + "\n"  +  "ZoomValue: "   + zoom );
    ZoomFaktor = zoom;
    // Retrieve location information
    geocoder.getLocations(address, this.GmapAddMap);
  }
} 

//###############################################################
mod_yellowpages_jsGmap.prototype.GmapAddMap = 
function
(
  response
)
//#
//#
//#
//#
//###############################################################
{
 
  if(response && response.Status.code == 200)
  { 
    alert("Adresse gefunden");
    //alert(DivId);
    Map.setMapType(G_NORMAL_MAP );
    Map.addControl(new GSmallMapControl());
    Map.addControl(new GMapTypeControl());
    // Retrieve the object
    place = response.Placemark[0];
    // Retrieve the latitude and longitude
    point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
    // Center the map on this point
    // alert("ZoomFaktor: " + ZoomFaktor);
    Map.setCenter(point, ZoomFaktor);
    // Create a marker
    marker = new GMarker(point);
    // Add the marker to map
    Map.addOverlay(marker);
    // Add address information to marker
    // marker.openInfoWindowHtml(place.address);
  }
  else
  {
   alert("huch Adresse nicht gefunden");
    // Adresse nicht gefunden -> Fallback Adresse anzeigen
    //alert(this.FallBackAdress + " - " + this.FallbackZoomValue + " - " + DivId);
    //var gmap = new mod_yellowpages_jsGmap(this.DivId);         
    //gmap.ShowAdress(this.FallBackAdress,this.FallbackZoomValue);
    //mytime = setTimeout(this.Timeout, 100); 
  }
}


mod_yellowpages_jsGmap.prototype.setDivId = function(value)
{
  this.DivId = value;
}
mod_yellowpages_jsGmap.prototype.getDivId = function()
{
  return this.DivId;
} 
