﻿//
///
////Javascript Dictionary Object
///
//
function jsDictionary()
{
		this.obj = new Object();
		
		//the number of key value pairs currently in here
		this.count = 0;
		
		//adds key,value pair
		this.add = _Add;
		
		//removes key,value pair
		this.remove = _Remove;
		
		//removes all pairs
		this.removeAll = _RemoveAll;
		
		//gets an array of values
		this.getValues = _GetValues;
		
		//gets an array of keys
		this.getKeys = _GetKeys;
		
		//gets a value from a key
		this.getVal = _GetVal;
		
		//sets a value from an existing key
		this.setVal = _SetVal;		
		
		//checks if the dictionary contains a key
		this.containsKey = _ContainsKey;
}

function _Add(_key,obj)
{
	var _szKey = String(_key);
	if(this.containsKey(_szKey))
	{
		this.setVal(_szKey);
		return false;
	}
	this.obj[_szKey]=obj;
	this.count++;
	return true;
}

function _Remove(_key)
{
	var _szKey = String(_key);
	if(!this.containsKey(_szKey))
		return false;
	delete this.obj[_szKey];
	this.count--;
}

function _RemoveAll()
{
	for(var _key in this.obj)
		delete this,obj[_key];
	this.count=0;
}

function _GetValues()
{
	var _return = new Array();
	for(var _key in this.obj)
		_return.push(this.obj[_key]);
	return _return;
}

function _GetKeys()
{
	var _return = new Array();
	for(var _key in this.obj)
		_return.push(_key);
	return _return;
}

function _GetVal(_key)
{
	return this.obj[String(_key)];
}

function _SetVal(_key,_val)
{
	var _szKey = String(_key);
	if(this.containsKey(_szKey))
		this.obj[_szKey]=_val;
	else
		this.add(_key,_val);
}

function _ContainsKey(_key)
{
	return (this.obj[_key])?true:false
}