﻿//Search points of interest
function searchPoi(searchVal) {
	if(_map.GetMapStyle()==VEMapStyle.Birdseye || _map.GetMapStyle()==VEMapStyle.BirdseyeHybrid){
		alert('We’re sorry. Searching has not yet been made available by Microsoft® in Bird’s Eye View. Please, return to “Road” or “Aerial” views.');
		return;
		}
	
    // Check to see if listing layer exists
    if (typeof(_poiLayer)!="undefined")
    {
        // Delete all existing listing icons
        _poiLayer.DeleteAllShapes();
    }
    else
    {
        // Create listing layer
        _poiLayer = new VEShapeLayer();
        _map.AddShapeLayer(_poiLayer);
    }

    if(searchVal===undefined) {
        if($('txtPoiSearch').value!="") {
            results = _map.Find($('txtPoiSearch').value,null,null,_poiLayer,null,20,true,false,false,false,ShowResults); 
        }
    }
    else {
    results = _map.Find(searchVal,null,null,_poiLayer,null,20,true,false,false,false,ShowResults); 
    }
}

function ShowResults(a,findResults,c,d,e)
{	
	if(findResults!=null)
	{		
	      var shapeArray = [];	
	      var latLongArray = [];
          for (r=0; r<findResults.length; r++)
           {
            var Shape = new VEShape(VEShapeType.Pushpin, findResults[r].LatLong);
                Shape.SetTitle(findResults[r].Name); 
		        Shape.SetDescription(findResults[r].Description);
		        Shape.SetCustomIcon("../App_Themes/Default/Images/Map/icon_poi.gif");
		        shapeArray.push(Shape);
		        latLongArray.push(findResults[r].LatLong);
           }
           _poiLayer.AddShape(shapeArray);
           //_map.SetMapView(latLongArray);
          //document.getElementById('poiResults').innerHTML = findResults.length+' results found'; 
	} 
	else {document.getElementById('poiResults').innerHTML = '0 results found'; }         
}