if(typeof pln=='undefined'){alert("class_toggle_control\nThis file required the PLN Javascript Library(pln.js)and it need to be loaded before this file.");}else if(typeof nvi=='undefined'){alert("class_toggle_control\nThis file required the NVI CORE(nvi.core.js)and it need to be loaded before this file.");}else if(typeof class_nvi_basic_panel=='undefined'){alert("class_toggle_control\nThis file required the Class Nvi Basic Panel and it need to be loaded before this file.");}else{function class_toggle_control(){var _host=this;var _event='click';var _constant={OPEN:{state:'OPEN',css:'toggle_open'},CLOSE:{state:'CLOSE',css:'toggle_close'},PARTIALLY_OPEN:{state:'PARTIALLY_OPEN',css:'toggle_partially_open'},DEACTIVATED:{state:'DEACTIVATED',css:'toggle_deactivated'}};var _state=_constant.CLOSE.state;var _localCollection={views:{},group:{}};var _default=false;var _displayParent=true;var _enable_cookie_state=false;this.__constructor=function(id){void __super.__constructor(id);};this.toString=function(){return "Nvi Toggle Control Class";};this.initialize=function(disableDeactivation){var enable=false;for(var viewId in _localCollection.views){try{if(pln.node.getLength(pln.node.getById(viewId))>0){enable=true;break;}}catch(error){}}var disableDeactivation=pln.isBoolean(disableDeactivation)?disableDeactivation:false;var element=this.getElement();var remove=pln.node.removeClassName;if(_state==_constant.OPEN.state)void remove(element,_constant.CLOSE.css);if(!enable&&!disableDeactivation){void remove(element,_constant.OPEN.css);void remove(element,_constant.CLOSE.css);void remove(element,_constant.PARTIALLY_OPEN.css);void pln.node.addClassName(element,_constant.DEACTIVATED.css);}else{class_toggle_control.collection.control[this.getId()]={instance:this,updateStatus:updateStatus};void pln.events.addListener(element,_event,this,this.toggle);if(_enable_cookie_state){var data=pln.cookie.get('toggle');if(pln.isset(data)){if(data[this.getId()]==_constant.OPEN.state){_default=true;_state=_constant.CLOSE.state;}}}if(_default){void this.toggle(null,true);if(!_enable_cookie_state&&_displayParent){var collection=class_toggle_control.collection.control;for(i in collection){var instance=collection[i].instance;if(instance!=this){var views=instance.getRegisteredViews();for(var j in views){if(pln.node.isChildOf(this.getElement(),pln.node.getById(j))){void instance.toggle(null,true);break;}}}}}}}__super.initialize();};this.terminate=function(){void pln.events.removeListener(this.getElement(),_event,this,this.toggle);};this.deleteInstance=function(){var id=this.getId();for(var i in _localCollection.group){var collection=class_toggle_control.collection.group[i];for(var j in collection){if(j!='closeAllView'&&j!='current'&&j!=id){var instance=nvi.panelManager.getInstance(j);if(pln.isObject(instance)&&instance!=this){void instance.toggle(null,true);break;}}}delete collection[id];}for(i in _localCollection.views)void pln.node.remove(pln.node.getById(i));void __super.deleteInstance();};this.animate;this.enable_cookie_state=function(enable){if(pln.isBoolean(enable))_enable_cookie_state=enable;};function inverseStatus(){var close=_constant.CLOSE.state;return _state==close||_state==_constant.PARTIALLY_OPEN.state?_constant.OPEN.state:close;};function displayViews(display,exception){var exception=pln.isObject(exception)?exception:{};if(pln.isBoolean(display)){for(var i in _localCollection.views){if(!pln.isset(exception[i])){class_toggle_control.collection.view[i].status=display?_constant.OPEN.state:_constant.CLOSE.state;if(pln.isFunction(_host.animate)){void _host.animate(i,display?'opening':'closing');}else{void pln.node.setProperty(i,'display',display?'block':'none');}void nvi.eventManager.dispatchEvent(_host.getId(),display?nvi.eventManager.events.__opened:nvi.eventManager.events.__closed);}}}};function changeGroupMemberStatus(){var id=_host.getId();for(var i in _localCollection.group){var group=class_toggle_control.collection.group[i];for(var j in group){if(j!=id){try{void group[j].displayViews(false,_localCollection.views);}catch(error){}}}}};function manageClassName(action){void pln.node[action+'ClassName'](_host.getElement(),_constant[_state].css);};function updateAllControls(){var collection=class_toggle_control.collection.control;for(i in collection){void collection[i].updateStatus();}};function updateStatus(){void manageClassName('remove');var closed=[];var opened=[];for(var i in _localCollection.views){var status=class_toggle_control.collection.view[i].status;(status==_constant.CLOSE.state?closed:opened).push(1);}if(closed.length==0)_state=_constant.OPEN.state;if(opened.length==0)_state=_constant.CLOSE.state;if(opened.length>0&&closed.length>0)_state=_constant.PARTIALLY_OPEN.state;void manageClassName('add');};function canCloseAll(){for(var i in _localCollection.group){if(!class_toggle_control.collection.group[i].closeAllView)return false;}return true;};function setCurrent(instance){for(var i in _localCollection.group){class_toggle_control.collection.group[i].current=instance;}};function getCurrent(){for(var i in _localCollection.group){return class_toggle_control.collection.group[i].current;}return null;};this.updateView=function(){};this.toggle=function(eventObject,display){var current=getCurrent();var display=pln.isBoolean(display)?display:null;if(((current==this&&_state==_constant.OPEN.state&&canCloseAll()==true)||(current==this&&_state==_constant.CLOSE.state))||current!=this||display!=null){void manageClassName('remove');if(pln.isBoolean(display)){_state=display?_constant.OPEN.state:_constant.CLOSE.state;void displayViews(display);}else{_state=inverseStatus();void displayViews(_state!=_constant.CLOSE.state);}if(_enable_cookie_state)void save_state(this.getId());void changeGroupMemberStatus();void updateAllControls();void setCurrent(this);}};function save_state(element_id){var data=pln.cookie.get('toggle');if(!pln.isset(data))data={};if(_state==_constant.OPEN.state){data[element_id]=_state;}else{for(i in _localCollection.views){var childs=pln.node.getByAttribute('id',pln.node.getById(i));while(childs.length>0){var id=childs.shift().id;try{if(nvi.panelManager.getInstance(id).toString()==_host.toString())delete data[id];}catch(error){}}}delete data[element_id];}void pln.cookie.set('toggle',data,99);};this.setAsDefault=function(displayParent){_default=true;if(pln.isBoolean(displayParent))_displayParent=displayParent;};this.setTriggerEvent=function(triggerEvent){if(pln.isString(triggerEvent))_event=triggerEvent;};this.assignView=function(viewId){var collection=class_toggle_control.collection.view;if(!pln.isset(collection[viewId])){collection[viewId]={status:_constant.CLOSE.state,motion:null};}if(pln.isString(viewId)&&!pln.isset(_localCollection.views[viewId])){_localCollection.views[viewId]={};}};this.getRegisteredViews=function(){return _localCollection.views;};this.registerToGroup=function(groupId){try{var collection=class_toggle_control.collection.group;var id=this.getId();if(!pln.isset(collection[groupId]))collection[groupId]={closeAllView:false,current:null};if(!pln.isset(collection[groupId][id])){collection[groupId][id]={instance:this,displayViews:displayViews};_localCollection.group[groupId]={};}else{nvi.logManager.log('The following control('+id+')is already registered to the following group:'+groupId,'Report','class_toggle_control','registerToGroup');}}catch(error){}};this.getSharedRessources=function(){return{type:'toggle',id:this.getId(),parameters:{complementaryData:this.getComplementaryDataObject()}};};this.duplicate=function(label){var set=pln.node.setProperty;var tempId='toggle_dynamic__'+pln.getUniqueId();var newViewId='view__'+tempId;var element=_host.getElement();void pln.events.removeListener(element,_event,this,this.toggle);var newTab=pln.node.duplicate(element);void pln.events.addListener(element,_event,this,this.toggle);void set(newTab,'id',tempId);var closeButton=pln.node.add(pln.node.create('div'),newTab);void set(closeButton,'innerHTML','[X]');function closeButtonHanlder(eventObject,$closeButton,$instanceId){void pln.events.removeListener($closeButton,'click',null,closeButtonHanlder,$closeButton,$instanceId);void nvi.panelManager.deleteInstance($instanceId);}void pln.events.addListener(closeButton,'click',null,closeButtonHanlder,closeButton,tempId);var labelElement=pln.node.getByAttributeValue('class','title',newTab);if(pln.isArray(labelElement))labelElement=labelElement[0];void set(labelElement,'innerHTML',label);var tempTab=nvi.panelManager.createInstance(tempId,class_toggle_control,true);var count=0;for(i in _localCollection.views){var newView=pln.node.duplicate(pln.node.getById(i));void set(newView,'id',newViewId+count);void tempTab.assignView(newViewId+count);count++;}for(i in _localCollection.group)tempTab.registerToGroup(i);void tempTab.initialize();void tempTab.toggle(null);};};class_toggle_control.collection={group:{},view:{},control:{}};class_toggle_control.enableCloseAllView=function(groupId){class_toggle_control.collection.group[groupId].closeAllView=true;};class_toggle_control.extend=class_nvi_basic_panel;}