/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */

if(!dojo._hasResource["esri.tasks.closestfacility"]){dojo._hasResource["esri.tasks.closestfacility"]=true;dojo.provide("esri.tasks.closestfacility");dojo.require("esri.tasks._task");dojo.require("esri.tasks.na");dojo.declare("esri.tasks.ClosestFacilityTask",esri.tasks._Task,{constructor:function(_1){this._url.path+="/solveClosestFacility";this._handler=dojo.hitch(this,this._handler);},__msigns:[{n:"solve",c:3,a:[{i:0,p:["incidents.features","facilities.features","pointBarriers.features","polylineBarriers.features","polygonBarriers.features"]}],e:2}],_handler:function(_2,io,_3,_4,_5){try{var _6=new esri.tasks.ClosestFacilitySolveResult(_2);this._successHandler([_6],"onSolveComplete",_3,_5);}catch(err){this._errorHandler(err,_4,_5);}},solve:function(_7,_8,_9,_a){var _b=_a.assembly,_c=this._encode(dojo.mixin({},this._url.query,{f:"json"},_7.toJson(_b&&_b[0]))),_d=this._handler,_e=this._errorHandler;return esri.request({url:this._url.path,content:_c,callbackParamName:"callback",load:function(r,i){_d(r,i,_8,_9,_a.dfd);},error:function(r){_e(r,_9,_a.dfd);}});},onSolveComplete:function(){}});esri._createWrappers("esri.tasks.ClosestFacilityTask");dojo.declare("esri.tasks.ClosestFacilityParameters",null,{accumulateAttributes:null,attributeParameterValues:null,defaultCutoff:null,defaultTargetFacilityCount:null,directionsLanguage:null,directionsLengthUnits:null,directionsTimeAttribute:false,facilities:null,impedanceAttribute:null,incidents:null,outputGeometryPrecision:null,outputGeometryPrecisionUnits:null,outputLines:null,outSpatialReference:null,pointBarriers:null,polygonBarriers:null,polylineBarriers:null,restrictionAttributes:null,restrictUTurns:null,returnDirections:false,returnFacilities:false,returnIncidents:false,returnPointBarriers:false,returnPolylgonBarriers:false,returnPolylineBarriers:false,returnRoutes:true,travelDirection:null,useHierarchy:false,timeOfDay:null,timeOfDayUsage:null,toJson:function(_f){var _10={returnDirections:this.returnDirections,returnFacilities:this.returnFacilities,returnIncidents:this.returnIncidents,returnBarriers:this.returnPointBarriers,returnPolygonBarriers:this.returnPolygonBarriers,returnPolylineBarriers:this.returnPolylineBarriers,returnCFRoutes:this.returnRoutes,useHierarchy:this.useHierarchy,attributeParameterValues:this.attributeParameterValues&&dojo.toJson(this.attributeParameterValues),defaultCutoff:this.defaultCutoff,defaultTargetFacilityCount:this.defaultTargetFacilityCount,directionsLanguage:this.directionsLanguage,directionsLengthUnits:esri.tasks._NALengthUnit[this.directionsLengthUnits],directionsTimeAttributeName:this.directionsTimeAttribute,impedanceAttributeName:this.impedanceAttribute,outputGeometryPrecision:this.outputGeometryPrecision,outputGeometryPrecisionUnits:this.outputGeometryPrecisionUnits,outputLines:this.outputLines,outSR:this.outSpatialReference?(this.outSpatialReference.wkid||dojo.toJson(this.outSpatialReference.toJson())):null,restrictionAttributeNames:this.restrictionAttributes?this.restrictionAttributes.join(","):null,restrictUTurns:this.restrictUTurns,accumulateAttributeNames:this.accumulateAttributes?this.accumulateAttributes.join(","):null,travelDirection:this.travelDirection,timeOfDay:this.timeOfDay&&this.timeOfDay.getTime()};if(this.timeOfDayUsage){var _11;switch(this.timeOfDayUsage.toLowerCase()){case "start":_11="esriNATimeOfDayUseAsStartTime";break;case "end":_11="esriNATimeOfDayUseAsEndTime";break;default:_11=this.timeOfDayUsage;}_10.timeOfDayUsage=_11;}var _12=this.incidents;if(_12 instanceof esri.tasks.FeatureSet&&_12.features.length>0){_10.incidents=dojo.toJson({type:"features",features:esri._encodeGraphics(_12.features,_f&&_f["incidents.features"])});}else{if(_12 instanceof esri.tasks.DataLayer){_10.incidents=_12;}}var _13=this.facilities;if(_13 instanceof esri.tasks.FeatureSet&&_13.features.length>0){_10.facilities=dojo.toJson({type:"features",features:esri._encodeGraphics(_13.features,_f&&_f["facilities.features"])});}else{if(_13 instanceof esri.tasks.DataLayer){_10.facilities=_13;}}var _14=function(_15,_16){if(!_15){return null;}if(_15 instanceof esri.tasks.FeatureSet){if(_15.features.length>0){return dojo.toJson({type:"features",features:esri._encodeGraphics(_15.features,_f&&_f[_16])});}else{return null;}}else{if(_15 instanceof esri.tasks.DataLayer){return _15;}}return dojo.toJson(_15);};_10.barriers=_14(this.pointBarriers,"pointBarriers.features");_10.polygonBarriers=_14(this.polygonBarriers,"polygonBarriers.features");_10.polylineBarriers=_14(this.polylineBarriers,"polylineBarriers.features");return esri.filter(_10,function(_17){if(_17!==null){return true;}});}});dojo.declare("esri.tasks.ClosestFacilitySolveResult",null,{constructor:function(_18){if(_18.directions){this.directions=[];dojo.forEach(_18.directions,function(_19,idx){var cgs=[];dojo.forEach(_19.features,function(f,i){cgs[i]=f.compressedGeometry;});this.directions[idx]=new esri.tasks.DirectionsFeatureSet(_19,cgs);},this);}if(_18.routes){this.routes=this._graphicsFromJson(_18.routes);}if(_18.facilities){this.facilities=this._graphicsFromJson(_18.facilities);}if(_18.incidents){this.incidents=this._graphicsFromJson(_18.incidents);}if(_18.barriers){this.pointBarriers=this._graphicsFromJson(_18.barriers);}if(_18.polylineBarriers){this.polylineBarriers=this._graphicsFromJson(_18.polylineBarriers);}if(_18.polygonBarriers){this.polygonBarriers=this._graphicsFromJson(_18.polygonBarriers);}if(_18.messages){this.messages=dojo.map(_18.messages,function(_1a,i){return new esri.tasks.NAMessage(_1a);});}},routes:null,facilities:null,incidents:null,pointBarriers:null,polylineBarriers:null,polygonBarriers:null,directions:null,messages:null,_graphicsFromJson:function(_1b){var sr=new esri.SpatialReference(_1b.spatialReference);var _1c=_1b.features;return dojo.map(_1c,function(_1d,i){var _1e=new esri.Graphic(_1d);_1e.geometry.setSpatialReference(sr);return _1e;});}});}