String.prototype.startsWith = function(str)
{ return (this.match("^" + str) == str) }

String.prototype.endsWith = function(str)
{ return (this.match(str + "$") == str) }

String.prototype.format = function() {
    var pattern = /\{\d+\}/g;
    var args = arguments;
    return this.replace(pattern, function(capture) { return args[capture.match(/\d+/)]; });
}
String.prototype.trimEnd = function(c) {
    if (c)
        return this.replace(new RegExp(c.escapeRegExp() + "*$"), '');
    return this.replace(/\s+$/, '');
}
String.prototype.trimStart = function(c) {
    if (c)
        return this.replace(new RegExp("^" + c.escapeRegExp() + "*"), '');
    return this.replace(/^\s+/, '');
}

String.prototype.escapeRegExp = function() {
    return this.replace(/[.*+?^${}()|[\]\/\\]/g, "\\$0");
}

function getFirstUrlPart() {
    var pos = window.location.pathname.indexOf(appPath);
    var firstUrlPart = window.location.pathname.substr(pos + appPath.length);

    pos = firstUrlPart.lastIndexOf("/");
    firstUrlPart = (pos != -1) ? firstUrlPart.substr(pos + 1, firstUrlPart.length) : firstUrlPart;

    return firstUrlPart;
}


