var NetManagerBase = new Class({
	
	options: {
		formatterSourceElm: 'title',
		formatterTargetElm: 'url_segment'
	},
	
	wizards: [],
	accordions: [],
	forms: [],
	dropdowns: [],
	imageSelectors: [],
	tableHandlers: [],
	tableHandlerKeys: [],
	translate: null,
	
	wizardInstanceCounter: 0,
	accordionInstanceCounter: 0,
	formInstanceCounter: 0,
	dropdownInstanceCounter: 0,
	imageSelectInstanceCounter: 0,
	tableHandlerInstanceCounter: 0,
	
	initialize: function(options) {
		this.setOptions(options);
		this.oAjax = new NetManagerPluginAjax();
	},
	
	formatUrl: function(e) {
		var targetElm = $(e.target.form).getElement('#' + this.options.formatterTargetElm);
		$(targetElm).setProperty('value', $(e.target).getProperty('value').clean().replace(/[^a-z0-9 ]/ig,'-').replace(/ /g, '-'));
	},
	
	getWizard: function(key) {
		if (!$defined(this.wizards.key)) {
			this.wizardInstanceCounter++;
			this.wizards.key = new NetManagerPluginWizard({zindex:this.wizards.length + 101, instanceId:this.wizardInstanceCounter});	
			return this.wizards.key;
		} else {
			return this.wizards.key;
		}
		return false;
	},
	
	getDropdown: function(options) {
		
		
			var ddKey = options.key;
			this.dropdownInstanceCounter++;
			this.dropdowns[options.key] = new NetManagerPluginDropdown({zindex         : 100 - this.dropdownInstanceCounter, 
																	    instanceId     : this.dropdownInstanceCounter,
																	    selectId       : options.selectId,
																	    icon	       : options.icon,
																	    containerWidth : options.containerWidth,
																	    width	       : options.width,
																		optEvent       : options.fnEvent,
																		container      : options.container});	
			return this.dropdowns[options.key];
		
				
		/*
		var ddKey = options.key;
		if (!$defined(this.dropdowns[options.key])) {
			this.dropdownInstanceCounter++;
			this.dropdowns[options.key] = new NetManagerPluginDropdown({zindex     : 100 - this.dropdownInstanceCounter, 
																	    instanceId : this.dropdownInstanceCounter,
																	    selectId   : options.selectId,
																	    width	   : options.width,
																		optEvent   : options.fnEvent});	
			return this.dropdowns[options.key];
		} else {
			return this.dropdowns[options.key];
		}
		return false;*/
	},
	
	getForm: function(key) {
		if (!$defined(this.forms.key)) {
			this.formInstanceCounter++;
			this.forms.key = new NetManagerPluginForm({instanceId:this.formInstanceCounter});	
			
			return this.forms.key;
		} else {
			return this.forms.key;
		}
		return false;
	},
	
	getAccordion: function(key) {
		if (!$defined(this.accordions.key)) {
			this.accordionInstanceCounter++;
			this.accordions.key = new NetManagerPluginAccordion({zindex:this.accordions.length + 101, instanceId:this.accordionInstanceCounter});	
			
			return this.accordions.key;
		} else {
			return this.accordions.key;
		}
		return false;
	},
	
	getTableHandler: function(key, options) {
		this.tableHandlerKeys.push(key);
		if (this.tableHandlerKeys.contains(key)) {
			this.tableHandlerInstanceCounter++;
			this.tableHandlers.key = new NetManagerPluginTable({instanceId: this.tableHandlerInstanceCounter, 
																tableId: options.tableId,
																overCls: options.hover, 
																popUp: options.popUp});	
			return this.tableHandlers.key;
		} else {
			return this.tableHandlers.key;
		}
		return false;
	},
	
	getImageSelector: function(options) {
		if (!$defined(this.imageSelectors[options.key])) {
			this.imageSelectInstanceCounter++;
			this.imageSelectors[options.key] = new NetManagerPluginImageSelect({instanceId     : this.imageSelectInstanceCounter,
																	    		selectId       : options.selectId});	

			return this.imageSelectors[options.key];
		} else {
			return this.imageSelectors[options.key];
		}
		return false;
	},
	
	getTranslations: function () {
    return this.translate;
  },
	
	showOverlay: function(sType) {
		
		// Create the transparent overlay
		var oOverlay = new Element('div').setProperty('id', 'transOverlay');
			
		oOverlay.addClass('loadingOverlay');
		
		var oText = new Element('p').setStyle('margin-top', (window.getHeight()/2 + 30)).setText('Een ogenblik geduld a.u.b.').inject(oOverlay);
		
		// Inject the overlay into the DOM
		oOverlay.inject(document.body);
	},
	
	hideOverlay: function() {
		
		if($defined($('transOverlay'))) {
			
			// Remove the overlay from the DOM
			$ES('#transOverlay').getLast().remove();
		}
	},
	
	redirect: function(url) {
		document.location.href=url;
	},
 
	stripSlashes: function(str){
		return (str) ? str.replace(/\\("|'|\\|\0)/g, '$1') : '';
	}

	
});

NetManagerBase.implement(new Options);