Array.prototype.sortNum = function() {
    return this.sort( function (a,b) {
        return a-b;
    } );
};

/**
 * Check if an array element is equal to argument
 * @param value The value to check the array for
 * @return <bool> Whether or not the value was found in the element
 */
Array.prototype.contains = function(value) {
    for (thisValue in this) {
        if (this[thisValue] === value) {
            return true;
        }
    }
    return false;
};

Object.prototype.getElementsByClass = function(searchClass, tag) {
    var returnArray = [];
    tag = tag || '*';
    var els = this.getElementsByTagName(tag);
    var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
    for (var i = 0; i < els.length; i++) {
        if ( pattern.test(els[i].className) ) {
            returnArray.push(els[i]);
        }
    }
    return returnArray;
};

String.prototype.backwards = function() {
    newString = '';
    for (i = this.length - 1; i >= 0; i++) {
        newString += this[i];
    }
    return newString;
};

/**
 * Check if string is equal to argument
 * @param value The value to check the string for
 * @return <bool> Whether or not the value was the same
 */
String.prototype.equals = function(value) {
    return this === value;
};

/**
 * Check if string contains the argument
 * @param value The value to check the string for
 * @return <bool> Whether or not the string contains the value
 */
String.prototype.contains = function(value) {
    return this.indexOf(value) >= 0;
};

/**
 * Trims specified length from entire string
 * @param trim The amount to trim from the length
 * @return <String> The trimmed original
 */
String.prototype.trimLength = function(trim) {
    newString = '';
    for (i = 0; i < trim; i++) {
        newString += this[i];
    }
    return newString;
};

/**
 * Trims specified length from front of string
 * @param trim The amount to trim from the front
 * @return <String> The trimmed original
 */
String.prototype.trimFront = function(trim) {
    newString = '';
    for (i = trim; i < this.length; i++) {
        newString += this[i];
    }
    return newString;
};

/**
 * Trims specified length from rear of string
 * @param trim The amount to trim from the rear
 * @return <String> The trimmed original
 */
String.prototype.trimRear = function(trim) {
    newString = '';
    for (i = 0; i < (this.length - trim); i++) {
        newString += this[i];
    }
    return newString;
};

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
};

String.prototype.ltrim = function() {
    return this.replace(/^\s*|\s*$/g,'');
};

String.prototype.rtrim = function() {
    return this.replace(/^\s*|\s*$/g,'');
};

String.prototype.trim = function() {
    return this.replace(/^\s*|\s*$/g,'');
};

String.prototype.formatNumber = function(num, prefix){
    prefix = prefix == null ? '' : prefix;
    num = '' + num;
    var splitStr = num.split('.');
    var splitLeft = splitStr[0];
    var splitRight = splitStr.length > 1 ? '.' + splitStr[1] : '';
    var regx = /(\d+)(\d{3})/;
    while (regx.test(splitLeft)) {
        splitLeft = splitLeft.replace(regx, '$1' + ',' + '$2');
    }
    return prefix + splitLeft + splitRight;
};

String.prototype.unformatNumber = function(num) {
    return num.replace(/([^0-9\.\-])/g,'') * 1;
};

Table.prototype.makeRowsCols = function(rows, cols) {
    while (this.rows.length > 0) {
        this.deleteRow(0);
    }
    for (i = 0; i < rows; i++) {
        this.insertRow(i);
        for (ii = 0; ii < cols; ii++) {
            this.rows[i].insertCell(ii);
        }
    }
};

Table.prototype.setColAlign = function(col, align) {
    for (i = 0; i < this.rows.length; i++) {
        this.rows[i].cells[col].align = align;
    }
};

Window.prototype.addEvent = function(event, func, capture) {
    if (this.addEventListener){
        this.addEventListener(event, func, capture);
        return true;
    } else if (this.attachEvent) {
        return this.attachEvent("on" + event, func);
    } else {
        this.myEvents = !this.myEvents ? {} : this.myEvents;
        this.myEvents[event] = this.myEvents[event] ? [] : this.myEvents[event]
        var evts = this.myEvents[event];
        evts[evts.length] = func;
        this['on' + event] = function(){
            if (!this || !this.myEvents || !this.myEvents[event]) {
                return false;
            }
            for (var i = 0, len = evts.length; i < len; i++) {
                evts[i]();
            }
            return true;
        };
    }
    return true;
};

