var CONFIRM_REMOVE = false;

function GEvents() {
	var events = new Array();
	
	this.addEventListener = function(eventType, eventName, action) {
		if(!events[eventType]) {
			events[eventType] = new Array();
		} 
		events[eventType][eventName] = action;
	}

	this.removeEventListener = function(eventType, eventName) {
		if(events[eventType] && events[eventType][eventName]) {
			delete events[eventType][eventName];
		}
	}
	this.triggerEvent = function(eventName, object) {
		if(eventName == 'removelayer') {
			return this.onRemoveLayer(object);
		} else if(eventName == 'removeservice') {
			return this.onRemoveService(object);
		}
		var eventArray = events[eventName];
		for(var i in eventArray) {
			eventArray[i](object);
		}

	}

	this.onRemoveLayer = function(layerName) {
		var eventArray = events['removelayer'];
		if(!CONFIRM_REMOVE || confirm('Do you want to remove layer '+layerName+'?')) {
			for(var i in eventArray) {
				eventArray[i](layerName);
			}
			return true;
		} else {
			return false;
		}
		return false;
		
	}

	this.onRemoveService = function(serviceName) {
		var eventArray = events['removeservice'];
		if(!CONFIRM_REMOVE || confirm('Do you want to remove service '+serviceName+'?')) {
			for(var i in eventArray) {
				eventArray[i](serviceName);
			}
			return true;
		} else {
			return false;
		}
		
	}



	this.onLoadedMapbook = function(mapBookXML,objMap) {
		var eventArray = events['loadedmapbook'];
		for(var i in eventArray) {
			eventArray[i](mapBookXML, this, objMap);
		}

	}

	this.changePointScale = function(centerPoint, scale) {
		var circ = new Circle();
		circ.Radius = scale;
		circ.Center = centerPoint;
		this.triggerEvent('navigate',circ);
	}
}
