﻿$(document).ready(function() {
    // geocoding
    var aLat = '<%=aLat%>';
    var aLong = '<%=aLong%>';
    var addrUrl = '<%=addrUrl%>';
    var myMap = new VEMap("myMap");
    myMap.LoadMap();

    if (aLat == 0 || aLong == 0) {
        myMap.Find(null,    // what
                  '<%=strAddr%>', // where
                  null,    // VEFindType (always VEFindType.Businesses)
                  null,    // 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)
                  null,    // set best map view? (default is true)
                  GeocodeCallback);  // call back function
    }
    else {
        //getWXC(aLong, aLat);
    }

});

function getWXC(longitude, latitude) {
    dataString = "longitude=" + longitude + "&amp;latitude=" + latitude;
    $.ajax({
        type: "POST",
        cache: false,
        // url: "http://www.amfam.com/api/agentsites/agentwxc.asp"
        url: "/agentwxc.asp",
        dataType: "html",
        data: dataString,
        async: false,
        processData: false,
        success: function(msg) { $('#wxc').html(msg) },
        error: function() { $('#wxc').html("error") }
    });
};

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 location = places[0].LatLong;
    //getWXC(location.Longitude, location.Latitude);
}
