/*
 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
 */
//>>built
define("esri/dijit/Popup",["dojo/_base/declare","dojo/_base/lang","dojo/_base/array","dojo/_base/connect","dojo/_base/kernel","dojo/has","dojo/window","dojo/Stateful","dojo/query","dojo/dom","dojo/dom-attr","dojo/dom-class","dojo/dom-construct","dojo/dom-geometry","dojo/dom-style","dijit/registry","esri/kernel","esri/lang","esri/sniff","esri/domUtils","esri/geometry/Polyline","esri/geometry/Polygon","esri/InfoWindowBase","esri/PopupBase","dojo/i18n!esri/nls/jsapi","dojo/NodeList-dom","dojo/has!extend-esri?esri/dijit/PopupTemplate","dojo/has!extend-esri?esri/dijit/PopupRenderer"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b,_c,_d,_e,_f,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19){var _1a=_1([_17,_18,_8],{declaredClass:"esri.dijit.Popup",offsetX:3,offsetY:3,zoomFactor:4,marginLeft:25,marginTop:25,highlight:true,pagingControls:true,pagingInfo:true,keepHighlightOnHide:false,popupWindow:true,titleInBody:true,anchor:"auto",constructor:function(_1b,_1c){this.initialize();_2.mixin(this,_1b);this.domNode=_a.byId(_1c);var nls=this._nls=_2.mixin({},_19.widgets.popup);var _1d=this.domNode;_c.add(_1d,"esriPopup");this._isRTL=!_e.isBodyLtr();if(this._isRTL){_f.set(_1d,"direction","rtl");}var _1e="<div class='esriPopupWrapper' style='position: absolute;'>"+"<div class='sizer'>"+"<div class='titlePane'>"+"<div class='spinner hidden' title='"+nls.NLS_searching+"...'></div>"+"<div class='title'></div>"+"<div class='titleButton prev hidden' title='"+nls.NLS_prevFeature+"'></div>"+"<div class='titleButton next hidden' title='"+nls.NLS_nextFeature+"'></div>"+"<div class='titleButton maximize' title='"+nls.NLS_maximize+"'></div>"+"<div class='titleButton close' title='"+nls.NLS_close+"'></div>"+"</div>"+"</div>"+"<div class='sizer content'>"+"<div class='contentPane'>"+"</div>"+"</div>"+"<div class='sizer'>"+"<div class='actionsPane'>"+"<div class='actionList hidden'>"+"<a class='action zoomTo' href='javascript:void(0);'>"+nls.NLS_zoomTo+"</a>"+"</div>"+"</div>"+"</div>"+"<div class='pointer hidden'></div>"+"</div>"+"<div class='outerPointer hidden'></div>";_b.set(_1d,"innerHTML",_1e);this._sizers=_5.query(".sizer",_1d);var _1f=_5.query(".titlePane",_1d)[0];_a.setSelectable(_1f,false);this._title=_5.query(".title",_1f)[0];this._prevFeatureButton=_5.query(".prev",_1f)[0];this._nextFeatureButton=_5.query(".next",_1f)[0];this._maxButton=_5.query(".maximize",_1f)[0];this._spinner=_5.query(".spinner",_1f)[0];this._contentPane=_5.query(".contentPane",_1d)[0];this._positioner=_5.query(".esriPopupWrapper",_1d)[0];this._pointer=_5.query(".pointer",_1d)[0];this._outerPointer=_5.query(".outerPointer",_1d)[0];this._actionList=_5.query(".actionsPane .actionList",_1d)[0];this._eventConnections=[_4.connect(_5.query(".close",_1f)[0],"onclick",this,this.hide),_4.connect(this._prevFeatureButton,"onclick",this,this.selectPrevious),_4.connect(this._nextFeatureButton,"onclick",this,this.selectNext),_4.connect(this._maxButton,"onclick",this,this._toggleSize),_4.connect(_5.query(".zoomTo",this._actionList)[0],"onclick",this,this._zoomToFeature),_4.connect(this,"onClearFeatures",this,this._featuresCleared),_4.connect(this,"onSelectionChange",this,this._featureSelected),_4.connect(this,"onDfdComplete",this,this._updateUI)];if(_6("esri-touch")){var _20=_14.setScrollable(this._contentPane);this._eventConnections.push(_20[0],_20[1]);}this._toggleVisibility(false);},onMaximize:function(){},onRestore:function(){},setMap:function(map){this.inherited(arguments);_d.place(this.domNode,map.root);if(this.highlight){this.enableHighlight(map);}this._maxHeight=_f.get(this._contentPane,"maxHeight");},unsetMap:function(){this.disableHighlight(this.map);this.inherited(arguments);},setTitle:function(_21){if(!this.popupWindow){return;}if(!_12.isDefined(_21)||_21===""){_21="&nbsp;";}this.destroyDijits(this._title);this.place(_21,this._title);if(this.isShowing){this.startupDijits(this._title);this.reposition();}},setContent:function(_22){if(!this.popupWindow){return;}if(!_12.isDefined(_22)||_22===""){_22="&nbsp;";}this.destroyDijits(this._contentPane);this.place(_22,this._contentPane);if(this.isShowing){this.startupDijits(this._contentPane);this.reposition();}},show:function(_23,_24){if(!this.popupWindow){return;}if(!_23){this._toggleVisibility(true);return;}var map=this.map,_25;if(_23.spatialReference){this._location=_23;_25=map.toScreen(_23);}else{this._location=map.toMap(_23);_25=_23;}var _26=map._getFrameWidth();if(_26!==-1){_25.x=_25.x%_26;if(_25.x<0){_25.x+=_26;}if(map.width>_26){var _27=(map.width-_26)/2;while(_25.x<_27){_25.x+=_26;}}}if(this._maximized){this.restore();}else{this._setPosition(_25);}if(_24&&_24.closestFirst){this.showClosestFirst(this._location);}if(!this.isShowing){this._toggleVisibility(true);this._followMap();this.startupDijits(this._title);this.startupDijits(this._contentPane);this.reposition();this.showHighlight();this.onShow();}},hide:function(){if(this.isShowing){this._toggleVisibility(false);this._unfollowMap();if(!this.keepHighlightOnHide){this.hideHighlight();}this.onHide();}},resize:function(_28,_29){if(!this.popupWindow){return;}this._sizers.style({width:_28+"px"});_f.set(this._contentPane,"maxHeight",_29+"px");this._maxHeight=_29;if(this.isShowing){this.reposition();}},reposition:function(){if(!this.popupWindow){return;}if(this.map&&this._location&&!this._maximized&&this.isShowing){this._setPosition(this.map.toScreen(this._location));}},maximize:function(){var map=this.map;if(!map||this._maximized||!this.popupWindow){return;}this._maximized=true;var max=this._maxButton;_c.remove(max,"maximize");_c.add(max,"restore");_b.set(max,"title",this._nls.NLS_restore);var _2a=this.marginLeft,_2b=this.marginTop,_2c=map.width-(2*_2a),_2d=map.height-(2*_2b),_2e=this.domNode;_f.set(_2e,{left:this._isRTL?null:(_2a+"px"),right:this._isRTL?(_2a+"px"):null,top:_2b+"px",bottom:null});_f.set(this._positioner,{left:null,right:null,top:null,bottom:null});this._savedWidth=_f.get(this._sizers[0],"width");this._savedHeight=_f.get(this._contentPane,"maxHeight");this._sizers.style({width:_2c+"px"});_f.set(this._contentPane,{maxHeight:(_2d-65)+"px",height:(_2d-65)+"px"});this._showPointer("");this._unfollowMap();_c.add(this.domNode,"esriPopupMaximized");this.onMaximize();},restore:function(){var map=this.map;if(!map||!this._maximized||!this.popupWindow){return;}this._maximized=false;var max=this._maxButton;_c.remove(max,"restore");_c.add(max,"maximize");_b.set(max,"title",this._nls.NLS_maximize);_f.set(this._contentPane,"height",null);this.resize(this._savedWidth,this._savedHeight);this._savedWidth=this._savedHeight=null;this.show(this._location);this._followMap();_c.remove(this.domNode,"esriPopupMaximized");this.onRestore();},startup:function(){},destroy:function(){if(this.map){this.unsetMap();}this.cleanup();if(this.isShowing){this.hide();}this.destroyDijits(this._title);this.destroyDijits(this._content);_3.forEach(this._eventConnections,_4.disconnect);_d.destroy(this.domNode);this._sizers=this._contentPane=this._actionList=this._positioner=this._pointer=this._outerPointer=this._title=this._prevFeatureButton=this._nextFeatureButton=this._spinner=this._eventConnections=this._pagerScope=this._targetLocation=this._nls=this._maxButton=null;},selectNext:function(){this.select(this.selectedIndex+1);},selectPrevious:function(){this.select(this.selectedIndex-1);},setFeatures:function(){this.inherited(arguments);this._updateUI();},postscript:null,_highlightSetter:function(_2f){var _30=this.highlight,map=this.map;this.highlight=_2f;if(map&&_2f!==_30){if(_2f){this.enableHighlight(map);var _31=this.features&&this.features[this.selectedIndex];if(_31){this.updateHighlight(map,_31);this.showHighlight();}}else{this.disableHighlight(map);}}},_pagingControlsSetter:function(_32){var _33=this.pagingControls,map=this.map;this.pagingControls=_32;if(map&&_32!==_33){this._updatePagingControls();}},_pagingInfoSetter:function(_34){var _35=this.pagingInfo,map=this.map;this.pagingInfo=_34;if(map&&_34!==_35&&this.features&&this.features.length){this._updatePagingInfo();}},_popupWindowSetter:function(_36){var _37=this.popupWindow,map=this.map;this.popupWindow=_36;if(map&&_36!==_37){if(_36){this._updateUI();this._updateWindow();}else{this.hide();this.showHighlight();}}},_anchorSetter:function(_38){var _39=this.anchor;this.anchor=_38;if(this.map&&_38!==_39){this.reposition();}},_featuresCleared:function(){this.setTitle("&nbsp;");this.setContent("&nbsp;");this._setPagerCallbacks(this);this._updateUI();this.hideHighlight();},_featureSelected:function(){this._updateUI();this._updateWindow();},_updateWindow:function(){var ptr=this.selectedIndex;if(ptr>=0){var _3a=this.features[ptr].getContent(),_3b;if(!this.titleInBody&&_3a&&_2.isString(_3a.id)){_3b=_10.byId(_3a.id);if(_3b&&_3b.set&&/_PopupRenderer/.test(_3b.declaredClass)){_3b.set("showTitle",false);}}this.setContent(_3a);this.updateHighlight(this.map,this.features[ptr]);this.showHighlight();}},_toggleVisibility:function(_3c){this._setVisibility(_3c);this.isShowing=_3c;},_setVisibility:function(_3d){_f.set(this.domNode,"visibility",_3d?"visible":"hidden");},_followMap:function(){this._unfollowMap();var map=this.map;this._handles=[_4.connect(map,"onPanStart",this,this._onPanStart),_4.connect(map,"onPan",this,this._onPan),_4.connect(map,"onZoomStart",this,this._onZoomStart),_4.connect(map,"onExtentChange",this,this._onExtentChange)];},_unfollowMap:function(){var _3e=this._handles;if(_3e){_3.forEach(_3e,_4.disconnect);this._handles=null;}},_onPanStart:function(){var _3f=this.domNode.style;this._panOrigin={left:_3f.left,top:_3f.top,right:_3f.right,bottom:_3f.bottom};},_onPan:function(_40,_41){var _42=this._panOrigin,dx=_41.x,dy=_41.y,_43=_42.left,top=_42.top,_44=_42.right,_45=_42.bottom;if(_43){_43=(parseFloat(_43)+dx)+"px";}if(top){top=(parseFloat(top)+dy)+"px";}if(_44){_44=(parseFloat(_44)-dx)+"px";}if(_45){_45=(parseFloat(_45)-dy)+"px";}_f.set(this.domNode,{left:_43,top:top,right:_44,bottom:_45});},_onZoomStart:function(){this._setVisibility(false);},_onExtentChange:function(_46,_47,_48){if(_48){this._setVisibility(true);this.show(this._targetLocation||this._location);}this._targetLocation=null;},_toggleSize:function(){if(this._maximized){this.restore();}else{this.maximize();}},_setPosition:function(_49){var _4a=_49.x,_4b=_49.y,_4c=this.offsetX||0,_4d=this.offsetY||0,_4e=0,_4f=0,_50=_e.position(this.map.container,true),_51=_50.w,_52=_50.h,_53="Left",_54="bottom",_55=_e.getContentBox(this._positioner),_56=_55.w/2,_57=_55.h/2,_58=_f.get(this._sizers[0],"height")+this._maxHeight+_f.get(this._sizers[2],"height"),_59=_58/2,_5a=0,_5b=0,_5c=_51,_5d=_52,_5e=_4a,_5f=_4b,_60=this.anchor.toLowerCase();if(_60==="auto"){var _61=_7.getBox;if(_61){_61=_61();_5a=Math.max(_61.l,_50.x);_5c=Math.min(_61.l+_61.w,_50.x+_50.w);_5b=Math.max(_61.t,_50.y);_5d=Math.min(_61.t+_61.h,_50.y+_50.h);_5e+=_50.x;_5f+=_50.y;}var _62=((_5f-_5b)>_59),_63=((_5d-_5f)>=_59),_64=((_5c-_5e)>=_56),_65=((_5e-_5a)>_56),_66=((_5f-_5b)>=_58),_67=((_5d-_5f)>=_58),_68=((_5c-_5e)>=_55.w),_69=((_5e-_5a)>=_55.w);if(_62&&_63){if(_68){_54="";_53="Left";}else{if(_69){_54="";_53="Right";}}}if(_53&&_54){if(_65&&_64){if(_66){_53="";_54="bottom";}else{if(_67){_53="";_54="top";}}}}if(_53&&_54){if(_68&&_66){_53="Left";_54="bottom";}else{if(_68&&_67){_53="Left";_54="top";}else{if(_69&&_67){_53="Right";_54="top";}else{if(_69&&_66){_53="Right";_54="bottom";}}}}}}else{_54=_53="";if(_60.indexOf("top")!==-1){_54="bottom";}else{if(_60.indexOf("bottom")!==-1){_54="top";}}if(_60.indexOf("left")!==-1){_53="Right";}else{if(_60.indexOf("right")!==-1){_53="Left";}}}var _6a=_54+_53;switch(_6a){case "top":case "bottom":_4f=14;break;case "Left":case "Right":_4e=13;break;case "topLeft":case "topRight":case "bottomLeft":case "bottomRight":_4f=45;break;}_f.set(this.domNode,{left:_4a+"px",top:_4b+"px",right:null,bottom:null});var _6b={left:null,right:null,top:null,bottom:null};if(_53){_6b[_53.toLowerCase()]=(_4e+_4c)+"px";}else{_6b.left=(-_56)+"px";}if(_54){_6b[_54]=(_4f+_4d)+"px";}else{_6b.top=(-_57)+"px";}_f.set(this._positioner,_6b);this._showPointer(_6a);},_showPointer:function(_6c){_c.remove(this._pointer,["top","bottom","right","left","topLeft","topRight","bottomRight","bottomLeft","hidden"]);_c.remove(this._outerPointer,["right","left","hidden"]);if(_6c==="Right"||_6c==="Left"){_6c=_6c.toLowerCase();_c.add(this._outerPointer,_6c);}else{_c.add(this._pointer,_6c);}},_setPagerCallbacks:function(_6d,_6e,_6f){if(!this.pagingControls){return;}if(_6d===this&&(!this._pagerScope||this._pagerScope===this)){return;}if(_6d===this._pagerScope){return;}this._pagerScope=_6d;if(_6d===this){_6e=this.selectPrevious;_6f=this.selectNext;}var _70=this._eventConnections;_4.disconnect(_70[1]);_4.disconnect(_70[2]);if(_6e){_70[1]=_4.connect(this._prevFeatureButton,"onclick",_6d,_6e);}if(_6f){_70[2]=_4.connect(this._nextFeatureButton,"onclick",_6d,_6f);}},_getLocation:function(_71){var map=this.map,_72,_73,_74=0,_75,_76=_71&&_71.geometry;if(_76){switch(_76.type){case "point":_72=_76;break;case "multipoint":_72=_76.getPoint(0);_73=_76.getExtent();break;case "polyline":_72=_76.getPoint(0,0);_73=_76.getExtent();if(map._getFrameWidth()!==-1){_3.forEach(_76.paths,function(_77){var _78={"paths":[_77,map.spatialReference]},_79=new _15(_78),_7a=_79.getExtent(),_7b=Math.abs(_7a.ymax-_7a.ymin),_7c=Math.abs(_7a.xmax-_7a.xmin),_7d=(_7c>_7b)?_7c:_7b;if(_7d>_74){_74=_7d;_75=_7a;}});_75.spatialReference=_73.spatialReference;_73=_75;}break;case "polygon":_72=_76.getPoint(0,0);_73=_76.getExtent();if(map._getFrameWidth()!==-1){_3.forEach(_76.rings,function(_7e){var _7f={"rings":[_7e,map.spatialReference]},_80=new _16(_7f),_81=_80.getExtent(),_82=Math.abs(_81.ymax-_81.ymin),_83=Math.abs(_81.xmax-_81.xmin),_84=(_83>_82)?_83:_82;if(_84>_74){_74=_84;_75=_81;}});_75.spatialReference=_73.spatialReference;_73=_75;}break;}}return [_72,_73];},_zoomToFeature:function(){var _85=this.features,ptr=this.selectedIndex,map=this.map;if(_85){var _86=this._getLocation(_85[ptr]),_87=_86[0],_88=_86[1];if(!_87){_87=this._location;}if(!_88||!_88.intersects(this._location)){this._location=_87;}if(_88){map.setExtent(_88,true);}else{var _89=map.getNumLevels(),_8a=map.getLevel(),_8b=map.getMaxZoom(),_8c=this.zoomFactor||1;if(_89>0){if(_8a===_8b){return;}var _8d=_8a+_8c;if(_8d>_8b){_8d=_8b;}map.navigationManager._wheelZoom({value:(_8d-_8a),mapPoint:_87},true);}else{map.navigationManager._wheelZoom({value:(1/Math.pow(2,_8c))*2,mapPoint:_87},true);}}}},_updatePagingControls:function(){var _8e=this._prevFeatureButton,_8f=this._nextFeatureButton,ptr=this.selectedIndex,_90=this.features?this.features.length:0;if(this.pagingControls&&_90>1){if(ptr===0){_c.add(_8e,"hidden");}else{_c.remove(_8e,"hidden");}if(ptr===(_90-1)){_c.add(_8f,"hidden");}else{_c.remove(_8f,"hidden");}}else{_c.add(_8e,"hidden");_c.add(_8f,"hidden");}},_updatePagingInfo:function(){var _91=this.features?this.features.length:0,nls=this._nls,_92="&nbsp;",_93,_94,_95;if(this.pagingInfo&&_91>1&&nls.NLS_pagingInfo){_92=_12.substitute({index:this.selectedIndex+1,total:_91},nls.NLS_pagingInfo);}if(_91){_93=this.getSelectedFeature();_94=_93.getInfoTemplate();_95=_93.getTitle();if((!_94||/esri\.InfoTemplate/.test(_94.declaredClass)||!this.titleInBody)&&_95){_92=_95+((_92==="&nbsp;")?"":(" "+_92));}}this.setTitle(_92);},_updateUI:function(){if(!this.popupWindow){return;}var _96="&nbsp;",ptr=this.selectedIndex,_97=this.features,_98=this.deferreds,_99=_97?_97.length:0,_9a=this._spinner,_9b=this._actionList,nls=this._nls;this._updatePagingControls();this._updatePagingInfo();if(_98&&_98.length){if(_97){_c.remove(_9a,"hidden");}else{this.setContent("<div style='text-align: center;'>"+nls.NLS_searching+"...</div>");}}else{_c.add(_9a,"hidden");if(!_99){this.setContent("<div style='text-align: center;'>"+nls.NLS_noInfo+".</div>");}}if(_99){_c.remove(_9b,"hidden");}else{_c.add(_9b,"hidden");}}});if(_6("extend-esri")){_2.setObject("dijit.Popup",_1a,_11);}return _1a;});