﻿function findAddress(address, location, link, center) {

	var shape = new VEShapeLayer();
	shape.SetTitle(location);

	var html = "<table>" +
			 "<tr><td style=\"text-transform: uppercase; font-weight: bold;\">" + location + "</td></tr>" +
			 "<tr><td width=\"90%\">" + address + "</td><td width=\"10%\"></td></tr>" +
			 "<tr><td><a href=\"" + link + "\">More Info</a></td></tr>" +
			 "</table>";

	shape.SetDescription(html);

	map.Find(null,    // what
              address, // where
              null,    // VEFindType (always VEFindType.Businesses)
              shape,    // VEShapeLayer (base by default)
              null,    // start index for results (0 by default)
              null,    // max number of results (default is 10)
              null,    // show results? (default is true)
              null,    // create pushpin for what results? (ignored since what is null)
              null,    // use default disambiguation? (default is true)
              center,    // set best map view? (default is true)
              GeocodeCallback);  // call back function
}

function GeocodeCallback(shapeLayer, findResults, places, moreResults, errorMsg) {
	// if there are no results, display any error message and return
	if (places == null) {
		alert((errorMsg == null) ? "There were no results" : errorMsg);
		return;
	}

	var place = places[0];

	// Add pushpin to the *best* place
	var location = place.LatLong;

	// Create a pin at that location, list the latitude & longitude
	var pin = new VEShape(VEShapeType.Pushpin, location);
	pin.SetCustomIcon("<img src='../Content/Resources/Common/Images/spelling_bee_map_icon.gif'/>");
	//pin.SetTitle(shapeLayer.GetTitle());
	pin.SetDescription(shapeLayer.GetDescription());

	map.AddShape(pin);
}
