// JavaScript Document

var Vector=Array;

Vector.prototype.add=function(data) {
  this.insert(this.length,data);
}

Vector.prototype.insert=function(index,data) {
	for (var i=this.length;i>index && i>0;i--)
	   this[i]=this[i-1];
	this[index]=data;
}

Vector.prototype.remove=function(index) {
	for (var i=index;i<this.length-1;i++)
      this[i]=this[i+1];
    if (index>=0 && index<this.length)
      this.length=this.length-1;
}

//////////////////////////////

function Map() {
  this.values=new Vector();
}

Map.prototype.getData=function(name) {
  for (var i=0;i<this.values.length;i++)
    if (this.values[i].name==name) return this.values[i];
  return null; 
};
  
Map.prototype.getValue=function(name) {
  var data=this.getData(name);
  if (data) return data.value;
  else return null;
};
  
Map.prototype.setValue=function(name,value) {
    for (var i=0;i<this.values.length;i++)
	  if (this.values[i].name==name) this.values[i].value=value;
};
  
Map.prototype.add=function(name,value) {
	this.putData(name,value);
}
  
Map.prototype.putData=function(name,value) {
    var data=this.getData(name);
	if (data) {
	   this.setValue(name,value);
	   return;
	}
	var index=this.values.length;
	this.values[index]={};
	this.values[index].name=name;
	this.values[index].value=value;
};

Map.prototype.remove=function(name) {
	for (var i=0;i<this.values.length;i++)
	  if (this.values[i].name==name) {
	    this.values.remove(i);
		return;
	  }
}

Map.prototype.getNameList=function() {
	var result=new Array();
	for (var i=0;i<this.values.length;i++)
	  result[i]=this.values[i].name;
	return result;
}

/////////////////////////////////////////

function EventListenerList() {
	this.listeners=new Map();
}

EventListenerList.prototype.add=function(which,ls) {
	var lses=this.get(which);
	if (!lses) {
		lses=new Vector();
		this.listeners.add(which,lses);
	}
    lses.add(ls);
}

EventListenerList.prototype.remove=function(which,ls) {
	var lses=this.get(which);
    if (lses!=null) {
	   var i=0;
	   while (i<lses.length) {
	      if (lses[i]==ls) lses.remove(i);
	      else i++;
	   }
    }
}

EventListenerList.prototype.get=function(which) {
	return this.listeners.getValue(which);
}
