	/*
	 * Main function of this script. If the user clicks on the map, a php script
	 * is called via GET with the current clicked location. A CBRadar Object is initialized, with its
	 * position as the position clicked. The parameters scanwidth, scanheight are given in 
	 * kilometers, specifying the intial radar range. Since the scan is an autoscan,
	 * the radar will increase its scanrange automatically, as long as the scanrange is lower than
	 * the maximum allowed scan range
	 */ 

function getAndDrawLocation(lat, lon) {
	
	//scanwidth and scanheight are given in KILOMETERS
	$.get("cb/radar.php", { lat: lat, lon: lon, scanwidth: 0, scanheight: 0},
		function(data){
	    		result = JSON.parse(data);
	    		
	    		/* remove old markers, polygons from map */
	    		if(oldlocationid) removeLocation(oldlocationid);
	    		
	    		$('#nearby').hide();
	    		if( (result['status'] == 0) && (result['error'] == 0) ) {
	    			
	    			/** 
	    			 * if the server did not find a valid location, show the
	    			 * nearest location instead, and inform the user
	    			 */
	    			
	    			if(result['nearbyLocations'] == 'true') {
	    				$('#nearby').text(localizedStrings['Nearest Guide'][lang]);
	    				$('#nearby').show();
	    			}
	    			
	    			
	    			//get locationid
	    			var locationid = result['scanresults'][0]['locationid'];
	    			
					/**
					 * if the user clicks on the same object, don't
					  * calculate the subelements. Otherwise, the user clicked on a 
					  * new area, so extend the global object 'cbpolyItems'
					 */ 
	    			if(cbpolyItems[locationid] == null) extendCBPolyItems(result, locationid);

	    			//draw on map
					drawLocation(locationid, lat, lon);
					
					//fill guideDescription
	       			showGuideStatistics(locationid);

	    			/* 
					 * set oldlocationname = newlocationname 
					 * so that removal script will work for further clicks
					 */
	    			oldlocationid = locationid;
	    			
	    		}
	    		else {
	    			// Display message, that nothing has been found
	    			oldlocationid = null;
	    			showNoGuide();
		    	}			    		
	  	});
}

