﻿///////////////////////////////////////////////////////////////////////////
// Georgetown namespace
///////////////////////////////////////////////////////////////////////////
var Georgetown = {};
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
// Georgetown.County namespace
///////////////////////////////////////////////////////////////////////////
Georgetown.County = {};
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
// Georgetown.County.generic namespace
///////////////////////////////////////////////////////////////////////////
Georgetown.County.generic = {};
///////////////////////////////////////////////////////////////////////////

Georgetown.County.generic.list = function() 
{
    this.items = new Array();
};

Georgetown.County.generic.list.prototype.add = function(item) 
{
    if (this.items.length != 0) 
    {
        var oldlen = this.items.length;
        var tmp = new Array(oldlen + 1);
        var i = 0;
        
        for (i = 0; i < this.items.length; i++) 
        {
            tmp[i] = this.items[i];
        };
        
        tmp[(tmp.length - 1)] = item;
        this.items = new Array(tmp.length);
        for (i = 0; i < tmp.length; i++) 
        {
            this.items[i] = tmp[i];
        };
        tmp = null;
    } 
    else 
    {
        this.items = new Array(1);
        this.items[0] = item;
    };
};

Georgetown.County.generic.list.prototype.addRange = function(objectArray) 
{
    if (this.items.length != 0) 
    {
        var oldlen = this.items.length;
        var tmp = new Array(oldlen + objectArray.length);
        var i = 0;
        
        for (i = 0; i < this.items.length; i++) 
        {
            tmp[i] = this.items[i];
        };
        for (i = 0; i < objectArray.length; i++) 
        {
            tmp[(i + oldlen)] = objectArray[i];
        };
        this.items = new Array(tmp.length);
        for (i = 0; i < tmp.length; i++) 
        {
            this.items[i] = tmp[i];
        };
        tmp = null;
    } 
    else 
    {
        var iloop = 0;
        
        this.items = new Array(objectArray.length);
        for (iloop = 0; iloop < objectArray.length; iloop++) 
        {
            this.items[iloop] = objectArray[iloop];
        };
    };
};

Georgetown.County.generic.list.prototype.clear = function() 
{
    this.items = new Array();
};

Georgetown.County.generic.list.prototype.compare = function(a, b) 
{
    return (a == b);
};

Georgetown.County.generic.list.prototype.count = function() 
{
    return this.items.length;
};

Georgetown.County.generic.list.prototype.extendProperty = function(index, obj) 
{
    for (key in obj) 
    {
        this.setProperty(index, key, obj[key]);
    };
};

Georgetown.County.generic.list.prototype.find = function(item) 
{
    var index = -1;
    var i = 0;
    
    for (i = 0; i < this.items.length; i++) 
    {
        if (this.compare(this.items[i], item)) 
        {
            index = i;
            break;
        };
    };
    
    return index;
};

Georgetown.County.generic.list.prototype.getItem = function(index) 
{
    return this.items[index];
};

Georgetown.County.generic.list.prototype.getItems = function() 
{
    return this.items;
};

Georgetown.County.generic.list.prototype.getProperty = function(index, property) 
{
    return this.items[index][property];
};

Georgetown.County.generic.list.prototype.insert = function(item, index) 
{
    if (this.items.length != 0) 
    {
        var oldlen = this.items.length;
        var tmp = new Array(oldlen + 1);
        var i = 0;
        var j = 0;
        
        for (i = 0; i < tmp.length; i++) 
        {
            if (i == index) tmp[i] = item;
            else 
            {
                tmp[i] = this.items[j];
                j++;
            };
        };
        this.items = new Array(tmp.length);
        for (i = 0; i < tmp.length; i++) 
        {
            this.items[i] = tmp[i];
        };
        tmp = null;
    } 
    else 
    {
        this.items = new Array(1);
        this.items[0] = item;
    };
};

Georgetown.County.generic.list.prototype.join = function(seprator, property) 
{
    var i = 0;
    var result = "";
    
    for (i = 0; i < this.items.length; i++) 
    {
        if (i == (this.items.length - 1)) 
        {
            result += (property) ? this.items[i][property] : this.items[i];
        } 
        else 
        {
            result += (property) ? this.items[i][property] : this.items[i];
            result += seprator;
        };
    };
    return result;
};

Georgetown.County.generic.list.prototype.remove = function(item) 
{
    var index = this.find(item);
    
    if (index != -1) 
    {
        var tmp = new Array((this.items.length - 1));
        var i = 0;
        var j = 0;
        
        for (i = 0; i < this.items.length; i++) 
        {
            if (i != index) 
            {
                tmp[j] = this.items[i];
                j++;
            };
        };
        this.items = new Array(tmp.length);
        for (i = 0; i < tmp.length; i++) 
        {
            this.items[i] = tmp[i];
        };
        tmp = null;
        this.count--;
    };
};

Georgetown.County.generic.list.prototype.removeAt = function(index) 
{
    if (this.items.length == 1) 
    {
        this.items = null;
        this.items = new Array();
    } 
    else 
    {
        var tmp = new Array((this.items.length - 1));
        var i = 0;
        var j = 0;
        
        for (i = 0; i < this.items.length; i++) 
        {
            if (i != index) 
            {
                tmp[j] = this.items[i];
                j++;
            };
        };
        this.items = new Array(tmp.length);
        for (i = 0; i < tmp.length; i++) 
        {
            this.items[i] = tmp[i];
        };
        tmp = null;
    };
};

Georgetown.County.generic.list.prototype.setItem = function(item, index) 
{
    this.items[index] = item;
};

Georgetown.County.generic.list.prototype.setProperty = function(index, property, value) 
{
    this.items[index][property] = value;
};