// JavaScript Document

//-----------------<EVENTS>----------------------\\
function Events(owner){
	if(!owner){alert("Events.Constructor, Fetal Error:can't create events with null owner");return;}
	this.iList=IList;
	this.iList(owner);
	this.append=function(objEvent){
		objEvent.construct(this);
		this.add(objEvent);
	};
	
	this.addListener=function(strEvtName,strSubscriber,funAction){
		//search for the event
		objEvent=this._(strEvtName);
		if(!objEvent){alert("Events.addListener Error:can't find the event ("+strEvtName+")");return false}
		var x=objEvent.indexOf(strSubscriber);
		if(x!=-1){objEvent.removeAt(x)}
		objEvent.add({name:strSubscriber,action:funAction});
		return true;
	};
	this.removeListner=function(strEvtName,strSubscriber){
		objEvent=this._(strEvtName);
		if(!objEvent){alert("Events.removeListener Error:can't find the event ("+strEvtName+")");return false}
		if(objEvent.indexOf(strSubscriber)==-1){alert("Events.removeListener Warning:"+strSubscriber+" not registerd in "+strEvtName)}
		objEvent.remove(strSubscriber);
		return true;
	};
	this.dispatch=function(strEvtName){
		this.temp=this._(strEvtName);
		if(!this.temp){alert("Events.dispatch Error:can't find the event ("+strEvtName+")");return false}
		this.temp.moveFirst();
		for(;!this.temp.atEnd();this.temp.moveNext()){
			this.temp.current().action(this.owner,this.temp.args);
		}
		return true;
	};
};
//-----------------<Event>----------------------------\\
function Event(strName,objArgs){
	if(!strName){alert("Event.constructor Error:can't create Event without name");return null}
	this.args=objArgs||null;
	this.name=strName;
	
	this.construct=function(parent){
		if(!parent){alert("Event.construct Error:can't create Event without parent");return null}
		this.parent=parent;
		this.iList=IList;
		this.iList(this.parent);
	};
};
