String.prototype.letterToUpperCase = function(index)
{
	return (this.substring(0, index) + 
	this.charAt(index).toUpperCase() + 
	this.substring(index+1, this.length));
}

String.prototype.letterToLowerCase = function(index)
{
	return (this.substring(0, index) + 
	this.charAt(index).toLowerCase() + 
	this.substring(index+1, this.length));
}

String.prototype.toTitleCase = function()
{
	// Abort if the string is empty.
	if(this.length <= 0) return this;
	
	// Compile a string in title case.
	// First convert the string to lower case.
	var temp_string = this.toLowerCase();
	
	// Convert the first letter to upper case.
	temp_string = temp_string.letterToUpperCase(0);
	
	// The last char to compare
	var end = temp_string.length - 1;
	
	// Capitalize words
	for (i = 1; i < end; i++)
	{
		current_char = temp_string.charAt(i);
		last_two_charactors = temp_string.substring(i - 1, i + 1);
		
		
        if (current_char == " " || current_char == "-" 
		|| last_two_charactors == "Mc" || last_two_charactors == "O'"
		|| last_two_charactors == "P." || last_two_charactors == "PO")
		{
            temp_string = temp_string.letterToUpperCase(i+1);
        }
	}
	return temp_string;
}

String.prototype.isBlank = function()
{
	return this.length = 0;
}

String.prototype.endsWith = function(value)
{
	var index = this.indexOf(value);
	
	if(index > -1)
	{
		return this.length == index + value.length;
	}
	else
	{
		return false;
	}
}
