var placeMarkerV = true;						//rakja ki a markert, ha valahova kattintott
var openInfoWindowV = true;						//nyissa meg az infowindowt, ha valahova kattintott
var onlyRoadV = false;							//Mindig ugorjon a legközelebbi útra, ha valahova kattintott
var clicked_latlng =null; 						// Utolsó pont
var clicked_marker =null; 						// Utolsó kitett marker
var lastInfoWindow = null;						// Utolsó megnyitott infoablak
var moveInfoWindow = null;						// Utolsó megnyitott move infoablak
var clickFoglalt=false;						// Van e érvényben lévő lekérés.

function changeMapMegj(opt,val){
	if(opt == 'info'){
		openInfoWindowV = val;
		if(val)
			getInfoContent('click','');
		else if(lastInfoWindow != null)
			lastInfoWindow.close(map);				
	}
	else if(opt == 'marker'){
		placeMarkerV = val;
		if(val)
			 placeMarker('reclick');
		else if(clicked_marker != null)
			clicked_marker.setMap(null);	
	}
	else if(opt == 'onlyroad'){
		onlyRoadV = val;
//		(val)? alert('true') : alert('false');	
	}	
}

function mapClickEvent(){
	closeAllScroll('all');
	if(openInfoWindowV){						//ha  kell infoWindow
		getInfoContent('click','');
	}
	else if(placeMarkerV){						//csak marker kell
		(onlyRoadV)? getRoadCoord('click') : placeMarker('click');	
					//megkeresni az utat 	//nem kell útra tenni 
	}	
	vszamlalo++;
	vmapclick++;
	if(vszamlalo == 5)
		setVisits();
}

function placeMarker(tip){
	if (tip == 'click' || tip == 'reclick') {
		if (clicked_marker == null || tip == 'reclick') {
			clicked_marker = new google.maps.Marker({
				position: clicked_latlng,
				map: map/*,
				title: "Utolsó kiválasztott pont" */
			});
//			Marker.set_draggable(true);

//			google.maps.event.addListener(clicked_marker, 'click', function(){
//				getInfoContent('new');
//			});
		}
		else
			clicked_marker.setPosition(clicked_latlng);
	}
}

function openInfowindow(tip,pont){
	if(tip == 'click'){
		if(lastInfoWindow == null){
			lastInfoWindow = new google.maps.InfoWindow({ 
				content: clickContent,
				position: clicked_latlng
			});		
		}
		else{
			lastInfoWindow.setContent(clickContent);
			lastInfoWindow.setPosition(clicked_latlng);
		}
		if(placeMarkerV )
			placeMarker('click');				//marker is kell, 

		lastInfoWindow.open(map);		
	}	
	else if(tip == 'move'){
		if(moveInfoWindow == null){
			moveInfoWindow = new google.maps.InfoWindow({ 
				content: moveContent,
				position: pont
			});		
		}
		else{
			moveInfoWindow.setContent(moveContent);
			moveInfoWindow.setPosition(pont);
		}
		moveInfoWindow.open(map);		
	}
	else if(tip == 'new'){	
		var otherInfoWindow = new google.maps.InfoWindow({ 
			content: clickContent,
//			size: new google.maps.Size(50,50),
			position: clicked_latlng
		});		
		otherInfoWindow.open(map);
	}			
}

/*
//markerek kezelése
google.maps.Map.prototype.markers = new Array();

google.maps.Map.prototype.addMarker = function(marker) {
    this.markers[this.markers.length] = marker;
};


google.maps.Map.prototype.getMarkers = function() {
    return this.markers;
};

google.maps.Map.prototype.clearMarkers = function() {
    for(var i=0; i<this.markers.length; i++){
        this.markers[i].setMap(null);
    }
    this.markers = new Array();
};

google.maps.Marker.prototype._setMap = google.maps.Marker.prototype.setMap;

google.maps.Marker.prototype.setMap = function(map) {
    if (map) {
        map.markers[map.markers.length] = this;
    }
    this._setMap(map);
}
*/
