function Hashtable(){
  this.clear();
}

Hashtable.prototype.clear = function(){
  this.container=new Object();
  this.count=0;
}

Hashtable.prototype.clone = function(){
  var htNew = new Hashtable();
  var key;
  for(key in this.container){
    if (this.container[key]!=undefined)
      htNew.put(key,this.container[key]);
  }
  return htNew;
}

Hashtable.prototype.contains = function(aValue){
  var key;
  for (key in this.container){
    if (this.container[key]==aValue) return true;
  }
  return false;
}

Hashtable.prototype.containsKey = function(aKey){
  return this.container[aKey]!=undefined;
}

Hashtable.prototype.containsValue = Hashtable.prototype.contains;

Hashtable.prototype.elements = function(){ 
  var eResult = new Enumeration();
  var key;
  for (key in this.container){
    if (this.container[key]!=undefined)
      eResult.addElement(this.container[key]);
  }
  return eResult;
}


Hashtable.prototype.equals = function(anObject){
  //make sure that anObject is a Hashtable
  if (typeof(anObject)!='object') return false;
  var iIndex= anObject.constructor.toString().indexOf("function Hashtable()");
  //IE returns 0, firefox returns 1.
  if (iIndex<-1 || iIndex>1) return false;
  //check the size
  if (this.size()!=anObject.size()) return false;
  //cannot use get() to compare because get converts undefined to null.
  var key;
  for (key in this.container){
    if (anObject.container[key]!=this.container[key]) return false;
  }
  return true;
}

/*return the value given the key, if key is not found, return null*/
Hashtable.prototype.get = function(aKey){
  if (this.container[aKey]!=undefined)
    return this.container[aKey];
  return null;
}

Hashtable.prototype.isEmpty = function(){
  return this.size()==0;
}

Hashtable.prototype.keys = function(){
  var eResult = new Enumeration();
  var key;
  for (key in this.container){
    if (this.container[key]!=undefined)
      eResult.addElement(key);
  }
  return eResult;
}

Hashtable.prototype.put = function(aKey, aValue){
  if (this.container[aKey]==undefined){
    this.count++;
  }
  this.container[aKey]=aValue;
}

/*Removes the key (and its corresponding value) from this hashtable. 
  This method does nothing if the key is not in the hashtable. 
  Value return is the value of the key removed or null if key is
  not in the hashtable*/
Hashtable.prototype.remove = function(aKey){
  if (this.container[aKey]!=undefined){
    var oResult = this.container[aKey];
    this.container[aKey]=undefined;
    this.count--;
    return oResult;
    
  }
  return null;
}

Hashtable.prototype.size = function(){
  return this.count;
}

Hashtable.prototype.toString = function (){
  var key;
  var sResult="";
  var i=1;
  for (key in this.container){
    if (this.container[key]!=undefined)
      sResult=sResult+"{" + key + ","+this.container[key]+"}";
    if (i++<this.count) sResult +=",";
  }
  return sResult;
}

Hashtable.prototype.values = Hashtable.prototype.elements;

