﻿String.prototype.equals = function(value, ignoreCase){
	if(value == null) return false;  //this will include undefined
    if(ignoreCase == null) ignoreCase = true;
    
	var left = ignoreCase ? this.toLowerCase() : this;
	var right = ignoreCase ? value.toString().toLowerCase() : value;

	return left == right;
}

String.prototype.trim = function()
{
    return this.replace(/^\s+/gm, "").replace(/\s+$/gm, "");
}

String.format = function (format){
	var args = arguments;

	return format.replace(/\{(\d*)\}/gm, getArg);
    
	function getArg(match, index, startPosition){
		if(!isNaN(index)){
			index = (index * 1) + 1;
			if(index < args.length) return args[index];
		}
        
		return match;
	}
}
       
function StringBuilder(){
	var values = [];

	this.append = function(value){
		values.push(value);
	}
    
	this.appendFormat = function(format){
		values.push(String.format.apply(this, arguments));
	}
    
	this.toString = function(delimiter){
		return values.join(delimiter ? delimiter : '');
	}
}

Array.prototype.contains = function(value){
    for(var i = 0, item; item = this[i]; i++){
        if(item === value) return true;
    }
    
    return false;
}