/*
 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.route"]){dojo._hasResource["esri.tasks.route"]=true;dojo.provide("esri.tasks.route");dojo.require("esri.tasks.na");dojo.require("esri.tasks.gp");dojo.require("esri.utils");dojo.declare("esri.tasks.RouteTask",esri.tasks._Task,{constructor:function(_1){this._url.path+="/solve";this._handler=dojo.hitch(this,this._handler);},__msigns:[{n:"solve",c:3,a:[{i:0,p:["stops.features","barriers.features","polylineBarriers.features","polygonBarriers.features"]}],e:2}],_handler:function(_2,io,_3,_4,_5){try{var _6=[],_7=[],_8=_2.directions||[],_9=_2.routes?_2.routes.features:[],_a=_2.stops?_2.stops.features:[],_b=_2.barriers?_2.barriers.features:[],_c=_2.polygonBarriers?_2.polygonBarriers.features:[],_d=_2.polylineBarriers?_2.polylineBarriers.features:[],_e=_2.messages,_f="esri.tasks.RouteTask.NULL_ROUTE_NAME",_10=dojo.forEach,_11=dojo.indexOf,_12=true,_13,_14;_10(_8,function(dir){_6.push(_13=dir.routeName);_7[_13]={directions:dir};});_10(_9,function(_15){if(_11(_6,(_13=_15.attributes.Name))===-1){_6.push(_13);_7[_13]={};}_7[_13].route=_15;});_10(_a,function(_16){_14=_16.attributes;if(_11(_6,(_13=_14.RouteName||_f))===-1){_6.push(_13);_7[_13]={};}if(_13!==_f){_12=false;}if(_7[_13].stops===undefined){_7[_13].stops=[];}_7[_13].stops.push(_16);});if(_a.length>0&&_12===true){_7[_6[0]].stops=_7[_f].stops;delete _7[_f];_6.splice(dojo.indexOf(_6,_f),1);}var _17=[];_10(_6,function(_18,i){_7[_18].routeName=_18===_f?null:_18;_17.push(new esri.tasks.RouteResult(_7[_18]));});var _19=function(_1a){_10(_1a,function(_1b,i){_1a[i]=new esri.Graphic(_1b);});return _1a;};_10(_e,function(_1c,i){_e[i]=new esri.tasks.NAMessage(_1c);});var _1d={routeResults:_17,barriers:_19(_b),polygonBarriers:_19(_c),polylineBarriers:_19(_d),messages:_e};this._successHandler([_1d],"onSolveComplete",_3,_5);}catch(err){this._errorHandler(err,_4,_5);}},solve:function(_1e,_1f,_20,_21){var _22=_1e.stops;if(_22&&_22 instanceof esri.tasks.FeatureSet){var _23=[],_24=false,_25;dojo.forEach(_22.features,function(_26){_25=_26.attributes;if((!_25||!_25.RouteName)&&!_24){_24=true;}else{if(dojo.indexOf(_23,_25?_25.RouteName:"")===-1){_23.push(_25?_25.RouteName:"");}}});if(_23.length>1&&_24){_24=new Error(esri.bundle.tasks.na.route.routeNameNotSpecified);this.onError(_24);if(_20){_20(_24);}throw _24;}}var _27=_21.assembly,_28=this._encode(dojo.mixin({},this._url.query,{f:"json"},_1e.toJson(_27&&_27[0]))),_29=this._handler,_2a=this._errorHandler;return esri.request({url:this._url.path,content:_28,callbackParamName:"callback",load:function(r,i){_29(r,i,_1f,_20,_21.dfd);},error:function(r){_2a(r,_20,_21.dfd);}});},onSolveComplete:function(){}});esri._createWrappers("esri.tasks.RouteTask");dojo.declare("esri.tasks.RouteParameters",null,{accumulateAttributes:null,attributeParameterValues:null,barriers:null,directionsLanguage:null,directionsLengthUnits:null,directionsTimeAttribute:null,doNotLocateOnRestrictedElements:false,findBestSequence:null,ignoreInvalidLocations:null,impedanceAttribute:null,outputLines:null,outputGeometryPrecision:null,outputGeometryPrecisionUnits:null,outSpatialReference:null,polygonBarriers:null,polylineBarriers:null,preserveFirstStop:null,preserveLastStop:null,restrictionAttributes:null,restrictUTurns:null,returnBarriers:false,returnDirections:false,returnPolygonBarriers:false,returnPolylineBarriers:false,returnRoutes:true,returnStops:false,startTime:null,stops:null,useHierarchy:null,useTimeWindows:null,toJson:function(_2b){var _2c={returnDirections:this.returnDirections,returnRoutes:this.returnRoutes,returnStops:this.returnStops,returnBarriers:this.returnBarriers,returnPolygonBarriers:this.returnPolygonBarriers,returnPolylineBarriers:this.returnPolylineBarriers,attributeParameterValues:this.attributeParameterValues&&dojo.toJson(this.attributeParameterValues),outSR:this.outSpatialReference?(this.outSpatialReference.wkid||dojo.toJson(this.outSpatialReference.toJson())):null,outputLines:this.outputLines,findBestSequence:this.findBestSequence,preserveFirstStop:this.preserveFirstStop,preserveLastStop:this.preserveLastStop,useTimeWindows:this.useTimeWindows,startTime:this.startTime?this.startTime.getTime():null,accumulateAttributeNames:this.accumulateAttributes?this.accumulateAttributes.join(","):null,ignoreInvalidLocations:this.ignoreInvalidLocations,impedanceAttributeName:this.impedanceAttribute,restrictionAttributeNames:this.restrictionAttributes?this.restrictionAttributes.join(","):null,restrictUTurns:this.restrictUTurns,useHierarchy:this.useHierarchy,directionsLanguage:this.directionsLanguage,outputGeometryPrecision:this.outputGeometryPrecision,outputGeometryPrecisionUnits:this.outputGeometryPrecisionUnits,directionsLengthUnits:esri.tasks._NALengthUnit[this.directionsLengthUnits],directionsTimeAttributeName:this.directionsTimeAttribute},_2d=this.stops;if(_2d instanceof esri.tasks.FeatureSet&&_2d.features.length>0){_2c.stops=dojo.toJson({type:"features",features:esri._encodeGraphics(_2d.features,_2b&&_2b["stops.features"]),doNotLocateOnRestrictedElements:this.doNotLocateOnRestrictedElements});}else{if(_2d instanceof esri.tasks.DataLayer){_2c.stops=_2d;}}var _2e=function(_2f,_30){if(!_2f){return null;}if(_2f instanceof esri.tasks.FeatureSet){if(_2f.features.length>0){return dojo.toJson({type:"features",features:esri._encodeGraphics(_2f.features,_2b&&_2b[_30])});}else{return null;}}else{if(_2f instanceof esri.tasks.DataLayer){return _2f;}}return dojo.toJson(_2f);};_2c.barriers=_2e(this.barriers,"barriers.features");_2c.polygonBarriers=_2e(this.polygonBarriers,"polygonBarriers.features");_2c.polylineBarriers=_2e(this.polylineBarriers,"polylineBarriers.features");return esri.filter(_2c,function(_31){if(_31!==null){return true;}});}});dojo.declare("esri.tasks.RouteResult",null,{constructor:function(_32){if(_32.directions){var cgs=[];dojo.forEach(_32.directions.features,function(f,i){cgs[i]=f.compressedGeometry;});this.directions=new esri.tasks.DirectionsFeatureSet(_32.directions,cgs);}this.routeName=_32.routeName;if(_32.route){this.route=new esri.Graphic(_32.route);}if(_32.stops){var ss=(this.stops=[]);dojo.forEach(_32.stops,function(_33,i){ss[_33.attributes.Sequence-1]=new esri.Graphic(_33);});}},routeName:null,directions:null,route:null,stops:null});}