var google_to_visicom = new Array();
google_to_visicom[0] = 0;
google_to_visicom[1] = 0;
google_to_visicom[2] = 0;
google_to_visicom[3] = 0;
google_to_visicom[4] = 0;
google_to_visicom[5] = 0;
google_to_visicom[6] = 0;
google_to_visicom[7] = 0;
google_to_visicom[8] = 1;
google_to_visicom[9] = 2;
google_to_visicom[10] = 3;
google_to_visicom[11] = 5;
google_to_visicom[12] = 6;
google_to_visicom[13] = 7;
google_to_visicom[14] = 8;
google_to_visicom[15] = 9;
google_to_visicom[16] = 10;
google_to_visicom[17] = 11;
google_to_visicom[18] = 11;

var visicom_to_google = new Array();
visicom_to_google[0] = 7;
visicom_to_google[1] = 9;
visicom_to_google[2] = 9;
visicom_to_google[3] = 10;
visicom_to_google[4] = 11;
visicom_to_google[5] = 11;
visicom_to_google[6] = 12;
visicom_to_google[7] = 13;
visicom_to_google[8] = 14;
visicom_to_google[9] = 15;
visicom_to_google[10] = 16;
visicom_to_google[11] = 17;


$NOT_FOUND = 'По вашему запросу ничего не найдено.'

function do_search(query, callback) {
	call('./search.php?q=' + encodeURI(query) + "&method=places&template=places.html",
		function(places) {
			if (places != '')  places = "<b>Рыбные места</b>:<br/>" + places;
			
			call('./search.php?q=' + encodeURI(query) + "&method=address&template=address.html",
				function(address) {
					if (address != '')  address = "<b>Населенные пункты</b>:<br/>" + address;
					
					callback(places + address);
				}
			);
		}
	);
}

function centerMap(id, map) {
	if (id.lng != null) {
		if (current_map == 'visicom') {
			map.setCenter(new VGeoPoint(id.lng, id.lat), 10);
			visicom_zoom = map.getZoomIndex();
                    	
		} else
		if (current_map == 'google') {
			Google_Map.setCenter(new GLatLng(id.lat, id.lng), visicom_to_google[10]);
			google_zoom = Google_Map.getZoom();
		}
		center_lng = id.lng;
                center_lat = id.lat;
		changeLink();
		return;
	}
	
	call('./search.php?q=' + encodeURI(id) + "&method=bounds",
		function(callback) {
			if (callback == '') return;
			var bounds = eval(callback);
			
			var point1 = bounds.getMinPoint().convertToGeoPoint();
			var point2 = bounds.getMaxPoint().convertToGeoPoint();
			center_lng = point1.getLongitude() + ((point2.getLongitude() - point1.getLongitude()) / 2);			
			center_lat = point1.getLatitude() + ((point2.getLatitude() - point1.getLatitude()) / 2);
			
			if (current_map == 'visicom') {
				map.setCenter(bounds);
				changeLink();
			} else
			if (current_map == 'google') {
				Google_Map.setCenter(new GLatLng(center_lat, center_lng), visicom_to_google[7]);
			}
		}
	);
}

var _route_ = null;
function showRoute(pointFrom, pointTo) {
	if (_route_ != null) map.removeRoute(_route_);
	
	var routeService = new VRouteService();  
	routeService.calculateRoute(pointFrom, pointTo,  
		function(route) {
			_route_ = route;
			map.addRoute(_route_);  
			map.repaintMap();  
		}  
	);  
}

// Нажата ли цифра
function isNumKeyPressed(event) {
	if (!event) event = window.event;
	if ((event.charCode < 48 || event.charCode > 57) & (event.charCode != 13)) return false;
}

