    //<![CDATA[
		
	var stat = "Slovensko";	
    var map = null;
    var geo;
    var reasons=[];
    var obec;
    
    function nazovobce(obec) {
		  var xmlHttp;
		  try
			{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
			}
		  catch (e)
			{
			// Internet Explorer
			try
			  {
			  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			  }
			catch (e)
			  {
			  try
				{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
			  catch (e)
				{
				alert("Vas prehliadac nepodporuje AJAX!");
				return false;
				}
			  }
			}
			xmlHttp.onreadystatechange=function()
			  {
			  if(xmlHttp.readyState==4)
				{
				obec = xmlHttp.responseText;
				document.getElementById('nazov_obce').value = xmlHttp.responseText;
				}
			  }
			xmlHttp.open("GET","inc/nazovobce.php?obec="+obec,true);
			xmlHttp.send(null);
		}
    
    function zmenmapu() {
      if (document.getElementById('je_mapa').checked == true) {
		 load();
         showAddress();
      }    
    }
    
    function load() {
      //document.getElementById('je_mapa').checked = true;
      
      map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl(1));	  
      map.setCenter(new GLatLng(48.139516,17.128716),12);
  	  map.enableScrollWheelZoom();
  	  map.enableDoubleClickZoom();
  	  GEvent.addDomListener(map.getContainer(), "DOMMouseScroll", wheelevent);
  	  map.getContainer().onmousewheel = wheelevent; 
  	  //continuous zoom enable
  	  map.enableContinuousZoom();
	  
      // ====== Create a Client Geocoder ======
      geo = new GClientGeocoder(); 

      // ====== Array for decoding the failure codes ======
      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]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      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.";
      
      GEvent.addListener(map,"move",getZoom);
      GEvent.addListener(map,"move",getType);
    }
  
	//prevent page scroll
	function wheelevent(e) {
			
			if (!e){
			e = window.event
			}
			if (e.preventDefault){
			e.preventDefault()
			}
			e.returnValue = false;
			
	}
	
	
  	function getZoom(){
      document.getElementById("zoom").value=map.getZoom();
    }
    
    function getType() {
      if (map.getCurrentMapType() == G_NORMAL_MAP) {
        document.getElementById("map_type").value="G_NORMAL_MAP";
      }
      if (map.getCurrentMapType() == G_SATELLITE_MAP) {
        document.getElementById("map_type").value="G_SATELLITE_MAP";
      }
      if (map.getCurrentMapType() == G_HYBRID_MAP) {
        document.getElementById("map_type").value="G_HYBRID_MAP";
      }
    }
    
    function setType(typ) {
      map.setMapType(typ);
    }
			
      // ====== Plot a marker after positive reponse to "did you mean" ======
    function place(lat,lng,z) {
        var point = new GLatLng(lat,lng);
        map.setCenter(point,14);
        map.setZoom(z);
		    var markerD2 = new GMarker(point, {icon:G_DEFAULT_ICON, draggable: true}); 
		    map.addOverlay(markerD2);
		
		    markerD2.enableDragging();
		
        document.getElementById("message").innerHTML = "";
		
        document.getElementById("location").value=markerD2.getPoint().toUrlValue();
		
		    GEvent.addListener(markerD2, "drag", function(){
		    document.getElementById("location").value=markerD2.getPoint().toUrlValue();
		});		
	}

      // ====== Geocoding ======
    function showAddress() {
     if (map != null) {
		document.getElementById('je_mapa').checked = true;
	  	if (document.getElementById("nazovkraj")) {
		    var kraj = ", " + document.getElementById("nazovkraj").value;
		  }
		  else {
		    var kraj = '';
		  }
		  
		  if (document.getElementById("nazov_obce")) {
		    var obec = ", " + document.getElementById("nazov_obce").value;
		  }
		  else {
		    var obec = '';
		  }
			var search = document.getElementById("ulica").value + obec + ", " + stat;
            // ====== 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 = "Mysleli ste:";
                // 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]
              } 
        /*************************NENASIEL ULICU, TAK TERAZ SA SNAZI NAJST OBEC*/
              //alert('Could not find "'+search+ '" ' + reason);
			         //document.getElementById("mapachyba").value = 'Could not find "'+search+ '" ' + reason;
			         
			         //if (document.getElementById("obec").value == '')
			         var search = document.getElementById("nazov_obce").value + ", " + stat;
	  	         // alert('Could not find "'+search+ '" ' + reason);
	  	
                // ====== 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 = "Mysleli ste:";
                        // 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]
                      } 
        			         //document.getElementById("mapachyba").value = 'Could not find "'+search+ '" ' + reason;
        			         
                       place(48.139516,17.128716);
                    }
                  }
                );		         
			         
               //place(48.139516,17.128716);
            }
          }
        );
      }
     }


