function SearchCircle() {
	var Url = AbsPath + 'includes/Components/Map/Ajax.php';
	
	var CircleBounds = Circle.getBounds();

	var NorthEast = CircleBounds.getNorthEast();
	var SouthWest = CircleBounds.getSouthWest();
	
	var BoundsLeftLatitude = SouthWest.lat();
	var BoundsLeftLongitude = SouthWest.lng();
	var BoundsRightLatitude = NorthEast.lat();
	var BoundsRightLongitude = NorthEast.lng();
	
	$.ajax({
		type: "POST",
		url: Url,
		data: {Type: 'LatLng', Action: 'LatLng',
			BoundsLeftLatitude: BoundsLeftLatitude,
			BoundsLeftLongitude: BoundsLeftLongitude,
			BoundsRightLatitude: BoundsRightLatitude,
			BoundsRightLongitude: BoundsRightLongitude },
		dataType: "json",
		contentType: "application/x-www-form-urlencoded; charset=UTF-8;",
		timeout: 5000,
		error: function(){
			// nothing
		},
		success: function( Result ) {
			GetResults( 'Circle' );
		}
	});	
}

function SearchCountry( CountryID ) {
	var Url = AbsPath + 'includes/Components/Map/Ajax.php';
	$.ajax({
		type: "POST",
		url: Url,
		data: {Type: 'Country', Action: 'Country', ID: CountryID},
		dataType: "json",
		contentType: "application/x-www-form-urlencoded; charset=UTF-8;",
		timeout: 5000,
		error: function(){
			// nothing
		},
		success: function( Result ) {
			GetResults( 'Country' );
			var lat = Result["Latitude"];
			var lng = Result["Longitude"];
			var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));			
			Map.panTo( point );
		}
	});	
	
}

function GetResults( Type ) {
	var Filename = AbsPath + 'includes/Markers/xml.php';
	if( Type == 'Circle' ) {
		if( Circle != null ) {
			var CircleRadius = Circle.getRadius();
			var CircleCenter = Circle.getCenter();
			
			$.get(Filename, function(xml){
				$(xml).find("marker").each(function(){			
					// create a new LatLng point for the marker
					var lat = $(this).find('lat').text();
					var lng = $(this).find('lng').text();
					var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
					
					var Distance = google.maps.geometry.spherical.computeDistanceBetween(CircleCenter,point);
					
					if( Distance <= CircleRadius ) {
						var marker_id = $(this).find('marker_id').text();
						var marker = new google.maps.Marker({
							icon: MapMarkerIcon,
							position: point
						});
					    google.maps.event.addListener(marker, 'mouseover', function(event) {
							DisplayProduct(marker_id);
					      });
					    google.maps.event.addListener(marker, 'click', function(event) {
					    	//LocationDisplayProduct(marker_id);
					      });	
						Markers.push(marker);
					}
				});
				DisplayMarkers();
			});	
		} else {
			return true;
		}
	} else if( Type == 'Country' ) {
		$.get(Filename, function(xml){
			$(xml).find("marker").each(function(){
			
				// create a new LatLng point for the marker
				var lat = $(this).find('lat').text();
				var lng = $(this).find('lng').text();
				var marker_id = $(this).find('marker_id').text();
				var url = $(this).find('url').text();
				var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
					
				var marker = new google.maps.Marker({
							icon: MapMarkerIcon,
							position: point
				});
			    google.maps.event.addListener(marker, 'mouseover', function(event) {
					DisplayProduct(marker_id);
			      });
			    google.maps.event.addListener(marker, 'click', function(event) {
					//LocationProduct(marker_id);
			      });			
				Markers.push(marker);
			});
			DisplayMarkers();
		});	
	}	
}
