/*
    Copyright (c) 2009, SpatialPoint, LLC.
    
    All rights reserved.
    
    http://www.spatialpoint.com
*/

Number.prototype.truncate = function(n)
{
    return Math.round(this * Math.pow(10, n)) / Math.pow(10, n);
};

String.prototype.toProperCase = function()
{
    var val = this;
    
    return val.replace(
        /[^\s]+/g, 
        function(word)
        {
            return word.substring(0,1).toUpperCase() + word.substring(1);
        });
};

String.prototype.trim = function()
{
    var val = this;
    
    return val.replace(/^\s*|\s*$/g, "");
};

if (!Array.prototype.indexOf)
{
    Array.prototype.indexOf = function(elt)
    {
        var len = this.length;
        
        var from = Number(arguments[1]) || 0;
        
        from = (from < 0)
             ? Math.ceil(from)
             : Math.floor(from);
        
        if (from < 0)
        {
            from += len;
        }
        
        for (; from < len; from++)
        {
            if (from in this && this[from] === elt)
            {
                return from;
            }
        }
        
        return -1;
    };
}

if (!Array.prototype.remove)
{
    Array.prototype.remove = function(elt)
    {
        var index = this.indexOf(elt);
        
        if (index == -1)
        {
            return;
        }

        this.splice(index, 1);        
    };
}

if (!Array.prototype.removeAt)
{
    Array.prototype.removeAt = function(index)
    {
        if (index < 0 || index > this.length - 1)
        {
            return;
        }

        this.splice(index, 1);
    };
}

