// Namespace declaration (if it does not exist) : EV
if(typeof(EV)=='undefined'){ window.EV={}; }
// Namespace declaration (if it does not exist) : EV.ME
if(typeof(EV.ME)=='undefined'){ EV.ME={}; }

EV.ME.ErrorManager = function() {

	if(arguments.callee.singletonInstance){
		// si le singleton a été instancié on le retourne directement.
		return arguments.callee.singletonInstance;
	}
	
	// sinon, definition de l'instance
	arguments.callee.singletonInstance=this;
	
	var array=new Array();
	
	this.add=function(_error){
		if(_error==undefined) throw new Error("error is undefined");
		if(_error==null) throw new Error("error is null");
		if(!(_error instanceof EV.ME.Error)) throw new Error("error is not instance of EV.ME.Error");
		array.push(_error);

		if(_error.getLevel() == EV.ME.ErrorLevel.FATAL){//la recherche ne peut pas continuer, on fait part de l'erreur à l'internaute
			_error.print();
			throw new Error("ERREUR FATALE : " + " - " + _error.getMessageKey() + " - " + _error.getMessage());//on affiche une erreur
		}else{//le recherche peut quand même continuer, on peut avertir l'internaute qu'un problème mineur est survenu au cours de la recherche
			_error.print();
			throw new Error("ERREUR MINEUR : " + " - " + _error.getMessageKey() + " - " + _error.getMessage());//on affiche une erreur
		}
	
	}
	
	this.get=function(_index){
		if(_index>=array.length) return null;
		if(_index<0) return null;
		return array[_index];
	}
	
	this.clear=function() {
		array=new Array();
	}	
	
	this.getList=function() {
		return array;
	}
		
	return arguments.callee.singletonInstance;
}

// instanciation singleton
new EV.ME.ErrorManager();
