// JavaScript Document
var map = null;
var counter = 1;
var addressResults;
		
function GetMap(){
	map = new VEMap('myMap');
	 
//Parameter Description 
//VELatLong A VELatLong object that represents the center of the map. Optional. 
//zoom The zoom level to display. Valid values range from 1 through 19. Optional. Default is 4. 
//style The map style. Valid values are a for aerial, h for hybrid, o for oblique (bird's eye), and r for road. Optional. Default is r. 
//fixed A Boolean value that specifies whether the map view is displayed as a fixed map that the user cannot change. Optional. Default is false. 

	map.LoadMap(new VELatLong(53.810135363828394,-1.5394538640976105), 3 ,'r' , false);
}

function addPin(Lat, Long, PropID, LinkAddress, Type){
	var pinID = counter;	

//	var pin = new VEPushpin(pinID, 
//			new VELatLong(Lat, Long), 
//			'http://www.flatsinleeds.com/images/house_icon.png',
//			'<a href="' + String(LinkAddress) +'">' + String(Type) + ' available for rental</a>',
//			'\nPlease click the link above to view the ' + String(Type) + ' details.'
//			);
	
	var pin = new VEPushpin(pinID, 
			new VELatLong(Lat, Long), 
			'/images/map/map-pointer-orange.png',
			'Ballet International Ltd',
			''
			);
	
	map.AddPushpin(pin);
	
	counter++;
}


function FindAddress(_address)
{
//	var address;
//	map.Find('',_address,'1',onFindResults);
	
	try         
	{            
		map.Find(null, _address);         
	}         
	catch(e)         
	{            
		alert(e.message);         
	} 
}

function GetInfo()         
{            
//	alert('The latitude,longitude at the center of the map is: '+map.GetCenter());  
	
	return map.GetCenter();
}


 
 
function onFindResults(findResults)
 {
 	addressResults = findResults;
	
	results="Find Results:\n";
	
	for (r=0; r < findResults.length; r++)
	{
	   if (findResults[r].ID!=null) //VESearchResult objects
	   {
		  results+=findResults[r].ID + ": " + findResults[r].LatLong+"\n";
	   }
	   else if (findResults[r].Name!=null) //VEFindResult objects
	   {
		  results += findResults[r].Name + ", ";
		  results += findResults[r].Description + ": ";
		  results += findResults[r].Phone + "\n";
	   }
	}
	alert(results);
 }

function ExtractCoordinates()
{
	var latLong;

	results="Find Results:\n";

	for (r=0; r < addressResults.length; r++)
	{
	   if (addressResults[r].ID!=null) //VESearchResult objects
	   {
		  results+=addressResults[r].ID + ": " + addressResults[r].LatLong+"\n";
	   }
	   else if (addressResults[r].Name!=null) //VEFindResult objects
	   {
		  results += addressResults[r].Name + ", ";
		  results += addressResults[r].Description + ": ";
		  results += addressResults[r].Phone + "\n";
	   }
	}

	var ctr = map.GetCenter();
	var lng = ctr.Longitude;
	var lat = ctr.Latitude;	

//	addPin(lat, lng);
	
	return String(lat) + ', ' + String(lng);
}
