  ///
  /// NetForce Tecnologia
  /// Biblioteca de funções DATE de JavaScript
  ///

  /**
   * Guardar funções nativas
   */
  Date.prototype.dateType         = 'Normal'; // Normal ou UTC
  Date.prototype._getDate         = Date.prototype.getDate;
  Date.prototype._getMonth        = Date.prototype.getMonth;
  Date.prototype._getDay          = Date.prototype.getDay;
  Date.prototype._getHours        = Date.prototype.getHours;
  Date.prototype._getMinutes      = Date.prototype.getMinutes;
  Date.prototype._getSeconds      = Date.prototype.getSeconds;
  Date.prototype._getMilliseconds = Date.prototype.getMilliseconds;

  /**
   * Adicionar função getInfo do objeto Date
   * 
   * @return Array
   */
  Date.prototype.getInfo = function() {
    var dd  = ((this.dateType == 'UTC') ? this.getUTCDate()          : this._getDate());
    var mm  = ((this.dateType == 'UTC') ? this.getUTCMonth()         : this._getMonth());
    var yy  = ((this.dateType == 'UTC') ? this.getUTCFullYear()      : this.getFullYear());
    var wk  = ((this.dateType == 'UTC') ? this.getUTCDay()           : this._getDay());
    var hh  = ((this.dateType == 'UTC') ? this.getUTCHours()         : this._getHours());
    var nn  = ((this.dateType == 'UTC') ? this.getUTCMinutes()       : this._getMinutes());
    var ss  = ((this.dateType == 'UTC') ? this.getUTCSeconds()       : this._getSeconds());
    var ms  = ((this.dateType == 'UTC') ? this.getUTCMilliseconds()  : this._getMilliseconds());

    // Tratar valores
    mm += 1;
    wk += 1;

    // Retorno
    var res = {
      day      : dd.toString().fillChars(2),
      month    : mm.toString().fillChars(2),
      year     : yy.toString().fillChars(4),
      week     : wk.toString().fillChars(2),
      hour     : hh.toString().fillChars(2),
      minute   : nn.toString().fillChars(2),
      second   : ss.toString().fillChars(2),
      msecond  : ms.toString().fillChars(2)
    }

    return res;
  }

  /**
   * Adicionar função getInfo do objeto Date
   * 
   * @return Array
   */
  Date.prototype.getInfoInt = function() {
    var info = this.getInfo();

    var res = {
      day     : info.day.intVal(),
      month   : info.month.intVal(),
      year    : info.year.intVal(),
      week    : info.week.intVal(),
      hour    : info.hour.intVal(),
      minute  : info.minute.intVal(),
      second  : info.second.intVal(),
      msecond : info.msecond.intVal()      
    }

    return res;
  }


  /**
   * Redeclarar função getDayWeek do objeto Date
   * 
   * @return Integer
   */
  Date.prototype.getDayWeek = function() {
    var info = this.getInfoInt();
    return info.week;
  }


  /**
   * Redeclarar função getMonth do objeto Date
   * 
   * @return Integer
   */
  Date.prototype.getMonth = function() {
    var info = this.getInfoInt();
    return info.month;
  }

  /**
   * Redeclarar função getDay do objeto Date
   * 
   * @return Integer
   */
  Date.prototype.getDay = function() {
    var info = this.getInfoInt();
    return info.day;
  }

  /**
   * Redeclarar função getYear do objeto Date
   * 
   * @return Integer
   */
  Date.prototype.getYear = function() {
    var info = this.getInfoInt();
    return info.year;
  }

  /**
   * Redeclarar função getHours do objeto Date
   * 
   * @return Integer
   */
  Date.prototype.getHours = function() {
    var info = this.getInfoInt();
    return info.hour;
  }

  /**
   * Redeclarar função getMinutes do objeto Date
   * 
   * @return Integer
   */
  Date.prototype.getMinutes = function() {
    var info = this.getInfoInt();
    return info.minute;
  }

  /**
   * Redeclarar função getSeconds do objeto Date
   * 
   * @return Integer
   */
  Date.prototype.getSeconds = function() {
    var info = this.getInfoInt();
    return info.second;
  }

  /**
   * Redeclarar função getMilliseconds do objeto Date
   * 
   * @return Integer
   */
  Date.prototype.getMilliseconds = function() {
    var info = this.getInfoInt();
    return info.msecond;
  }

  /**
   * Adicionar função toStrDMY do objeto Date
   *
   * @return string
   */
  Date.prototype.toStrDMY = function() {
    var info = this.getInfo();
    return info.day + '/' + info.month + '/' + info.year;
  }

  /**
   * Adicionar função toStrDMYHNS do objeto Date
   *
   * @return string
   */
  Date.prototype.toStrDMYHNS = function() {
    var info = this.getInfo();
    return info.day + '/' + info.month + '/' + info.year + ' ' + info.hour + ':' + info.minute + ':' + info.second;
  }

  /**
   * Adicionar função toStrMY do objeto Date
   *
   * @return string
   */
  Date.prototype.toStrMY = function() {
    var info = this.getInfo();
    return info.month + '/' + info.year;
  }

  /**
   * Adicionar função toStrHNS do objeto Date
   *
   * @return string
   */
  Date.prototype.toStrHNS = function() {
    var info = this.getInfo();
    return info.hour + ':' + info.minute + ':' + info.second;
  }

  /**
   * Adicionar função makeDate do objeto Date
   */
  Date.prototype.makeDate = function(dd, mm, yy, hh, nn, ss, ms) {
    mm -= 1;

    if (this.dateType == 'UTC')
    {
      this.setUTCFullYear(yy);
      this.setUTCMonth(mm);
      this.setUTCDate(dd);
    } else {
      this.setFullYear(yy);
      this.setMonth(mm);
      this.setDate(dd);
    }

    if (hh != undefined)
    {
      nn = ((nn == undefined) ? 0 : nn);
      ss = ((ss == undefined) ? 0 : ss);
      ms = ((ms == undefined) ? 0 : ms);

      if (this.dateType == 'UTC')
        this.setUTCHours(hh, nn, ss, ms);
      else
        this.setHours(hh, nn, ss, ms);
    }
  }

  /**
   * Adicionar função daysOfMonth do objeto Date
   *
   * @param integer yy
   * @param integer mm
   * @return integer
   */
  Date.prototype.daysOfMonth = function(yy, mm) {
    if ((yy == undefined) || (mm == undefined))
    {
      var info = this.getInfo();
      var mm   = info.month.intVal();
      var yy   = info.year.intVal();
    }

    var dt = new Date(yy, mm, 0);
    return (dt.getUTCDate()); 
  }

  /**
   * Adicionar função addYears do objeto Date
   *
   * @param integer years
   */
  Date.prototype.addYears = function(years) {
    var info    = this.getInfo();
    var yy      = info.year.intVal();

    if (this.dateType == 'UTC')
      this.setUTCFullYear(yy + years);
    else
      this.setFullYear(yy + years);
  }

  /**
   * Adicionar função addMonths do objeto Date
   *
   * @param integer mons
   */
  Date.prototype.addMonths = function(mons) {
    var info    = this.getInfo();
    var mm      = (info.month.intVal() - 1);

    if (this.dateType == 'UTC')
      this.setUTCMonth(mm + mons);
    else
      this.setMonth(mm + mons);
  }

  /**
   * Adicionar função addDays do objeto Date
   *
   * @param integer days
   */
  Date.prototype.addDays = function(days) {
    if (days == 0)
      return;

    var dti   = this.getInfoInt();
    var fator = ((days < 0) ? -1 : 1);
    var days  = ((days < 0) ? (days * -1) : days);

    // Deslocar
    while (days > 0)
    {
      dti = this.getInfoInt();
      if ((fator > -1) && (dti.day >= this.daysOfMonth(dti.year, dti.month)))
      {
        if (this.dateType == 'UTC')
          this.setUTCDate(1);
        else
          this.setDate(1);

        this.addMonths(1);
      } else {
        if (this.dateType == 'UTC')
          this.setUTCDate(dti.day + fator);
        else
          this.setDate(dti.day + fator);
      }

      days -= 1;
    }
  }

  /**
   * Adicionar função addSecond do objeto Date
   *
   * @param integer secs
   */
  Date.prototype.addSeconds = function(secs) {
    var info    = this.getInfo();
    var ss      = info.second.intVal();

    if (this.dateType == 'UTC')
      this.setUTCSeconds(ss + secs);
    else
      this.setSeconds(ss + secs);
  }

  /**
   * Adicionar função addMSeconds do objeto Date
   *
   * @param integer msecs
   */
  Date.prototype.addMSeconds = function(msecs) {
    var info    = this.getInfo();
    var ms      = info.msecond.intVal();

    if (this.dateType == 'UTC')
      this.setUTCMilliseconds(ms + msecs);
    else
      this.setMilliseconds(ms + msecs);
  }

  /**
   * Retorna a diferença de datas em MiliSegundos
   *
   * @param Date data
   */
  Date.prototype.getDiff = function(data) {
    var info1    = this.getInfoInt();
    var info2    = data.getInfoInt();
    var dtDia    = 86400000;

    var dt1     = 0;
    dt1  = info1.msecond;
    dt1 += (info1.second * 1000);
    dt1 += (info1.minute * 60000);
    dt1 += (info1.hour   * 3600000);
    dt1 += (info1.day    * dtDia);
    dt1 += (info1.month  * (30 * dtDia));
    dt1 += (info1.year   * (365 * dtDia));

    var dt2     = 0;
    dt2  = info2.msecond;
    dt2 += (info2.second * 1000);
    dt2 += (info2.minute * 60000);
    dt2 += (info2.hour   * 3600000);
    dt2 += (info2.day    * dtDia);
    dt2 += (info2.month  * (30 * dtDia));
    dt2 += (info2.year   * (365 * dtDia));

    return (dt2 - dt1);
  }
