﻿function clearForm() { document.getElementById("ctl00_Main_lat").value = ""; document.getElementById("ctl00_Main_lng").value = ""; } 

var mArray = Array();

 

    if (GBrowserIsCompatible()) {

      var lastmarker;

       var iwform = '<div align="center" class="INFOWINDOW">Your Geo-Location will be based on this point. To select another location press the <B>Remove</B> button below and start again.</div></td></tr></table><table width="220" border="0" class="style1"><tr><td><div align="center"></div></td></tr></table><table width="220" border="0"><tr><td class="style5"><div align="center" class="style2"><input type="button" onClick="lastmarker.hide(); map.closeInfoWindow(); clearForm();" value="Remove" /></div></td></tr></table>';

 

 

 

 

      // == creates a draggable marker with an input form ==

      function createInputMarker(point) {

        var marker = new GMarker(point,{draggable:false, icon:G_START_ICON});

        GEvent.addListener(marker, "click", function() {

          lastmarker = marker;

          marker.openInfoWindowHtml(iwform);

        });

        map.addOverlay(marker);

 

        marker.openInfoWindowHtml(iwform);

        lastmarker=marker;

        return marker;

      }

 

      // == creates a "normal" marker

      function createMarker(point,text) {

        var marker = new GMarker(point);

        GEvent.addListener(marker,"click", function() {

          marker.openInfoWindow(document.createTextNode(text));

        });

        map.addOverlay(marker);

        return marker;

      }

//var result;




var map = new GMap2(document.getElementById("map"), {mapTypes:[G_NORMAL_MAP]});
map.setCenter(new GLatLng(52.65191617864402,-7.25247859954834), 13);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new google.maps.LocalSearch());
var kml = new GGeoXml("http://planning.kilkennycoco.ie/gmaps/OutsideKilkenny.kml");
map.addOverlay(kml);

      // == Display the map, with some controls and set the initial location



 

 

 

            var marker = new Array();

            var tileLayers;

    tileLayers = new Array();

    // "map" is the ID of the DIV in which the map contains

 //   var map = new GMap2(document.getElementById("map"));

 

 

 

 

 

 

                                    GDraggableObject.setDraggableCursor('crosshair');

                                    GDraggableObject.setDraggingCursor('move');

 

 // ============================================================

      // ===== Start of Custom Map Addition

 // ============================================================

           // ============================================================

 

            var TileToQuadKey = function ( tx,  ty,  zl){

                                                var quad;

                                                quad = "";

                                                for (var i = zl; i > 0; i--){

                                                            var mask = 1 << (i - 1);

                                                            var cell = 0;

                                                            if ((tx & mask) != 0)

                                                                        cell++;

                                                            if ((ty & mask) != 0)

                                                                        cell += 2;

                                                            quad += cell;

                                                }

                                                return quad;

                                    }

 

 

                                    var OSIcopyright = new GCopyright(1,

                              new GLatLngBounds(new GLatLng(-90, -180),

                                                new GLatLng(90, 180)),

                              0,

                              "Kilkenny CCMA 2008-2012");

                    var copyrightCollection = new GCopyrightCollection('OSI Licence # ');

                                    copyrightCollection.addCopyright(OSIcopyright);

 

 

                                    var SIXINCHMAPS = function (a,b) {

 

                                                var f = "http://gis.kilkennycoco.ie/Background Mapping/SixInch/Layer_SI/" + TileToQuadKey(a.x,a.y,b) + ".png";

                                                return f;

                                    }

 

 

                                                                        var DISCOVERYMAP = function (a,b) {

 

                                                var f = "http://gis.kilkennycoco.ie/Background Mapping/Layer_Discovery/" + TileToQuadKey(a.x,a.y,b) + ".png";

                                                return f;

                                    }

 

 

                                                                                                            var PHOTO2005 = function (a,b) {

 

                                                var f = "http://gis.kilkennycoco.ie/Background Mapping/2005/Layer_OSI/" + TileToQuadKey(a.x,a.y,b) + ".png";

                                                return f;

                                    }

 

 

 

 

                                    tileLayers[0] = new Array();

                                    tileLayers[0][0] = new GTileLayer(copyrightCollection , 12, 17);

                                    tileLayers[0][0].getTileUrl = PHOTO2005;

                                    tileLayers[0][0].isPng = function() {return true;};

                                    var ORTHO2005 = new GMapType(tileLayers[0], G_NORMAL_MAP.getProjection(), "Photography", {errorMessage:"No OSi 2005 Photography available at this scale and/or location"});

                                    map.addMapType(ORTHO2005);

 

                                    tileLayers[1] = new Array();

                                    tileLayers[1][0] = new GTileLayer(copyrightCollection , 12, 17);

                                    tileLayers[1][0].getTileUrl = DISCOVERYMAP;

                                    tileLayers[1][0].isPng = function() {return true;};

                                    var DISCOVERYCOL = new GMapType(tileLayers[1], G_NORMAL_MAP.getProjection(), "Discovery", {errorMessage:"No Discovery Mapping available at this scale and/or location"});

                                    map.addMapType(DISCOVERYCOL);

 

                                    tileLayers[2] = new Array();

                                    tileLayers[2][0] = new GTileLayer(copyrightCollection , 12, 17);

                                    tileLayers[2][0].getTileUrl = SIXINCHMAPS;

                                    tileLayers[2][0].isPng = function() {return true;};

                                    var SIXINCH = new GMapType(tileLayers[2], G_NORMAL_MAP.getProjection(), "Six Inch", {errorMessage:"No Six Inch Mapping available at this scale and/or location. Zoom in closer."});

                                    map.addMapType(SIXINCH);

 

                         // ====== Restricting the range of Zoom Levels =====

      // Get the list of map types

      var mt = map.getMapTypes();

      // Overwrite the getMinimumResolution() and getMaximumResolution() methods

      for (var i=0; i<mt.length; i++) {

        mt[i].getMinimumResolution = function() {return 13;}

        mt[i].getMaximumResolution = function() {return 17;}

     }

 

 

 

               // ============================================================

      // ===== End of Custom map Addition

 

               // Add a move listener to restrict the bounds range

      GEvent.addListener(map, "move", function() {

        checkBounds();

      });

 

      // The allowed region which the whole map must be within

      var allowedBounds = new GLatLngBounds(new GLatLng(52.217673,-7.758157), new GLatLng(52.932486,-6.864090));

 

 

 

      // If the map position is out of range, move it back

      function checkBounds() {

        // Perform the check and return if OK

        if (allowedBounds.contains(map.getCenter())) {

          return;

        }

        // It`s not OK, so find the nearest allowed point and move there

        var C = map.getCenter();

        var X = C.lng();

        var Y = C.lat();

 

        var AmaxX = allowedBounds.getNorthEast().lng();

        var AmaxY = allowedBounds.getNorthEast().lat();

        var AminX = allowedBounds.getSouthWest().lng();

        var AminY = allowedBounds.getSouthWest().lat();

 

        if (X < AminX) {X = AminX;}

        if (X > AmaxX) {X = AmaxX;}

        if (Y < AminY) {Y = AminY;}

        if (Y > AmaxY) {Y = AmaxY;}

        //alert ("Restricting "+Y+" "+X);

        map.setCenter(new GLatLng(Y,X));

      }

 

 

                        // Start of GeoCoding - Brendan C

             // ====== Create a Client Geocoder ======

            var kilkenny = ' Kilkenny Ireland';

 function showAddresskilkenny(search)

                        {   showAddress(search + kilkenny)

 

                          }

 

      var geo = new GClientGeocoder();

 

      // ====== Array for decoding the failure codes ======

      var reasons=[];

      reasons[G_GEO_SUCCESS]            = "Success";

      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";

      reasons[G_GEO_UNKNOWN_ADDRESS]    = ". Please check your spelling or refine your address search with more detail (eg, 'Main Street Ballyhale' instead of 'Main Street').";

      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";

      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";

      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";

      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";

 

                    // ====== Plot a marker after positive reponse to "did you mean" ======

      function place(lat,lng) {

        var point = new GLatLng(lat,lng);

        map.setCenter(point,14);

    //    map.addOverlay(new GMarker(point));

        document.getElementById("message").innerHTML = "";

      }

 

      // ====== Geocoding ======

      function showAddress() {

        var search = document.getElementById("search").value + kilkenny;

        // ====== Perform the Geocoding ======

   geo.getLocations(search, function (result)

          {

            map.clearOverlays();

            if (result.Status.code == G_GEO_SUCCESS) {

              // ===== If there was more than one result, "ask did you mean" on them all =====

              if (result.Placemark.length > 1) {

                document.getElementById("message").innerHTML = "Did you mean:";

                // Loop through the results

                for (var i=0; i<result.Placemark.length; i++) {

                  var p = result.Placemark[i].Point.coordinates;

                  document.getElementById("message").innerHTML += "<br>"+(i+1)+": <a href='javascript:place(" +p[1]+","+p[0]+")'>"+ result.Placemark[i].address+"</a>";

                }

              }

              // ===== If there was a single marker =====

              else {

                document.getElementById("message").innerHTML = "";

                var p = result.Placemark[0].Point.coordinates;

                place(p[1],p[0]);

              }

            }

            // ====== Decode the error status ======

            else {

              var reason="Code "+result.Status.code;

              if (reasons[result.Status.code]) {

                reason = reasons[result.Status.code]

              }

              alert('Could not find "'+search+ '" ' + reason);

 

                                    }

          }

        );

      }

 

 

 

            // End of GeoCoding - Brendan C

 

 

    function resizeMap() {

 

                /* Again, IE and Firefox have different ways to get the window's height */

                if (document.documentElement &&      document.documentElement.clientHeight) {

                            var winHeight = document.documentElement.clientHeight;

                }

                else if (window.self && self.innerHeight) {

                            var winHeight = self.innerHeight;   // This is for Mozilla

                }

 

                var e = document.getElementById("map");

                var e2 = document.getElementById("sidebar");

                var offset = e.offsetTop;

 

                var height = winHeight - offset - 70;

 

                e.style.height = height + "px";

                e2.style.height = height + "px";

    }

 

 	  // == Listen for map click and add an input marker
      GEvent.addListener(map,"click",function(overlay,point){
        if (!overlay) {
		map.clearOverlays()
		map.addOverlay(kml)
          createInputMarker(point);
        }
      });

 

 

GEvent.addListener(map, "click",function(marker,point){

 

            if (!marker) {

                        oLat = document.getElementById("ctl00_Main_lat");

                        oLat.value = point.y;

                        oLon = document.getElementById("ctl00_Main_lng");

                        oLon.value = point.x;

            }

 });

 

 

 function process(form) {

        // == obtain the data

        var forename = form.forename.value;

                        var surname = form.surname.value;

                        var mobile = form.mobile.value;

                        var email = form.email.value;

                        var SearchLimit = form.SearchLimit.value;

        var lat = form.ctl00_Main_lat.value;

        var lng = form.ctl00_Main_lng.value;

 

                         GDownloadUrl(

                        "userdetails7.php",

                         function(doc){},

                         "lat=" + lat + "&lng=" + lng + "&forename=" + forename + "&surname=" + surname + "&mobile=" + mobile + "&email=" + email + "&GeneralRpt=" + GeneralRpt + "&PlanningRpt=" + PlanningRpt + "&WaterRpt=" + WaterRpt + "&CensusElecRpt=" + CensusElecRpt + "&SearchLimit=" + SearchLimit + "&EnvGeoRpt=" + EnvGeoRpt);

 

        // == remove the input marker and replace it with a completed marker

        map.closeInfoWindow();

 

      var point = lastmarker.getPoint();

              var html = "<div class='style2'>Thank you<B> " + forename + "</B>.<BR>You will shortly receive an email with your report(s) attached.</div>";

      var marker = createMarker(point,html);

      map.addOverlay(marker);

      GEvent.addListener(marker,"click", function() {

          marker.openInfoWindowHtml(html);

        });

 

      }

 

 

 

 

    }

 

    else {

      alert("Sorry, the Google Maps API is not compatible with this browser");

    }

    //]]>

