﻿// JScript File
        var locator = new esri.tasks.Locator(locatorURL);
        var locatorComplete_handler = dojo.connect(locator, "onAddressToLocationsComplete", showAddressResults);	
function locate() {
	//map.graphics.clear();
	var add = dojo.byId("address").value.split(",");
	var address = {
		//Address : add[0],
		Street: add[0],
		City: add[1],
		State: add[2],
		Zip: add[3]
	};
	//executeQueryTask(address,'geocoder');
	locator.outSpatialReference = map.spatialReference;
	locator.addressToLocations(address, ["Loc_name"]);
	dojo.byId('btnClear').style.visibility="visible";
}

function showAddressResults(candidates) {
	var candidate;
	  map.infoWindow.resize(250,75);
	var symbol = new esri.symbol.SimpleMarkerSymbol();
	var infoAddressTemplate = new esri.InfoTemplate("Your Requested Location", "Address: ${address}");
	//var infoAddressTemplate = new esri.InfoTemplate("Location", "Address: ${address}<br />Score: ${score}<br /><br /><br /> To clear geocoding results click <br />anywhere on the map away from the <br />geocoded point(s).");

	symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND);
	symbol.setColor(new dojo.Color([255, 0, 0, 0.75]));

	var points = new esri.geometry.Multipoint(map.spatialReference);

	for (var i = 0, il = candidates.length; i < il; i++) {
		candidate = candidates[i];

		if (candidate.score > 80) {
			var attributes = { address: candidate.address, score: candidate.score, locatorName: candidate.attributes.Loc_name, Lat: candidate.location.x, Long: candidate.location.y };
			var graphic = new esri.Graphic(candidate.location, symbol, attributes, infoAddressTemplate);
			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);
		}
	}
	var zoomExt = points.getExtent().expand(3);
	map.setExtent(zoomExt);
}

function submitenter(myfield,e)  {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13) {
       locate();
       dojo.byId('btnClear').style.visibility="visible";
    //   document.getElementById("btnClear").style.visibility.
       return false;
    }else return true;
}

function clickclear(thisfield, defaulttext) {
    if (thisfield.value == defaulttext) {
        thisfield.value = "";
    }
}

function clickrecall(thisfield, defaulttext) {
    if (thisfield.value == "") {
        thisfield.value = defaulttext;
    }
}

function clearMap(){
	map.graphics.clear();
	dojo.byId('btnClear').style.visibility="hidden";
	dojo.byId('address').value = "Address or intersection";
	
}

