﻿Type.registerNamespace("ATI.Ajax.Scripts");

ATI.Ajax.Scripts.GeoManager = function() {
    this._distances = new Array();
}

ATI.Ajax.Scripts.GeoManager.prototype =
{
    _geoServicePath: "/Trace/ATIGeoService.asmx"
    , _calculationFunctionName: "GetDistance"

    , _getDistanceParams: function(fromCity, toCity, viaCity) {
        return { "fromCity": fromCity, "toCity": toCity, "viaCity": viaCity };
    },

    _succeededCalculationHandler: function(distance, params) {
        if (params != null) {
            var succeededHandler = params["succeededHandler"];
            if (succeededHandler) {
                succeededHandler.call(null, distance);
            }
        }
    },

    calculateDistance: function(fromCity, toCity, viaCity, succeededHandler, failedHandler) {
        if (fromCity && toCity) {
            Sys.Net.WebServiceProxy.invoke(this._geoServicePath,
                this._calculationFunctionName,
                false, this._getDistanceParams(fromCity, toCity, viaCity ? viaCity : 0),
                this._succeededCalculationHandler, failedHandler,
                { "succeededHandler": succeededHandler }, 3000);
        }
        else {
            failedHandler.call(null, 'invalid distance arguments');
        }
    }

    , dispose: function() {
    }
}
ATI.Ajax.Scripts.GeoManager.registerClass('ATI.Ajax.Scripts.GeoManager', null, Sys.IDisposable);

var GeoManager = new ATI.Ajax.Scripts.GeoManager();

// Notify ScriptManager that this is the end of the script.
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();