    //<![CDATA[
    
    /**
  * @file
  * Javascript functions for module geouri
  *
  * See geouri.module for more information
  * 
  */ 
    
    var geouri_map_view = null;
    /*! contains the Google Maps API map object for the node views */
    var geouri_map_edit = null;
    /*! contains the Google Maps API map object for the edit views */
    var geouri_geocoder = null;
    /*! contains the Google Maps API geocoder */    
    var geouri_longitude = new Array();
    /*! the list of longitudes of the maps to show */
    var geouri_latitude = new Array();
    /*! the list of latitudes of the maps to show */
    var geouri_latitude;
    /*! default longitude */
    var geouri_longitude;
    /*! default latitude */
    var geouri_setgeourifieldname = null;
    /*! contains the name of the field which contains the coordinates*/
    var geouri_edit_marker = null;

/**
 * Helper function to execute a function when page is loaded 
 * 
 * as we cannot use <body onload="..."> for this
 *
 * @param 
 *  function to be executed
 *
 */
function addLoadEvent(func) {
  var oldOnload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      oldOnload();
      func();
    }
  }
}

/**
 * Does the necessary work when a map is loaded for viewing
 * 
 * which is centering and showing the maps and adding a marker in the center
 *
 */
function geouri_load_view() {
  if (GBrowserIsCompatible()) {
    var not_done_all_maps = 0;
    i = 0;
    while (not_done_all_maps < 3) {
      var geouri_element = document.getElementById("geouri_map_view_" + i);
      if (geouri_element) {
        var geouri_map_view = new GMap2(geouri_element);
        if (geouri_map_view) {
          if ((typeof geouri_latitude[i] != "undefined") && (typeof geouri_longitude[i] != "undefined")) {
            geouri_map_view.addControl(new GSmallMapControl());
            geouri_map_view.setCenter(new GLatLng(geouri_latitude[i], geouri_longitude[i]), 4);
            geouri_map_view.addOverlay(new GMarker(new GLatLng(geouri_latitude[i], geouri_longitude[i])));
           }
        }
      }
      else {
        not_done_all_maps++;
      }
      i++;
      delete (geouri_element);
      delete (geouri_map_view);
    }
  }
}

/**
 * Does the necessary work when a map is loaded for editing
 * 
 * which is centering and showing the maps and adding a marker in the center
 * Additionally when the map is clicked on, the coordinates (geouri) are set to this position,
 * the same if the map is doubleclicked and centered
 *
 */
function geouri_load_edit() {
  if (GBrowserIsCompatible()) {
    geouri_map_edit = new GMap2(document.getElementById("geouri_map_edit"));
    geouri_map_edit.addControl(new GSmallMapControl());
    geouri_map_edit.setCenter(new GLatLng(geouri_latitude[0], geouri_longitude[0]), 4);
    geouri_edit_marker = new GMarker(new GLatLng(geouri_latitude[0], geouri_longitude[0]));
    geouri_map_edit.addOverlay(geouri_edit_marker);
    geouri_geocoder = new GClientGeocoder();
/*    GEvent.addListener(geouri_map_edit, "click", function(overlay, point) {
      geouri_map_edit.removeOverlay(geouri_edit_marker);
      delete(geouri_edit_marker);
      geouri_edit_marker = new GMarker(point);
      geouri_map_edit.addOverlay(geouri_edit_marker);
      // prepare the coordinates to put them into the coordinates field
      var geouri_coordinates = document.getElementsByName(geouri_setgeourifieldname)[0];
      var geouri_workstring1 = String(point);
      var geouri_workstring2 = String(geouri_workstring1.replace(/\)/g, ''));
      var geouri_workstring3 = String(geouri_workstring2.replace(/\(/g, ''));
      var geouri_workstring4 = String(geouri_workstring3.replace(/\ /g, ''));
      geouri_coordinates.value = geouri_workstring4;
    });*/
  }
}

function showAddress(address) {
  var adr = String(address);
  adr = adr.replace(/\s+/g," ").replace(/\s+$/,"").replace(/^\s+/,"");
  if (adr.length > 3) {
    if (geouri_geocoder) {
      geouri_geocoder.getLatLng(
        address,
        function(point) {
          var geouri_coordinates = document.getElementsByName(geouri_setgeourifieldname)[0];
          if (!point) {
//             alert("Address not found.");
//             document.getElementById("geouri_map_edit").style.visibility = 'hidden';
//             geouri_coordinates.value = '';
          } else {
            document.getElementById("geouri_map_edit").style.visibility = 'visible';
            geouri_map_edit.setCenter(point, 13);
            geouri_map_edit.removeOverlay(geouri_edit_marker);
            delete(geouri_edit_marker);
            geouri_edit_marker = new GMarker(point);
            geouri_map_edit.addOverlay(geouri_edit_marker);
            var geouri_workstring1 = String(point);
            var geouri_workstring2 = String(geouri_workstring1.replace(/\)/g, ''));
            var geouri_workstring3 = String(geouri_workstring2.replace(/\(/g, ''));
            var geouri_workstring4 = String(geouri_workstring3.replace(/\ /g, ''));
            geouri_coordinates.value = geouri_workstring4;
          }
        }
      );
    }
  }
}
    //]]>

