/*
 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
 */

window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","esri.arcgis.csv"],["require","dojox.data.CsvStore"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["esri.arcgis.csv"]){_4._hasResource["esri.arcgis.csv"]=true;_4.provide("esri.arcgis.csv");_4.require("dojox.data.CsvStore");(function(){var _7=esri.arcgis.csv;_7.latFieldStrings=["lat","latitude","y","ycenter","latitude83","latdecdeg","POINT-Y"];_7.longFieldStrings=["lon","lng","long","longitude","x","xcenter","longitude83","longdecdeg","POINT-X"];_7.buildCSVFeatureCollection=function(_8){var _9=new _4.Deferred();var _a=function(_b){_9.callback(_b);};var _c=esri.request({url:_8.url,handleAs:"text",load:function(_d){_7._processCsvData(_d,_8,_4.hitch(this,_a));},error:function(_e){console.error("error: "+_e);}},{usePost:false});return _9;};_7.projectFeatureCollection=function(_f,_10){var _11=new _4.Deferred();var _12=function(_13){_11.callback(_13);};_7._projectFeatureSet(_f,new esri.SpatialReference({wkid:4326}),_10,_4.hitch(this,_12));return _11;};_7.generateDefaultPopupInfo=function(_14){var _15=_14.layerDefinition.fields;var _16={"esriFieldTypeDouble":1,"esriFieldTypeSingle":1};var _17={"esriFieldTypeInteger":1,"esriFieldTypeSmallInteger":1};var dt={"esriFieldTypeDate":1};var _18=null;var _19=_4.map(_15,_4.hitch(this,function(_1a){if(_1a.name.toUpperCase()==="NAME"){_18=_1a.name;}var _1b=(_1a.type!=="esriFieldTypeOID"&&_1a.type!=="esriFieldTypeGlobalID"&&_1a.type!=="esriFieldTypeGeometry");var _1c=null;if(_1b){var f=_1a.name.toLowerCase();var _1d=",stretched value,fnode_,tnode_,lpoly_,rpoly_,poly_,subclass,subclass_,rings_ok,rings_nok,";if(_1d.indexOf(","+f+",")>-1||f.indexOf("area")>-1||f.indexOf("length")>-1||f.indexOf("shape")>-1||f.indexOf("perimeter")>-1||f.indexOf("objectid")>-1||f.indexOf("_")===f.length-1||(f.indexOf("_i")===f.length-2&&f.length>1)){_1b=false;}if(_1a.type in _17){_1c={places:0,digitSeparator:true};}else{if(_1a.type in _16){_1c={places:2,digitSeparator:true};}else{if(_1a.type in dt){_1c={dateFormat:"shortDateShortTime"};}}}}return _4.mixin({},{fieldName:_1a.name,label:_1a.alias,isEditable:true,tooltip:"",visible:_1b,format:_1c,stringFieldOption:"textbox"});}));var _1e={title:_18?"{"+_18+"}":"",fieldInfos:_19,description:null,showAttachments:false,mediaInfos:[]};return _1e;};_7._processCsvData=function(_1f,_20,_21){var _22=_1f.indexOf("\n");var _23=_4.trim(_1f.substr(0,_22));var _24=_20.columnDelimiter;if(!_24){_24=_7._getSeparator(_23);}var _25=new _6.data.CsvStore({data:_1f,separator:_24});var _26=(_4.isIE<9)?750:1001;_25.fetch({start:0,count:_26,onComplete:function(_27,_28){var _29=0;var _2a={"layerDefinition":_20.layerDefinition,"featureSet":{"features":[],"geometryType":"esriGeometryPoint"}};var _2b=_2a.layerDefinition.objectIdField;if(!_2b){if(!_4.some(_2a.layerDefinition.fields,function(_2c){if(_2c.type=="esriFieldTypeOID"){_2b=_2c.name;return true;}return false;})){_2a.layerDefinition.fields.push({"name":"__OBJECTID","alias":"__OBJECTID","type":"esriFieldTypeOID","editable":false,"domain":null});_2b="__OBJECTID";}}var _2d,_2e;var _2f=_25._attributes;var _30=[];var _31=[];_4.forEach(_2a.layerDefinition.fields,function(_32,_33){if(_32.type==="esriFieldTypeDate"){_30.push(_32.name);}else{if(_32.type==="esriFieldTypeDouble"||_32.type==="esriFieldTypeInteger"){_31.push(_32.name);}}});if(_20.locationInfo&&_20.locationInfo.locationType==="coordinates"){_2d=_20.locationInfo.latitudeFieldName;_2e=_20.locationInfo.longitudeFieldName;}else{_4.forEach(_2f,function(_34){var _35;_35=_4.indexOf(_7.latFieldStrings,_34.toLowerCase());if(_35!==-1){_2d=_34;}_35=_4.indexOf(_7.longFieldStrings,_34.toLowerCase());if(_35!==-1){_2e=_34;}},this);}if(!_2d||!_2e){setTimeout(function(){console.error("File does not seem to contain fields with point coordinates.");},1);return;}var i=0,il=_27.length;for(i;i<il;i++){if(_2a.featureSet.features.length>=1000){setTimeout(function(){console.error("1000 feature limit reached. Unable to load any more data.");},1);break;}var _36=_27[i];var _37=_25.getAttributes(_36),_38={};_4.forEach(_37,function(_39,_3a){if(_4.some(_30,function(a){return a===_39;})){var val=_25.getValue(_36,_39),_3b=new Date(val);_38[_39]=_7._isValidDate(_3b,val)?_3b.getTime():null;}else{if(_4.some(_31,function(a){return a===_39;})){var _3c=_4.number.parse(_25.getValue(_36,_39));if((_39==_2d||_39==_2e)&&(isNaN(_3c)||Math.abs(_3c)>181)){_3c=parseFloat(_25.getValue(_36,_39));if(isNaN(_3c)){_38[_39]=null;}else{_38[_39]=_3c;}}else{if(isNaN(_3c)){_38[_39]=null;}else{_38[_39]=_3c;}}}else{_38[_39]=_25.getValue(_36,_39);}}});_38[_2b]=_29;_29++;var _3d=_38[_2d];var _3e=_38[_2e];if(_3e==null||_3d==null||isNaN(_3d)||isNaN(_3e)){continue;}var _3f=new esri.geometry.Point(_3e,_3d,new esri.SpatialReference({wkid:4326}));var _40={"geometry":_3f.toJson(),"attributes":_38};_2a.featureSet.features.push(_40);}_2a.layerDefinition.name="csv";if(_21){_21(_2a);}},onError:function(_41){console.error("Error fetching items from CSV store: ",_41);}});return true;};_7._getSeparator=function(_42){var _43=[","," ",";","|","\t"];var _44=0;var _45="";_4.forEach(_43,function(_46){var _47=_42.split(_46).length;if(_47>_44){_44=_47;_45=_46;}});return _45;};_7._isValidDate=function(d,_48){if(!d||Object.prototype.toString.call(d)!=="[object Date]"||isNaN(d.getTime())){return false;}var _49=true;if(_4.isChrome&&/\d+\W*$/.test(_48)){var _4a=_48.match(/[a-zA-Z]{2,}/);if(_4a){var _4b=false,i=0,len=_4a.length,_4c=/^((jan(uary)?)|(feb(ruary)?)|(mar(ch)?)|(apr(il)?)|(may)|(jun(e)?)|(jul(y)?)|(aug(ust)?)|(sep(tember)?)|(oct(ober)?)|(nov(ember)?)|(dec(ember)?)|(am)|(pm)|(gmt)|(utc))$/i;while(!_4b&&(i<=len)&&!(_4b=!_4c.test(_4a[i]))){i++;}_49=!_4b;}}return _49;};_7._projectFeatureSet=function(_4d,_4e,_4f,_50){if(!_4d.featureSet||_4d.featureSet.length===0){return;}if(_7._sameSpatialReference(_4f,_4e)){_50(_4d);return;}var _51=function(_52){var _53=[];_4.forEach(_4d.featureSet.features,function(_54,i){if(_52[i]){_54.geometry=_52[i];_53.push(_54);}},this);_50(_4d);};var _55=function(_56,_57){console.error("error projecting featureSet ("+_4d.layerDefinition.name+"). Try one more time.");_7._projectGeometries(_58,_4d.featureSet.geometryType,_4e,_4f,_4.hitch(this,_51),_4.hitch(this,_59));};var _59=function(_5a,_5b){console.error("error projecting featureSet ("+_4d.layerDefinition.name+"). Final try.");_50(_4d);};if(_4d.featureSet.features&&_4d.featureSet.features.length>0){var _58=[];_4.forEach(_4d.featureSet.features,function(_5c){_58.push(_5c.geometry);});_7._projectGeometries(_58,_4d.featureSet.geometryType,_4e,_4f,_4.hitch(this,_51),_4.hitch(this,_55));}else{_50(_4d);}};_7._projectGeometries=function(_5d,_5e,_5f,_60,_61,_62){if(_5d.length===0){_61(null);}var _63=esri.geometry.getGeometryType(_5e);var _64=[];_4.forEach(_5d,function(_65){var _66=new _63(_65);_66.spatialReference=_5f;_64.push(_66);},this);var _67=[102113,102100,3857];if(_5f.wkid&&_5f.wkid===4326&&_60.wkid&&_4.indexOf(_67,_60.wkid)>-1){_4.forEach(_64,function(_68){if(_68.xmin){_68.xmin=Math.max(_68.xmin,-180);_68.xmax=Math.min(_68.xmax,180);_68.ymin=Math.max(_68.ymin,-89.99);_68.ymax=Math.min(_68.ymax,89.99);}else{if(_68.rings){_4.forEach(_68.rings,function(_69){_4.forEach(_69,function(_6a){_6a[0]=Math.min(Math.max(_6a[0],-180),180);_6a[1]=Math.min(Math.max(_6a[1],-89.99),89.99);},this);},this);}else{if(_68.paths){_4.forEach(_68.paths,function(_6b){_4.forEach(_6b,function(_6c){_6c[0]=Math.min(Math.max(_6c[0],-180),180);_6c[1]=Math.min(Math.max(_6c[1],-89.99),89.99);},this);},this);}else{if(_68.x){_68.x=Math.min(Math.max(_68.x,-180),180);_68.y=Math.min(Math.max(_68.y,-89.99),89.99);}}}}},this);_5d=[];_4.forEach(_64,function(_6d){var _6e=esri.geometry.geographicToWebMercator(_6d);if(_60.wkid!==102100){_6e.spatialReference=_60;}_5d.push(_6e.toJson());},this);_61(_5d);}else{if(_5f.wkid!==null&&_4.indexOf(_67,_5f.wkid)>-1&&_60.wkid!==null&&_60.wkid===4326){_5d=[];_4.forEach(_64,function(_6f){_5d.push(esri.geometry.webMercatorToGeographic(_6f).toJson());},this);_61(_5d);}else{var _70=function(_71,_72){if(_71&&_71.length===_5d.length){_5d=[];_4.forEach(_71,function(_73){if(_73&&((_73.rings&&_73.rings.length>0&&_73.rings[0].length>0&&_73.rings[0][0].length>0&&!isNaN(_73.rings[0][0][0])&&!isNaN(_73.rings[0][0][1]))||(_73.paths&&_73.paths.length>0&&_73.paths[0].length>0&&_73.paths[0][0].length>0&&!isNaN(_73.paths[0][0][0])&&!isNaN(_73.paths[0][0][1]))||(_73.xmin&&!isNaN(_73.xmin)&&_73.ymin&&!isNaN(_73.ymin))||(_73.x&&!isNaN(_73.x)&&_73.y&&!isNaN(_73.y)))){_5d.push(_73.toJson());}else{_5d.push(null);}},this);_61(_5d);}else{_62(_71,_72);}};if(esri.config.defaults.geometryService){esri.config.defaults.geometryService.project(_64,_60,_4.hitch(this,_70),_62);}else{_61(null);}}}};_7._sameSpatialReference=function(sp1,sp2){var _74=[102113,102100,3857];if(sp1&&sp2&&sp1.wkid===sp2.wkid&&sp1.wkt===sp2.wkt){return true;}else{if(sp1&&sp2&&sp1.wkid&&sp2.wkid&&_4.indexOf(_74,sp1.wkid)>-1&&_4.indexOf(_74,sp2.wkid)>-1){return true;}}return false;};}());}}};});