/**
 * Map controls
 */
var gmap = null;
var loaded = null;
var sendForApi = null;


/* Load api */	
//google.load("maps", "2.x");

function mapsLoaded() {
	loaded = true;
}

/**
 * Function initializes map within given divId element, showing marker
 * found at given location. If location not found or error occured, the map
 * doesn't loads instead the error message is displayed.
 * @param {String} location location to search
 * @param {String} divId id of element to put the map in
 */
function initialize(location, divId) {
	
	if(!loaded) {
		google.load('maps', '2.x',{'callback': function() {loaded = true; initialize(location, divId); }});
		return;
	}
	
	if (google.maps.BrowserIsCompatible()) {
		
		/* Div content element */
		var div = document.getElementById(divId);
		
		/* Geocoder search */
		var myGeocoder = new MyGeocoder('PL', div);
	
		/* TEST */
		//location = 'Wrocław, Stare Miasto, Inowrocławska';
		//location = 'Wrocław, Krzyki, Gwiaździsta 36';
		//location = 'Wrocław, Krzyki';
		//location = 'Wrocław';
	
		/* Run geocoding search */
		myGeocoder.performSearch(location);
		
	}
}

function initialize2(lat, lng, divId) {
	
	if(!loaded) {
		google.load('maps', '2.x',{'callback': function() {loaded = true; initialize2(lat, lng, divId);}});
		return;
	}
	
	if (google.maps.BrowserIsCompatible()) {
		
		//google.maps.Log.write(lng + ' ->' + lat);
		
		/* Div content element */
		var div = document.getElementById(divId);
		
		/* Geocoder search */
		var myGeocoder = new MyGeocoder('PL', div);
		
		var myGmap = new MyGmap(div, myGeocoder);
	
		myGmap.loadMap(new google.maps.LatLng(parseFloat(lat), parseFloat(lng)),false ,15);
		
			
	}
}

/**
 *
 */
function initializeOnce(divId, zoom, lat, lng, location_lat, location_lng, park_area) {
	
	if(!loaded) {
		google.load('maps', '2.x',{'callback': function() {loaded = true; initializeOnce(divId, zoom, lat, lng); if(location_lat && location_lng && park_area) gmap.startMakingArea(location_lat, location_lng, park_area); else if(park_area) gmap.showArea(park_area); }});
		return;
	}
	
	if (google.maps.BrowserIsCompatible()) {
		
		/* Div content element */
		var div = document.getElementById(divId);
		
		/* Geocoder search */
		var myGeocoder = new MyGeocoder('PL', div);
	
		/* Create Geocoder */
		var myGmap = new MyGmap(div, myGeocoder);
		myGeocoder.map = myGmap;
		if ((lat) && (lng)) { /* Marker should be added */
			myGmap.loadMap(new google.maps.LatLng(parseFloat(lat), parseFloat(lng)), false, zoom);
		} else { /* Normal add mode */
			myGmap.loadFirst(new google.maps.LatLng(51.9194380, 19.1451360), zoom);
			//myGmap.startAddMarkerMode();
		}
		
		/* Expose map object */
		gmap = myGmap;
		return myGmap;
	}
}

/*========================= GoogleMap ================================*/

/**
 * Constructor of map
 * @param {DOMObject} div element to insert within the map
 */
function MyGmap(div, geocoder) {
	this.debug = false;
	this.div = div;
	this.map = null;
	this.mapPoints = new Array();
	this.myGeocoder = geocoder;
	this.newMarker = null;
}

/**
 * Loads map with given point and zoom
 * @param {GLatLng} point to add
 * @param {Number} zoom level
 * @param {String} text optional text 
 */
MyGmap.prototype.loadMap = function(point, draggable, zoom, text) {
	/* Initializing map */
	this.map = new google.maps.Map2(this.div);
	this.map.setCenter(point, zoom);
    //map.addControl(new google.maps.LargeMapControl3D());
	this.map.addControl(new google.maps.SmallZoomControl3D());
	
	//map.disableDragging();
	var m = null;
	if(draggable) {
		m = new google.maps.Marker(point,{draggable:true, autoPan:false});
		google.maps.Event.addListener(m, 'dragend', function(position) {
	    	//marker.openInfoWindow(marker.innerForm);
			//alert(position.lat() + ':' + position.lng());
	    	document.getElementById('ggl_h').value = position.lat();
			document.getElementById('ggl_w').value = position.lng();
		});
		this.newMarker = m;
	} else {
		m = new google.maps.Marker(point);	
		//alert('POINT');
		//google.maps.Log.write('Point: ' + point);
	}
	this.map.addOverlay(m);
	this.mapPoints.push(m);
//	if(text != null) {
//		google.maps.Event.addListener(m,'click', function() {
//			m.openInfoWindowHtml(text, {maxWidth: 40});
//		}); 
//	}
	var that = this;
	google.maps.Event.addListener(this.map, 'movestart', function() {
		if(that.myGeocoder) {
			that.myGeocoder.hideTooltip();	
		}
	});
	google.maps.Event.addListener(this.map, 'zoomend', function() {
		if(that.myGeocoder) {
			that.myGeocoder.hideTooltip();	
		}
	});
}

MyGmap.prototype.loadFirst = function(point, zoom) {
	/* Initializing map */
	this.map = new google.maps.Map2(this.div);
	this.map.setCenter(point, zoom);
	//this.map.addControl(new google.maps.LargeMapControl());
	//this.map.addControl(new google.maps.SmallZoomControl3D());
	this.map.addControl(new google.maps.LargeMapControl3D());
	this.map.addControl(new google.maps.HierarchicalMapTypeControl());
	this.map.addMapType(G_HYBRID_MAP);
	this.map.addMapType(G_PHYSICAL_MAP);
	
	this.lineColor = "#0000af";
	this.fillColor = "#335599";
	this.lineWeight = 3;
	this.lineOpacity = .8;
	this.fillOpacity = .2;
		
	
	var that = this;
	google.maps.Event.addListener(this.map, 'movestart', function() {
		if(that.myGeocoder) {
			that.myGeocoder.hideTooltip();	
		}
	});
	google.maps.Event.addListener(this.map, 'zoomend', function() {
		if(that.myGeocoder) {
			that.myGeocoder.hideTooltip();	
		}
	});
}

MyGmap.prototype.focusOnProvince = function(name) {
	this.myGeocoder.performSearchAndFocus(name, 7);
}
	
MyGmap.prototype.focusOnCity = function(name) {
	this.myGeocoder.performSearchAndFocus(name, 12);	
}

/**
 * Musi byc nazwa miasta dodatkowo
 * @param {Object} name
 */
MyGmap.prototype.focusOnDistrict = function(name) {
	this.myGeocoder.performSearchAndFocus(name, 13);
}	

MyGmap.prototype.focusOnStreet = function(name) {
	this.myGeocoder.performSearchAndFocus(name, 16);
}

MyGmap.prototype.focusOnLocation = function(country, province, city, district, street) {
	var cnt = document.getElementById(country);
	var cntText = null;
	if(cnt) {
		cntText = cnt.value;
	}
	var p = document.getElementById(province);
	var pText = null;
	if(p) {
		pText = p.options[p.selectedIndex].text;	
	}
	var c = document.getElementById(city).value;
	var d = document.getElementById(district).value;
	var s = document.getElementById(street).value;
	if(this.debug) google.maps.Log.write(pText + ':' + c + ':' + d + ':' + s);
	var name = '';
	var zoom = 7;
	if (cntText && (cntText.length > 2)) {
		name += cntText;
		zoom = 5;
	}
	if(pText && (pText != 'wybierz')) name += pText;
	if (c.length > 2) {
		name += ', ' + c;
		zoom = 12;
	}
	if (d.length > 2) {
		name += ', ' + d;
		zoom = 13;
	}
	if (s.length > 2) {
		name += ', ' + s;
		zoom = 16;
	}
	this.myGeocoder.performSearchAndFocus(name, zoom);
}
	

/**
 * Unloads map - for memory leaks
 */
MyGmap.prototype.unload = function() {
	for(var i=0; i<this.mapPoints.lenght; i++) {
		this.map.removeOverlay(this.mapPoints[i]);
		delete this.mapPoints[i];
	}
	this.mapPoints.splice(0, this.mapPoints.lenght);
}

MyGmap.prototype.clearMarkers = function() {
	for(var i=0; i<this.mapPoints.lenght; i++) {
		this.map.removeOverlay(this.mapPoints[i]);
		google.maps.Event.clearListeners(this.mapPoints[i]); 
		delete this.mapPoints[i];
	}
	this.mapPoints.splice(0, this.mapPoints.lenght);
}

MyGmap.prototype.removeLast = function() {
	var m = this.mapPoints.pop();
	this.map.removeOverlay(m);
	google.maps.Event.clearListeners(m);
}

MyGmap.prototype.createNewMarkerForm = function (newMarker) {
	var div = document.createElement('div');
	div.style.fontFamily = 'Arial,sans-serif';
	div.style.fontSize = '1.0em';
	div.style.padding = '5px';
	div.innerHTML = '<b>Ustaw punkt</b><br/>Po wybraniu nowego punktu kliknij: ';
	var button = document.createElement('input');
	button.type = 'button';
	button.value = 'Zapisz';
	button.onclick = function() {
		
	};
	div.appendChild(button);
	return div;
}

MyGmap.prototype.startAddMarkerMode = function () {
	this.follow();
}

MyGmap.prototype.follow = function() {
//	var marker;
//	var dog = true;
//	var noMore = false;
//	/* Start listening mouse move event */
//	var that = this;
//	var mouseMove = google.maps.Event.addListener(that.map, 'mousemove', function(cursorPoint){
//		if(!noMore){
//			marker = new google.maps.Marker(cursorPoint,{draggable:true, autoPan:false});
//			marker.innerForm = that.createNewMarkerForm(marker);
//			that.map.addOverlay(marker);
//			that.newPoint = marker;
//	        noMore = true;
//		    // This function deletes the marker when dragged outside map
//	        google.maps.Event.addListener(marker, 'drag', function(markerPoint){
//	        	marker.closeInfoWindow();
//	        	if(!that.map.getBounds().containsLatLng(markerPoint)){
//	        		that.map.removeOverlay(marker);
//	        	}
//			});
//	        //Function for info window handling
//	        //google.maps.Event.addListener(marker, 'click', function() {
//	        //	marker.openInfoWindow(marker.innerForm);
//	    	//});
//	        google.maps.Event.addListener(marker, 'dragend', function(position) {
//	        	//marker.openInfoWindow(marker.innerForm);
//				//alert(position.lat() + ':' + position.lng());
//	    		document.getElementById('ggl_h').value = position.lat();
//				document.getElementById('ggl_w').value = position.lng();
//			});
//		}
//	    if(dog){
//	    	marker.setLatLng(cursorPoint);
//			//TODO set in input coordinates
//			//ggl_h
//			//ggl_w
////			document.getElementById('ggl_h').value = marker.getLatLng().lat();
////			document.getElementById('ggl_w').value = marker.getLatLng().lng();
//	    }
//		document.getElementById('ggl_h').value = cursorPoint.lat();
//		document.getElementById('ggl_w').value = cursorPoint.lng();
//	    		
//	});
//	var mapClick = google.maps.Event.addListener(that.map, 'click', function(){
//		dog = false;
//	    // 'mousemove' event listener is deleted to save resources
//	    google.maps.Event.removeListener(mouseMove);
//	    google.maps.Event.removeListener(mapClick);
//	    //marker.openInfoWindow(marker.innerForm);
//	});
	var that = this;
	var mapClick = google.maps.Event.addListener(that.map, 'click', function(overlay, cursorPoint){
		if(!that.newMarker) {
			that.newMarker = new google.maps.Marker(cursorPoint,{draggable:true, autoPan:false});
			that.map.addOverlay(that.newMarker);
			
			document.getElementById('ggl_h').value = cursorPoint.lat();
			document.getElementById('ggl_w').value = cursorPoint.lng();
			
			google.maps.Event.addListener(that.newMarker, 'dragend', function(position) {
	        	//marker.openInfoWindow(marker.innerForm);
				//alert(position.lat() + ':' + position.lng());
	    		document.getElementById('ggl_h').value = position.lat();
				document.getElementById('ggl_w').value = position.lng();
			});
		}
		if(that.myGeocoder) {
			that.myGeocoder.hideTooltip();
		}
	});
}

MyGmap.prototype.addIcon = function(icon) { // Add icon attributes
	icon.shadow = this.icon_url + "mm_20_shadow.png";
	icon.iconSize = new google.maps.Size(12, 20);
	icon.shadowSize = new google.maps.Size(22, 20);
	icon.iconAnchor = new google.maps.Point(6, 20);
	icon.infoWindowAnchor = new google.maps.Point(5, 1);
}

MyGmap.prototype.startMakingArea = function (idLat, idLng, idArea) {
	var that = this;
	this.count = 0;
	this.pts = new Array();
	this.markers = new Array();
	this.icon_url ="http://labs.google.com/ridefinder/images/";
	this.points = new Array();
	this.divLat = document.getElementById(idLat);
	this.divLng = document.getElementById(idLng);
	this.divArea = document.getElementById(idArea);

	google.maps.Event.clearListeners(this.map);
	google.maps.Event.addListener(this.map, "click", function(overlay, point) {
		if(point) {
  			that.count++;
 			if(that.count%2 != 0) {
  				// Light blue marker icons
				var icon = new google.maps.Icon();
  				icon.image = that.icon_url + "mm_20_yellow.png";
  				that.addIcon(icon);
 			} else {
				// Purple marker icons
				var icon = new google.maps.Icon();
				icon.image = that.icon_url +"mm_20_purple.png";
  				that.addIcon(icon);
 			}

  			// Make markers draggable
			var marker = new google.maps.Marker(point, {icon:icon, draggable:true, bouncy:false, dragCrossMove:true});
  			that.map.addOverlay(marker);
  			marker.content = that.count;
  			marker.tooltip = "Punkt "+ that.count;
			that.markers.push(marker);
  			

//  			GEvent.addListener(marker, "mouseover", function() {
//	 			//showTooltip(marker);
//  			});

//  GEvent.addListener(marker, "mouseout", function() {
//   tooltip.style.display = "none";
// });

  			// Drag listener
  			google.maps.Event.addListener(marker, "drag", function() {
   				//tooltip.style.display = "none";
   				that.drawOverlay();
				that.updateInputData();
  			});

  			// Second click listener
	  		google.maps.Event.addListener(marker, "click", function() {
   				//tooltip.style.display = "none";

  				// Find out which marker to remove
				for(var n = 0; n < that.markers.length; n++) {
   					if(that.markers[n] == marker) {
    					that.map.removeOverlay(that.markers[n]);
    					break;
   					}
  				}

  				// Shorten array of markers and adjust counter
  				that.markers.splice(n, 1);
  				if(that.markers.length == 0) {
    				count = 0;
  				} else {
    				that.count = that.markers[that.markers.length-1].content;
    				that.drawOverlay();
  					that.updateInputData();
				}
  			});
 
 			that.drawOverlay();
			that.updateInputData();
 		}
	});
}

MyGmap.prototype.updateInputData = function() {
	if(this.divArea) {
		this.divArea.value = '';
		if (this.markers.length > 2) {
			for (var i = 0; i < this.markers.length; i++) {
				this.divArea.value += this.markers[i].getLatLng().lat().toPrecision(7) + ',' +
				this.markers[i].getLatLng().lng().toPrecision(7);
				if (i < this.markers.length - 1) 
					this.divArea.value += ':';
			}
		}
	}
	var bounds = this.poly.getBounds();
  	if(this.divLat) {
		if(this.markers.length > 2) 
			this.divLat.value = bounds.getCenter().lat().toPrecision(7) + ' ';	
		else this.divLat.value = '';
	}
	if(this.divLng) {
		if(this.markers.length > 2) 
			this.divLng.value = bounds.getCenter().lng().toPrecision(7) + ' ';	
		else this.divLng.value = '';
	}
}

MyGmap.prototype.drawOverlay = function () {

	if(this.poly) { this.map.removeOverlay(this.poly); }
	this.points.length = 0;

 	for (i = 0; i < this.markers.length; i++) {
		this.points.push(this.markers[i].getLatLng());
	}
   
   	// Polygon mode
   	this.points.push(this.markers[0].getLatLng());
    this.poly = new google.maps.Polygon(this.points, this.lineColor, this.lineWeight, this.lineOpacity, this.fillColor, this.fillOpacity);
  	this.map.addOverlay(this.poly);
}

MyGmap.prototype.showArea = function(divId) {
	this.map.addControl(new google.maps.LargeMapControl3D());
	this.map.addControl(new google.maps.HierarchicalMapTypeControl());
	this.map.addMapType(G_HYBRID_MAP);
	this.map.addMapType(G_PHYSICAL_MAP);
	
	this.lineColor = "#0000af";
	this.fillColor = "#335599";
	this.lineWeight = 3;
	this.lineOpacity = .8;
	this.fillOpacity = .2;
    	
	var div = document.getElementById(divId);
	if (div) {
		var points = new Array();
		var pointsStrings = div.value.split(":");
		var pointString = null;
		for (var i = 0; i < pointsStrings.length; i++) {
			pointString = pointsStrings[i].split(',');
			points.push(new google.maps.LatLng(parseFloat(pointString[0]), parseFloat(pointString[1])));
		}
		points.push(points[0]);	
		var poly = new google.maps.Polygon(points, this.lineColor, this.lineWeight, this.lineOpacity, this.fillColor, this.fillOpacity);
		poly.getBounds().getCenter();
		
  		var bounds = poly.getBounds();
  		this.map.setCenter(bounds.getCenter());
  		this.map.setZoom(this.map.getBoundsZoomLevel(bounds)); 
		this.map.addOverlay(poly);
	}
} 

/*========================= GeoCoding ================================*/
/**
 * Main class for handling geocode request to google API
 * @param {Object} locale locales for searching locations
 */
function MyGeocoder(locale, div) {
	this.div = div;
	this.debug = false;									//Debugging for MyGeocoder                                   
	this.geocoder = new google.maps.ClientGeocoder();   //Client geocoder
	this.geocoder.setBaseCountryCode(locale);
	this.map = null;
	this.tooltip = null;
	this.timer = null;
}

/**
 * Function performs location search, based on given query,
 * and returns location point
 * @param {Object} location query to geocode
 */
MyGeocoder.prototype.performSearch = function(location) {
	if(this.geocoder) {
		if(location.length <= 2) {
			this.handleErrors(G_GEO_MISSING_QUERY);
			return;
		}
		if(this.debug) google.maps.Log.write('MyGeocoder DEBUG: ' + 'searching: ' + location);  
		var that = this;
		this.geocoder.getLocations(location, 
			
			function(response) {
				/* Response handler */
				var place = null;
				/* Check the response */
				if(response.Status.code == G_GEO_SUCCESS) {
					if(that.debug) google.maps.Log.write('MyGeocoder DEBUG: ' + response);
					if(response.Placemark.lenght > 1) {
						if(that.debug) google.maps.Log.write('MyGeocoder DEBUG: ' + 'more than one result!');
					}
					place = response.Placemark[0];
					//place.address - nicely formed address
					//place.AddressDetails.Accuracy - accuracy- dpends on map zoom
					//place.Point.coordinates[0] - lon
					//place.Point.coordinates[1] - lat
					var zoom = 4;
					if(place.AddressDetails.Accuracy <= 4) zoom = 12;
					else if(place.AddressDetails.Accuracy <= 5) zoom = 13;
					else if(place.AddressDetails.Accuracy <= 6) zoom = 15;
					else if(place.AddressDetails.Accuracy <= 7) zoom = 17; 
					else zoom = 7;
					if (!that.map) {
						that.map = new MyGmap(that.div, that);
						that.map.loadMap(new google.maps.LatLng(place.Point.coordinates[1], place.Point.coordinates[0]), false, zoom, place.address);
					}	
				} else {
					that.handleErrors(response.Status.code);
					if(that.debug) google.maps.Log.write('MyGeocoder DEBUG: ' + 'not found!');
				}
			}
		
		);
	} else {
    	if(this.debug) google.maps.Log.write('MyGeocoder DEBUG: ' + 'geocoder is null'); 
    }
}

MyGeocoder.prototype.performSearchAndFocus = function(location, zoom) {
	if(this.geocoder) {
		if(location.length <= 2) {
			//this.handleErrors(G_GEO_MISSING_QUERY);
			return;
		}
		if(this.debug) google.maps.Log.write('MyGeocoder DEBUG: ' + 'searching: ' + location);  
		var that = this;
		this.geocoder.setViewport(this.map.map.getBounds());
		this.geocoder.getLocations(location, 
			
			function(response) {
				/* Response handler */
				var place = null;
				/* Check the response */
				if(response.Status.code == G_GEO_SUCCESS) {
					if(that.debug) google.maps.Log.write('MyGeocoder DEBUG: ' + response);
					that.hideTooltip();
					if(response.Placemark.lenght > 1) {
						if(that.debug) google.maps.Log.write('MyGeocoder DEBUG: ' + 'more than one result!');
					}
					place = response.Placemark[0];
					//place.address - nicely formed address
					//place.AddressDetails.Accuracy - accuracy- dpends on map zoom
					//place.Point.coordinates[0] - lon
					//place.Point.coordinates[1] - lat
					that.map.map.setCenter(new google.maps.LatLng(place.Point.coordinates[1], place.Point.coordinates[0]), zoom);	
					if (that.map.newMarker) {
						that.map.newMarker.setLatLng(that.map.map.getCenter());
						google.maps.Event.trigger(that.map.newMarker, 'dragend', that.map.map.getCenter());
					}	
				} else {
					//that.handleErrors(response.Status.code);
					if(that.debug) google.maps.Log.write('MyGeocoder DEBUG: ' + 'not found!');
					that.showTooltip(that.map.map.getCenter(), "Nie można wycentrować,\n błędna lokalizacja!");
					that.timer = setTimeout(function(){that.hideTooltip();}, 4000);
				}
			}
		);
	} else {
    	if(this.debug) google.maps.Log.write('MyGeocoder DEBUG: ' + 'geocoder is null'); 
    }
}

/**
 * Display tooltip on a map object
 * @param {GLatLng} pos position to show tooltip
 * @param {String} text text of tooltip
 */
MyGeocoder.prototype.showTooltip = function(pos, text) { // Display tooltips
	if(this.timer) clearTimeout(this.timer);
	if(this.map) {
		if(!this.tooltip) {
			/* Add a div element for toolips */
 			this.tooltip = document.createElement("div");
 			this.tooltip.className="tooltip";
 			this.map.map.getPane(G_MAP_MARKER_PANE).appendChild(this.tooltip);	
		}
	
		this.tooltip.innerHTML = text;
	 	this.tooltip.style.display = "block";	 

		// Tooltip transparency specially for IE
 		if(typeof(this.tooltip.style.filter) == "string") {
			this.tooltip.style.filter = "alpha(opacity:70)";
		}

		var currtype = this.map.map.getCurrentMapType().getProjection();
		var point = currtype.fromLatLngToPixel(pos, this.map.map.getZoom());
		var offset= currtype.fromLatLngToPixel(this.map.map.getBounds().getSouthWest(),this.map.map.getZoom());
		if(this.debug) google.maps.Log.write((point.x - offset.x) + " : " +  (offset.y - point.y));
		var width = this.tooltip.clientWidth/2;
		var height = this.tooltip.clientHeight/2;
		var pos = new google.maps.ControlPosition(G_ANCHOR_TOP_LEFT, new google.maps.Size((point.x - offset.x - width), (offset.y - point.y - height))); 
		pos.apply(this.tooltip);
	}
	
}

/**
 * Hides tooltip
 */
MyGeocoder.prototype.hideTooltip = function() {
	if(this.map) {
		if (this.tooltip) {
			this.tooltip.style.display = "none";
			this.timer = null;
		}
	}
}

/**
 * Sets message to div element instead of loadin map
 * with result
 */
MyGeocoder.prototype.setMessage = function(text) {
	this.div.innerHTML = '<b>' + text + '</b>';
}
 

/**
 * Status codes hadler
 * @param {Object} statusCode
 */
MyGeocoder.prototype.handleErrors = function(statusCode) {
	if (statusCode == G_GEO_UNKNOWN_ADDRESS) {
		if (this.debug)	google.maps.Log.write("MyGeocoder DEBUG: " + "No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + statusCode);
		
	} else if (statusCode == G_GEO_SERVER_ERROR) { 
		if (this.debug) google.maps.Log.write("MyGeocoder DEBUG: " + "A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + statusCode);
	
	} else if (statusCode == G_GEO_MISSING_QUERY) { 
		if (this.debug)	google.maps.Log.write("MyGeocoder DEBUG: " + "The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + statusCode);
	
	} else if (statusCode == G_GEO_BAD_KEY) { 
		if (this.debug) google.maps.Log.write("MyGeocoder DEBUG: " + "The given key is either invalid or does not match the domain for which it was given. \n Error code: " + statusCode);
	
	} else if (statusCode == G_GEO_BAD_REQUEST) { 
		if (this.debug) google.maps.Log.write("MyGeocoder DEBUG: " + "A directions request could not be successfully parsed.\n Error code: " + statusCode);
	
	} else if (statusCode == G_GEO_MISSING_ADDRESS) { 
		if (this.debug)	google.maps.Log.write("MyGeocoder DEBUG: " + "The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + statusCode);
	
	} else if (statusCode == G_GEO_UNAVAILABLE_ADDRESS) { 
		if (this.debug)	google.maps.Log.write("MyGeocoder DEBUG: " + "The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + statusCode);
	
	} else if (statusCode == G_GEO_UNKNOWN_DIRECTIONS) { 
		if (this.debug) google.maps.Log.write("MyGeocoder DEBUG: " + "The GDirections object could not compute directions between the points mentioned in the query. This is usually because there is no route available between the two points, or because we do not have data for routing in that region.\n Error code: " + statusCode);
	
	} else if (statusCode == G_GEO_TOO_MANY_QUERIES) { 
		if (this.debug)	google.maps.Log.write("MyGeocoder DEBUG: " + "The given key has gone over the requests limit in the 24 hour period or has submitted too many requests in too short a period of time.\n Error code: " + statusCode);
		this.setMessage('Przekroczono 24h limit żądań dla map Google!');
		return;
	} else {
		if (this.debug) google.maps.Log.write("MyGeocoder DEBUG: " + "An unknown error occurred.\n Error code: " + statusCode);
	}
	this.setMessage('Brak dokładnych informacji o lokalizacji');	
}

