/**
 * Associative array class. Wraps an object with useful
 * array management functions.
 *
 * Copyright: (c)2007 CK Web Technologies - http://www.ckweb.com.au/
 * Author:    Chris Knowles <chris.knowles@ckweb.com.au>
 * Version:   $Id: AssocArray.js 2 2008-07-23 08:02:22Z Chris $
 */

if (!CKW) {
    var CKW = function(){};
}

CKW.AssocArray = function()
{
    this.vals = {};
    this.length = 0;
}

CKW.AssocArray.prototype =
{
    set: function(name, value)
    {
        if (this.vals[name]) {
            throw new Error("Trying to use an assoc array value thats already been allocated. Params: [" + name + "][" + value + "]");
        }
        this.vals[name] = value;
        this.length++;
    },

    get: function(name)
    {
        if (this.vals[name]) {
            return this.vals[name];
        }
        return false;
    },

    update: function(data)
    {
        for (name in data) {
            if (this.vals[name]) {
                this.vals[name] = data[name];
            }
        }
    },

    add: function(data)
    {
        for (name in data) {
            this.vals[name] = data[name];
            this.length++;
        }
    },

    empty: function()
    {
        this.vals = {};
        this.length = 0;
    },

    unset: function(name)
    {
        this.vals[name] = null;
        this.length--;
    },

    remove: function(name)
    {
        if (this.vals[name]) {
            delete this.vals[name];
            this.length--;
        }
    }

}

CKW.registry =  new CKW.AssocArray;

var $AA = CKW.AssocArray;
var $R = CKW.registry;
