var g_monthArray = new Array (GADGET_JAN, GADGET_FEB, GADGET_MAR,
                              GADGET_APR, GADGET_MAY, GADGET_JUN,
                              GADGET_JUL, GADGET_AUG, GADGET_SEP,
                              GADGET_OCT, GADGET_NOV, GADGET_DEC);
                              
///////////////////////////////////////////////////////////////////////////////
// DATE TIME UTILITY
///////////////////////////////////////////////////////////////////////////////
function DTUtil (dateStr, id, dt)
{
  this._id = id;

  if ((dateStr != "") && (dateStr != null))
  {
    var str = dateStr.split ("-")[0];
    if ((str == null) || (str == "")) return;
    var year = parseInt (this.removeLeadingZero (str));

    str = dateStr.split ("-")[1];
    if ((str == null) || (str == "")) return;
    var month = parseInt (this.removeLeadingZero (str)) - 1;

    str = dateStr.split ("-")[2];
    if ((str == null) || (str == "")) return;
    str = str.split (" ")[0];
    if ((str == null) || (str == "")) return;
    var day   = parseInt (this.removeLeadingZero (str));

    str = dateStr.split (" ")[1];
    if ((str == null) || (str == "")) return;
    str = str.split (":")[0];
    if ((str == null) || (str == "")) return;
    var hours = parseInt (this.removeLeadingZero (str));

    str = dateStr.split (" ")[1];
    if ((str == null) || (str == "")) return;
    str = str.split (":")[1];
    if ((str == null) || (str == "")) return;
    var min   = parseInt (this.removeLeadingZero (str));
    
    this._date = new Date  ();
    this._date.setFullYear (year , month, day);
    this._date.setHours    (hours, min , 0, 0);
  }
  else if (dt != null)
  {
    this._date = dt;
  }
}

DTUtil.prototype._id;
DTUtil.prototype._date;
DTUtil.prototype._months = g_monthArray;

///////////////////////////////////////////////////////////////////////////////
DTUtil.prototype.removeLeadingZero = function (str)
{
  if (str.charAt (0) == "0")
  {
    return str.substr (1);
  }
  
  return str;
}

///////////////////////////////////////////////////////////////////////////////
DTUtil.prototype.getDT  = function ()
{
  return this._date;
}

///////////////////////////////////////////////////////////////////////////////
DTUtil.prototype.toString = function ()
{
  return "DTUtil: _id=" + this._id + ", _date=" + this._date;
}

///////////////////////////////////////////////////////////////////////////////
DTUtil.prototype.getTime = function ()
{
  if (this._date != null)
  {
    return this._date.getTime ();
  }
  
  return null;
}

///////////////////////////////////////////////////////////////////////////////
DTUtil.prototype.getFormattedYear = function ()
{
  if (this._date == null)
  {
    return "";
  }

  return this._date.getFullYear ();
}

///////////////////////////////////////////////////////////////////////////////
DTUtil.prototype.getFormattedMonth = function ()
{
  if (this._date == null)
  {
    return "";
  }

  return this._months[this._date.getMonth ()];
}

///////////////////////////////////////////////////////////////////////////////
DTUtil.prototype.getFormattedDay = function ()
{
  if (this._date == null)
  {
    return "";
  }

  var day = this._date.getDate ();
  if (day < 10)
  {
    return "0" + day;
  }

  return day;
}

///////////////////////////////////////////////////////////////////////////////
DTUtil.prototype.getFormattedHour = function ()
{
  if (this._date == null)
  {
    return "";
  }

  var hour = this._date.getHours ();
  if (hour < 10)
  {
    return "0" + hour;
  }

  return hour;
}

///////////////////////////////////////////////////////////////////////////////
DTUtil.prototype.getFormattedMin = function ()
{
  if (this._date == null)
  {
    return "";
  }

  var mins = this._date.getMinutes ();
  if (mins < 10)
  {
    return "0" + mins;
  }

  return mins;
}


