﻿// JScript File

function locate() {
        map.graphics.clear();
        var add = dojo.byId("address").value.split(",");
            var address = {
              Street : add[0]
            };
        locator.addressToLocations(address);
        document.getElementById('btnClear').style.visibility="visible";
}

function showResults(candidates) {
    var foundOne;
    var candidate;
    var symbol = new esri.symbol.SimpleMarkerSymbol();
    var infoTemplate = new esri.InfoTemplate("Your Requested Location", "Address: ${address}");

    symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND);
    symbol.setColor(new dojo.Color([0,0,255,0.75]));

    var points =  new esri.geometry.Multipoint(map.spatialReference);

    foundOne = 0;

    for (var i=0, il=candidates.length; i<il; i++) {
     
      candidate = candidates[i];
          if (candidate.score > 60) {
console.log(candidate.address + "  " + candidate.cityname);
console.log(candidate);
            foundOne = 1
            var attributes = { address: candidate.address, score:candidate.score };
            var graphic = new esri.Graphic(candidate.location, symbol, attributes, infoTemplate);
            map.graphics.add(graphic);
            map.graphics.add(new esri.Graphic(candidate.location, new esri.symbol.TextSymbol(attributes.address).setOffset(0, 8)));
            points.addPoint(candidate.location);
          }
    }
          map.infoWindow.resize(250,75);
    if (foundOne == 0) {
        alert ("No addresses found");
    }
    map.setExtent(points.getExtent().expand(4));
}