String.prototype.hashCode = function () {
    var hash = 0, len = this.length;
    if (len === 0) return hash;
    for (var i = 0; i < len; ++i) {
        char = this.charCodeAt(i);
        hash = ((hash << 5) - hash) + char;
        hash = hash & hash; // Convert to 32bit integer
    }
    return hash;
}

// permitir utilizar String.format('{0}', 'valor')
if (!String.format) {
    String.format = function (format) {
        var args = Array.prototype.slice.call(arguments, 1);
        return format.replace(/{(\d+)}/g, function (match, number) {
            return typeof args[number] != 'undefined'
              ? args[number]
              : match
            ;
        });
    };
};

function isNumeric(n) {
    var nn = n.replace(',', '.');
    return !isNaN(parseFloat(nn)) && isFinite(nn);
}

if (!Array.prototype.distinct) {
    Array.prototype.distinct = function () {
        var u = {}, a = [];
        for (var i = 0, l = this.length; i < l; ++i) {
            if (u.hasOwnProperty(this[i])) {
                continue;
            }
            a.push(this[i]);
            u[this[i]] = 1;
        }
        return a;
    }
};


function GetToken() {

    var k = moment().format("YYYYMMDDHH")

    var m = forge.hmac.create();
    m.start('sha256', '0f03afc7-9c19-4316-bc33-789018b8fb72');
    m.update(k);

    return forge.util.encode64(m.digest().getBytes());
}



Date.prototype.yyyymmdd = function () {
    var yyyy = this.getFullYear().toString();
    var mm = (this.getMonth() + 1).toString();
    var dd = this.getDate().toString();
    return [yyyy, (mm[1] ? mm : "0" + mm[0]), (dd[1] ? dd : "0" + dd[0])].join("-");
};


function S4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}

function newGUID() {
    return guid = (S4() + S4() + "-" + S4() + "-4" + S4().substr(0, 3) + "-" + S4() + "-" + S4() + S4() + S4()).toUpperCase();
}


Date.prototype.YYYYMMDDHH = function () {
    var yyyy = this.getFullYear().toString();
    var MM = pad(this.getMonth() + 1, 2);
    var dd = pad(this.getDate(), 2);
    var hh = pad(this.getHours(), 2);
    var mm = pad(this.getMinutes(), 2)
  
    return yyyy + MM + dd + hh  ;
};
function pad(number, length) {

    var str = '' + number;
    while (str.length < length) {
        str = '0' + str;
    }

    return str;

}