/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","dojox.grid.enhanced.plugins._SelectionPreserver"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["dojox.grid.enhanced.plugins._SelectionPreserver"]){_4._hasResource["dojox.grid.enhanced.plugins._SelectionPreserver"]=true;_4.provide("dojox.grid.enhanced.plugins._SelectionPreserver");_4.declare("dojox.grid.enhanced.plugins._SelectionPreserver",null,{_connects:[],constructor:function(_7){this.selection=_7;var _8=this.grid=_7.grid;_8.onSelectedById=this.onSelectedById;this.reset();var _9=_8._clearData;var _a=this;_8._clearData=function(){_a._updateMapping(!_8._noInternalMapping);_a._trustSelection=[];_9.apply(_8,arguments);};this.connect(_8,"_setStore","reset");this.connect(_8,"_addItem","_reSelectById");this.connect(_7,"addToSelection",_4.hitch(this,"_selectById",true));this.connect(_7,"deselect",_4.hitch(this,"_selectById",false));this.connect(_7,"selectRange",_4.hitch(this,"_updateMapping",true,true,false));this.connect(_7,"deselectRange",_4.hitch(this,"_updateMapping",true,false,false));this.connect(_7,"deselectAll",_4.hitch(this,"_updateMapping",true,false,true));},destroy:function(){this.reset();_4.forEach(this._connects,_4.disconnect);delete this._connects;},connect:function(_b,_c,_d){var _e=_4.connect(_b,_c,this,_d);this._connects.push(_e);return _e;},reset:function(){this._idMap=[];this._selectedById={};this._trustSelection=[];this._defaultSelected=false;},_reSelectById:function(_f,_10){var s=this.selection,g=this.grid;if(_f&&g._hasIdentity){var id=g.store.getIdentity(_f);if(this._selectedById[id]===undefined){if(!this._trustSelection[_10]){s.selected[_10]=this._defaultSelected;}}else{s.selected[_10]=this._selectedById[id];}this._idMap.push(id);g.onSelectedById(id,_10,s.selected[_10]);}},_selectById:function(_11,_12){if(this.selection.mode=="none"||!this.grid._hasIdentity){return;}var _13=_12;if(typeof _12=="number"||typeof _12=="string"){var _14=this.grid._by_idx[_12];_13=_14&&_14.item;}if(_13){var id=this.grid.store.getIdentity(_13);this._selectedById[id]=!!_11;}else{this._trustSelection[_12]=true;}},onSelectedById:function(id,_15,_16){},_updateMapping:function(_17,_18,_19,_1a,to){var s=this.selection,g=this.grid,_1b=0,_1c=0,i,id;for(i=g.rowCount-1;i>=0;--i){if(!g._by_idx[i]){++_1c;_1b+=s.selected[i]?1:-1;}else{id=g._by_idx[i].idty;if(id&&(_17||this._selectedById[id]===undefined)){this._selectedById[id]=!!s.selected[i];}}}if(_1c){this._defaultSelected=_1b>0;}if(!_19&&_1a!==undefined&&to!==undefined){_19=!g.usingPagination&&Math.abs(to-_1a+1)===g.rowCount;}if(_19&&!g.usingPagination){for(i=this._idMap.length;i>=0;--i){this._selectedById[this._idMap[i]]=_18;}}}});}}};});