;(function(trv, $, window, document, undefined) {
    "use strict";

    var stringFormatRegExp = /{(\w+?)}/g;

    trv.utils = {
        trim: function (s, charlist) {
            return this.rtrim(this.ltrim(s, charlist), charlist);
        },

        ltrim: function (s, charlist) {
            if (charlist === undefined) {
                charlist = "\s";
            }
            return s.replace(new RegExp("^[" + charlist + "]+"), "");
        },

        rtrim: function (s, charlist) {
            if (charlist === undefined) {
                charlist = "\s";
            }
            return s.replace(new RegExp("[" + charlist + "]+$"), "");
        },

        stringFormat: function (template, data) {
            var isArray = Array.isArray(data);
            return template.replace(stringFormatRegExp, function ($0, $1) {
                return data[isArray ? parseInt($1) : $1];
            });
        },

        tryParseInt: function (value) {
            if (/^\-?([0-9]+|Infinity)$/.test(value)) {
                return Number(value);
            }                
            return NaN;
        },
    };
    
})(window.telerikReportViewer = window.telerikReportViewer || {}, window.jQuery, window, document);