	function Event(EventName)
	{
		var _Name;
		var _EventHandlers;

		_Name = EventName;
		_EventHandlers = new Collection();

		function FindEventHandler(CallbackFunction)
		{
			return _EventHandlers.Find(CallbackFunction);
		}

		function AddHandler(CallbackFunction)
		{
			return _EventHandlers.Add(CallbackFunction);
		}


		function RemoveHandler(CallbackFunction)
		{
			_EventHandlers.RemoveObject(CallbackFunction);
		}
			
		function Raise(Param)
		{
			var i;
			for (i=0; i<_EventHandlers.Count(); i++)
				_EventHandlers.Item(i)(Param);
		}
		
		this.Name = _Name;
		this.EventHandlers = _EventHandlers;
		this.FindEventHandler = FindEventHandler;
		this.AddHandler = AddHandler;
		this.RemoveHandler = RemoveHandler;
		this.Raise = Raise;
	}
	
	
	function EventManager()
	{
		var _Events;
	
		_Events = new Collection();

		function RaiseEvent(Namespace, EventItem, Data)  
		{
			var objEvent;
			var EventName;

			EventName = Namespace + "::" + EventItem;
			objEvent = _Events.FindByName(EventName);
			if (objEvent == null)
				return;
			else
				objEvent.Raise(Data);
		}
							
		function RegisterForEvent(Namespace, EventItem, CallbackFunction)
		{
			var objEvent;
			var EventName;

			EventName = Namespace + "::" + EventItem;
			objEvent = _Events.FindByName(EventName);
			if (objEvent == null)
			{
				objEvent = new Event(EventName);
				_Events.Add(objEvent);
			}
			else
			{
				if (objEvent.FindEventHandler(CallbackFunction) != null)
					return;
			}

			objEvent.AddHandler(CallbackFunction);
		}


		function UnRegisterForEvent(Namespace, EventItem, CallbackFunction)
		{
			var objEvent;
			var EventName;

			EventName = Namespace + "::" + EventItem;
			objEvent = _Events.FindByName(EventName);
			if (objEvent == null || objEvent.FindEventHandler(CallbackFunction) == null)
				return;

			objEvent.RemoveHandler(CallbackFunction);
		}
		
		this.RegisterForEvent = RegisterForEvent;
		this.RaiseEvent = RaiseEvent;
		this.UnRegisterForEvent = UnRegisterForEvent;
	}
	
	
	
	function AvailableInfos(InfosName,fnHandler)
	{
		var _Name;
		var _Handlers;

		_Name = InfosName;
		_Handlers = fnHandler;

		this.Name = _Name;
		this.Handler = _Handlers;
	}
	
	function AvailableInfosManager()
	{
		var _AvailableInfos = new Collection();
		
		
		function RegisterForAvailableInfos(Namespace, InfosItem, CallbackFunction)
		{
			var obj;
			var InfosName;

			InfosName = Namespace + "::" + InfosItem;
			obj = _AvailableInfos.FindByName(InfosName);
			if (obj == null)
			{
				obj = new AvailableInfos(InfosName,CallbackFunction);
				_AvailableInfos.Add(obj);
			}
			
		}

		function UnRegisterForAvailableInfos(Namespace, InfosItem)
		{
			var obj;
			var InfosName;

			InfosName = Namespace + "::" + InfosItem;
			_AvailableInfos.RemoveByName(InfosName);

		}
		
		function RequestAvailableInfos(Namespace, InfosItem)
		{
			var obj;
			var InfosName;

			InfosName = Namespace + "::" + InfosItem;
			obj = _AvailableInfos.FindByName(InfosName);
			if( obj != null )
				return obj.Handler;
			return null;
		}
		
		this.RegisterForAvailableInfos = RegisterForAvailableInfos;
		this.UnRegisterForAvailableInfos = UnRegisterForAvailableInfos;		
		this.RequestAvailableInfos = RequestAvailableInfos;
		
	}
		
	
	
	function ProvidersManager()
	{
		var _MEvent;
		var _MAvailableInfos;
		
		_MEvent = new EventManager();
		_MAvailableInfos = new AvailableInfosManager();
		
		
		function SetCookie(Name, Value)
		{
		  	document.cookie = Name + "=" + escape(Value);
		}
		

		function GetCookie(Name)
		{

		  	var aCookie = document.cookie.split(";");
		  	for (var i=0; i < aCookie.length; i++)
		  	{
		    		var aCrumb = aCookie[i].split("=");
		    		var sCookie = Trim(aCrumb[0]);
		    		if (Name == sCookie) 
		      			return unescape(aCrumb[1]);
		  	}
		  	return null;
		}
		
		
		function RegisterEvent(Namespace, EventItem, CallBackFunction )
		{
			_MEvent.RegisterForEvent(Namespace,EventItem,CallBackFunction);			
		}
		
		function UnRegisterEvent(Namespace,EventItem,CallBackFunction )
		{
			_MEvent.UnRegisterForEvent(Namespace,EventItem,CallBackFunction);	
		}
		
		function RaiseEvent(Namespace,EventItem,Data)
		{
			_MEvent.RaiseEvent(Namespace, EventItem, Data);
		}
		
		
		function RegisterAvailableInfos(Namespace, InfosItem, CallbackFunction)
		{
			_MAvailableInfos.RegisterForAvailableInfos(Namespace, InfosItem, CallbackFunction)
			
		}

		function UnRegisterAvailableInfos(Namespace, InfosItem)
		{
			_MAvailableInfos.UnRegisterForAvailableInfos(Namespace, InfosItem)

		}
		
		function RequestAvailableInfos(Namespace, InfosItem)
		{
			return _MAvailableInfos.RequestAvailableInfos(Namespace, InfosItem)
		}		

		this.SetCookie = SetCookie;
		this.GetCookie = GetCookie;
		this.RegisterEvent = RegisterEvent;
		this.UnRegisterEvent = UnRegisterEvent;
		this.RaiseEvent = RaiseEvent;
		this.RegisterAvailableInfos = RegisterAvailableInfos;
		this.UnRegisterAvailableInfos = UnRegisterAvailableInfos;		
		this.RequestAvailableInfos = RequestAvailableInfos;
}	


	//**************MAIN******************

	var Provider = new ProvidersManager();
	
	function RegisterEvent(Namespace, EventItem, CallBackFunction)
	{
		Provider.RegisterEvent(Namespace,EventItem,CallBackFunction);
	}
	
	function UnRegisterEvent(Namespace,EventItem,CallBackFunction)
	{
		Provider.UnRegisterEvent(Namespace,EventItem,CallBackFunction);	
	}
	
	function RaiseEvent(Namespace,EventItem,Data)
	{
		Provider.RaiseEvent(Namespace, EventItem, Data);
	}
	
	
	function RegisterApplicationEvent(Namespace, EventItem, CallBackFunction)
	{
		RegisterEvent(Namespace, EventItem, CallBackFunction);
		if( HasWindowOpener() && window.opener.RegisterApplicationEvent != undefined )
		{
			window.opener.RegisterApplicationEvent(Namespace,EventItem,CallBackFunction);
		}
	}				
	
	
	function UnRegisterApplicationEvent(Namespace,EventItem,CallBackFunction)
	{
		UnRegisterEvent(Namespace,EventItem,CallBackFunction);	
		if( HasWindowOpener() && window.opener.UnRegisterApplicationEvent != undefined )
		{
			window.opener.UnRegisterApplicationEvent(Namespace,EventItem,CallBackFunction);	
		}					
	}
	
	function RaiseApplicationEvent(Namespace,EventItem,Data)
	{
		RaiseEvent(Namespace,EventItem,Data);
		if( HasWindowOpener() && window.opener.RaiseApplicationEvent != undefined )
		{
			window.opener.RaiseApplicationEvent(Namespace,EventItem,Data);
		}						
	}				
	
	
	function RegisterAvailableInfos(Namespace, EventItem, CallBackFunction )
	{
		Provider.RegisterAvailableInfos(Namespace,EventItem,CallBackFunction);			
	}
	
	function UnRegisterAvailableInfos(Namespace,EventItem)
	{
		Provider.UnRegisterAvailableInfos(Namespace,EventItem);	
	}
	
	function RequestAvailableInfos(Namespace,EventItem)
	{
		var func = null;
		func = Provider.RequestAvailableInfos(Namespace, EventItem);
		
		if( func == null )
		{
			if( HasWindowOpener() && window.opener.RequestAvailableInfos != undefined )
				func = window.opener.RequestAvailableInfos(Namespace, EventItem);
		}
		return func;
	}	 						
