//
// ManagedDatetime.js
//
// JavaScript class for maintaining a Managed Datetime using DOM HTML
// to swap between display and edit elements.
//
// April 2004  -pge
//
// Constructor:
//  ManagedDatetime( baseid, dateformat[, blurrproc] )
//   baseid - Name of JavaScript variable declared for this class instance.
//   dateformat - Initial format string.
//   blurrproc - Optional procedure name that takes baseid as argument
//     and called at end of onblurr event handler.
//   fieldname - Optional name fir hidden input element.
//   fieldformat - Optional format for fieldname, defaults to dateformat.
//   fromstring - Optional string with a JS recognizable date.
//
// Principal methods:
//  embed() - Called to create Date Display at desired location in document.
//  setFormat( dateformat ) - Used to change date format.
//  getFormat() - Returns current dateformat string.
//  toString( [dateformat] ) - Returns date formatted like current, or like
//    optional dateformat when provided.
//  valueOf() - Returns this.datetime.valueOf().
//
//  Format specifiers (all other characters considerred punctuation):
//   M, m, L, l, K, k - Month: 01, 1, JAN, Jan, JANUARY, January
//   D, d - Day: 01, 1
//   Y, y - Year: 2001, 01
//   H, h - (0-23:Hour): 01, 1
//   N, n - Minute: 01, 1
//   S, s - Second: 01, 1
//
// Modified:
//

// Constructor.
function ManagedDatetime
(
  baseid,
  dateformat,
  blurrproc,
  fieldname,
  fieldformat,
  fromstring
)
{
  this.baseid = baseid;
  this.dateformat = dateformat;
  this.blurrproc = blurrproc;
  this.fieldname = fieldname;
  this.fieldformat = fieldformat;
  if ( fromstring ) { this.datetime = new Date( fromstring ); }
  else { this.datetime = new Date(); }
  this.span = new Object();
  this.hiddenelement = new Object();
  this.displayelement = new Array();
  this.editelement = new Array();
}

// Dummy class instance needed in JS1.1 before methods can be defined.
new ManagedDatetime( "junk","m/d/y h/n/s" );

// Class methods.
ManagedDatetime.prototype.embed = function( el, fromstring )
{
  this.span = document.createElement( 'span' );
  this.span.id = this.baseid;
  this.span.className = 'mdt';
  if ( this.fieldname )
  {
    this.hiddenelement = document.createElement( "input" );
    this.hiddenelement.type = "hidden";
    this.hiddenelement.id = "mdt_hidden_" + this.fieldname;
    this.hiddenelement.name = this.fieldname;
    if ( this.fieldformat )
     this.hiddenelement.value = this.toString( this.fieldformat );
    else this.hiddenelement.value = this.toString();
    this.span.appendChild( this.hiddenelement );
  }
  if ( fromstring ) { this.datetime = new Date( fromstring ); }
  this.buildDate();
  var obj = document.getElementById( el );
  obj.appendChild( this.span );
}
ManagedDatetime.prototype.setFormat = function( dateformat )
{
  while( this.span.childNodes.length > 0 )
  {
    this.span.removeChild( this.span.firstChild );
  }
  this.dateformat = dateformat;
  this.buildDate();
}
ManagedDatetime.prototype.getFormat = function() { return this.dateformat; }
ManagedDatetime.prototype.toString = function( dfmt )
{
  var c, str = "";
  dfmt = ( dfmt ) ? dfmt : this.dateformat;
  for( var i = 0; i < dfmt.length; i++ )
  {
    c = dfmt.charAt( i );
    switch( c )
    {
      case "M" : str += this.getZMonth(); break;
      case "m" : str += this.getMonth(); break;
      case "L" : str += this.getZMonthShortName(); break;
      case "l" : str += this.getMonthShortName(); break;
      case "K" : str += this.getZMonthName(); break;
      case "k" : str += this.getMonthName(); break;
      case "D" : str += this.getZDay(); break;
      case "d" : str += this.getDay(); break;
      case "Y" : str += this.getYear(); break;
      case "y" : str += this.getShortYear(); break;
      case "H" : str += this.getZHour(); break;
      case "h" : str += this.getHour(); break;
      case "N" : str += this.getZMinute(); break;
      case "n" : str += this.getMinute(); break;
      case "S" : str += this.getZSecond(); break;
      case "s" : str += this.getSecond(); break;
      default  : str += c;
    }
  }
  return str;
}
ManagedDatetime.prototype.valueOf = function()
{
  return this.datetime.valueOf();
}
ManagedDatetime.prototype.fromString = function( fromstring )
{
  if ( fromstring )
  {
    while( this.span.childNodes.length > 0 )
    {
      this.span.removeChild( this.span.firstChild );
    }
    this.datetime = new Date( fromstring );
    this.buildDate();
  }
}
ManagedDatetime.prototype.mdt_a_click = function( dpart )
{
  if ( this.displayelement[dpart].firstChild.nodeType == 3 )
  {
    this.editelement[dpart].setAttribute
    ( "value", this.displayelement[dpart].firstChild.nodeValue );
    this.span.replaceChild
    ( this.editelement[dpart], this.displayelement[dpart] );
    this.editelement[dpart].focus();
    this.editelement[dpart].select();
  }
}
ManagedDatetime.prototype.mdt_text_blur = function( evt )
{
  evt = ( evt ) ? evt : ( ( window.event ) ? event : null );
  if ( evt )
  {
    var inp = ( evt.target ) ? evt.target :
               ( ( evt.srcElement ) ? evt.srcElement : null );
    if ( inp )
    {
      var arr = inp.id.toString().split( "_" );
      var span = eval( arr[2] + ".span" );
      eval( arr[2] + ".set" + mdt_functions[arr[0]] + "('" + inp.value + "')" );
      var str = eval( arr[2] + ".get" + mdt_functions[arr[0]] + "()" );
      var txt = document.createTextNode( str );
      var anc = eval( arr[2] + ".displayelement['" + arr[0] + "']" );
      while( anc.childNodes.length > 0 )
      {
        anc.removeChild( anc.firstChild );
      }
      anc.appendChild( txt );
      span.replaceChild( anc, inp );
      var obj = eval( inp.id.toString().split( "_" )[2] );
      if ( obj.fieldformat && obj.hiddenelement )
      {
        if ( obj.fieldformat )
         obj.hiddenelement.value = obj.toString( obj.fieldformat );
        else obj.hiddenelement.value = obj.toString();
      }
      mdt_callRemote( inp.id );
    }
  }
}
ManagedDatetime.prototype.mdt_text_key = function( evt )
{
  evt = ( evt ) ? evt : ( ( window.event ) ? event : null );
  if ( evt )
  {
    var inp = ( evt.target ) ? evt.target :
               ( ( evt.srcElement ) ? evt.srcElement : null );
    if ( inp )
    {
      var c = ( evt.charCode ) ? evt.charCode :
                 ( ( evt.which ) ? evt.which : evt.keyCode );
      switch( c )
      {
        case mdt_cPageUp :
          mdt_adjoiningValue( inp.id, 5, true )
          return false;
        case mdt_cPageDown :
          mdt_adjoiningValue( inp.id, 5, false )
          return false;
        case mdt_cUpArrow :
        case mdt_cPlus :
          mdt_adjoiningValue( inp.id, 1, true )
          return false;
        case mdt_cDownArrow :
        case mdt_cMinus :
          mdt_adjoiningValue( inp.id, 1, false )
          return false;
        case mdt_cForwardSlash :
        case mdt_cSemiColon :
        case mdt_cSpace :
          if ( mdt_editNext( inp.id, inp.value, false ) )
          {
            inp.blur();
            return false;
          }
          return true;
        case mdt_cBackSlash :
        case mdt_cComa :
          if ( mdt_editNext( inp.id, inp.value, true ) )
          {
            inp.blur();
            return false;
          }
          return true;
        case mdt_cBackSpace :
        case mdt_cRightArrow :
        case mdt_cLeftArrow :
          return true;
      }
      if ( mdt_isMonthName( inp.id ) )
      {
        if ( c < 65 || ( c > 90 && c < 97  ) || c > 122 )
        {
          inp.blur();
          return false;
        }
        return mdt_monthNameKey( inp.id, c );
      }
      else if ( c < 48 || c > 57 )
      {
        inp.blur();
        return false;
      }
    }
  }
  return true;
}
ManagedDatetime.prototype.mdt_text_wheel = function( evt )
{
  evt = ( evt ) ? evt : ( ( window.event ) ? event : null );
  if ( evt )
  {
    var inp = ( evt.target ) ? evt.target :
               ( ( evt.srcElement ) ? evt.srcElement : null );
    if ( inp )
    {
      if ( evt.wheelDelta > 0 )
      {
        mdt_adjoiningValue( inp.id, 1, true )
      }
      else
      {
        mdt_adjoiningValue( inp.id, 1, false )
      }
    }
  }
}
ManagedDatetime.prototype.datepartDOM = function( dpart, val )
{
  this.displayelement[dpart] = document.createElement( "a" );
  this.displayelement[dpart].id = dpart + "_a_" + this.baseid;
  this.displayelement[dpart].className = "mdt_display";
  this.displayelement[dpart].setAttribute
  ( "href", "javascript:" + this.baseid + ".mdt_a_click('" + dpart + "')" );
  var txt = document.createTextNode( val );
  this.displayelement[dpart].appendChild( txt );
  this.span.appendChild( this.displayelement[dpart] );
  this.editelement[dpart] = document.createElement( "input" );
  this.editelement[dpart].id = dpart + "_text_" + this.baseid;
  this.editelement[dpart].className = "mdt_edit";
  this.editelement[dpart].setAttribute( "type", "text" );
  if ( dpart == "Y" )
  {
    this.editelement[dpart].setAttribute( "size", 4 );
  }
  else if ( dpart == "K" || dpart == "k" )
  {
    this.editelement[dpart].setAttribute( "size", 9 );
  }
  else if ( dpart == "L" || dpart == "l" )
  {
    this.editelement[dpart].setAttribute( "size", 3 );
  }
  else { this.editelement[dpart].setAttribute( "size", 2 ); }
  this.editelement[dpart].setAttribute( "value", val );
  this.editelement[dpart].onblur = this.mdt_text_blur;
  this.editelement[dpart].onkeypress = this.mdt_text_key;
  this.editelement[dpart].onmousewheel = this.mdt_text_wheel;
}
ManagedDatetime.prototype.punctuationpartDOM = function( punctuationpart )
{
  var txt = document.createTextNode( punctuationpart );
  this.span.appendChild( txt );
}
ManagedDatetime.prototype.buildDate = function()
{
  var c;
  for( var i = 0; i < this.dateformat.length; i++ )
  {
    c = this.dateformat.charAt( i );
    switch( c )
    {
      case "M" : this.datepartDOM( c, this.getZMonth() ); break;
      case "m" : this.datepartDOM( c, this.getMonth() ); break;
      case "L" : this.datepartDOM( c, this.getZMonthShortName() ); break;
      case "l" : this.datepartDOM( c, this.getMonthShortName() ); break;
      case "K" : this.datepartDOM( c, this.getZMonthName() ); break;
      case "k" : this.datepartDOM( c, this.getMonthName() ); break;
      case "D" : this.datepartDOM( c, this.getZDay() ); break;
      case "d" : this.datepartDOM( c, this.getDay() ); break;
      case "Y" : this.datepartDOM( c, this.getYear() ); break;
      case "y" : this.datepartDOM( c, this.getShortYear() ); break;
      case "H" : this.datepartDOM( c, this.getZHour() ); break;
      case "h" : this.datepartDOM( c, this.getHour() ); break;
      case "N" : this.datepartDOM( c, this.getZMinute() ); break;
      case "n" : this.datepartDOM( c, this.getMinute() ); break;
      case "S" : this.datepartDOM( c, this.getZSecond() ); break;
      case "s" : this.datepartDOM( c, this.getSecond() ); break;
      default  : this.punctuationpartDOM( c );
    }
  }
}
ManagedDatetime.prototype.getMonth = function()
{ return this.datetime.getMonth() + 1; }
ManagedDatetime.prototype.getZMonth = function()
{ return mdt_zpad( this.getMonth() ); }
ManagedDatetime.prototype.getMonthName = function()
{ return mdt_monthName[this.datetime.getMonth()]; }
ManagedDatetime.prototype.getZMonthName = function()
{ return this.getMonthName().toString().toUpperCase(); }
ManagedDatetime.prototype.getMonthShortName = function()
{ return mdt_monthShortName[this.datetime.getMonth()]; }
ManagedDatetime.prototype.getZMonthShortName = function()
{ return this.getMonthShortName().toString().toUpperCase(); }
ManagedDatetime.prototype.getDay = function()
{ return this.datetime.getDate(); }
ManagedDatetime.prototype.getZDay = function()
{ return mdt_zpad( this.getDay() ); }
ManagedDatetime.prototype.getWeekday = function()
{ return this.datetime.getDay(); }
ManagedDatetime.prototype.getWeekdayName = function()
{ return mdt_weekdayName[this.datetime.getDay()]; }
ManagedDatetime.prototype.getWeekdayShortName = function()
{ return mdt_weekdayShortName[this.datetime.getDay()]; }
ManagedDatetime.prototype.getYear = function()
{ return this.datetime.getFullYear(); }
ManagedDatetime.prototype.getShortYear = function()
{
  var yy;
  var yyyy = this.datetime.getFullYear();
  if ( yyyy < 2000 ) yy = yyyy - 1900;
  else yy = yyyy - 2000;
  return mdt_zpad( yy );
}
ManagedDatetime.prototype.getHour = function()
{ return this.datetime.getHours(); }
ManagedDatetime.prototype.getZHour = function()
{ return mdt_zpad( this.getHour() ); }
ManagedDatetime.prototype.getMinute = function()
{ return this.datetime.getMinutes(); }
ManagedDatetime.prototype.getZMinute = function()
{ return mdt_zpad( this.getMinute() ); }
ManagedDatetime.prototype.getSecond = function()
{ return this.datetime.getSeconds(); }
ManagedDatetime.prototype.getZSecond = function()
{ return mdt_zpad( this.getSecond() ); }
ManagedDatetime.prototype.getMillisecond = function()
{ return this.datetime.getMilliseconds(); }
ManagedDatetime.prototype.setMonth = function( m )
{
  if ( m > 0 && m < 13 )
  {
    if ( this.getDay() <= mdt_monthLength[mdt_isLeap(this.getYear())][m-1] )
      this.datetime.setMonth( m - 1 );
  }
}
ManagedDatetime.prototype.setZMonth = function( m ) { this.setMonth( m ); }
ManagedDatetime.prototype.setMonthName = function( m )
{
  var ix = mdt_monthIndex[m.toString().substring( 0, 3 ).toLowerCase()];
  if ( this.getDay() <= mdt_monthLength[mdt_isLeap(this.getYear())][ix] )
  {
    this.datetime.setMonth( ix );
  }
}
ManagedDatetime.prototype.setZMonthName = function( m )
{ this.setMonthName( m ); }
ManagedDatetime.prototype.setMonthShortName = function( m )
{ this.setMonthName( m ); }
ManagedDatetime.prototype.setZMonthShortName = function( m )
{ this.setMonthName( m ); }
ManagedDatetime.prototype.setDay = function( d )
{
  if ( d > this.lastDay() ) d = this.lastDay();
  if ( d > 0 ) this.datetime.setDate( d );
}
ManagedDatetime.prototype.setZDay = function( d ) { this.setDay( d ); }
ManagedDatetime.prototype.setYear = function( y )
{
  if ( y >= 0 && y < 50 ) { y = Number( y ) + 2000; }
  if ( y >= 50 && y < 1000 ) { y = Number( y ) + 1900; }
  if ( y > 0 ) this.datetime.setFullYear( y );
}
ManagedDatetime.prototype.setShortYear = function( y ) { this.setYear( y ); }
ManagedDatetime.prototype.setHour = function( h )
{
  if ( h >= 0 && h < 24 ) { this.datetime.setHours( h ); }
}
ManagedDatetime.prototype.setMinute = function( m )
{
  if ( m >= 0 && m < 60 ) { this.datetime.setMinutes( m ); }
}
ManagedDatetime.prototype.setZMinute = function( m ) { this.setMinute( m ); }
ManagedDatetime.prototype.setSecond = function( s )
{
  if ( s >= 0 && s < 60 ) { this.datetime.setSeconds( s ); }
}
ManagedDatetime.prototype.setZSecond = function( s ) { this.setSecond( s ); }
ManagedDatetime.prototype.setMillisecond = function( s )
{
  if ( s >= 0 && s < 1000 ) { this.datetime.setMilliseconds( s ); }
}
ManagedDatetime.prototype.lastDay = function()
{
  return mdt_monthLength[mdt_isLeap(this.getYear())][this.datetime.getMonth()];
}
ManagedDatetime.prototype.mdt_nextDatepart = function( dpart )
{
  var c, thisone = false, breakloop = false, nextpart = dpart;
  for( var i = 0; i < this.dateformat.length; i++ )
  {
    c = this.dateformat.charAt( i );
    switch( c )
    {
      case "K" :
      case "k" :
      case "L" :
      case "l" :
      case "M" :
      case "m" :
      case "D" :
      case "d" :
      case "Y" :
      case "y" :
      case "H" :
      case "h" :
      case "N" :
      case "n" :
      case "S" :
      case "s" :
        if ( thisone ) { nextpart = c; breakloop = true; }
        if ( c == dpart ) { thisone = true; }
        break;
    }
    if ( breakloop ) { break; }
  }
  return nextpart;
}
ManagedDatetime.prototype.mdt_prevDatepart = function( dpart )
{
  var c, thisone = false, breakloop = false, prevpart = dpart;
  for( var i = this.dateformat.length - 1; i >= 0; i-- )
  {
    c = this.dateformat.charAt( i );
    switch( c )
    {
      case "K" :
      case "k" :
      case "L" :
      case "l" :
      case "M" :
      case "m" :
      case "D" :
      case "d" :
      case "Y" :
      case "y" :
      case "H" :
      case "h" :
      case "N" :
      case "n" :
      case "S" :
      case "s" :
        if ( thisone ) { prevpart = c; breakloop = true; }
        if ( c == dpart ) { thisone = true; }
        break;
    }
    if ( breakloop ) { break; }
  }
  return prevpart;
}

// Global methods.
function mdt_editNext( bid, val, prev )
{
  var arr = bid.toString().split( "_" );
  var ndp;
  if ( prev ) { ndp = eval( arr[2] + ".mdt_prevDatepart('" + arr[0] + "')" ); }
  else { ndp = eval( arr[2] + ".mdt_nextDatepart('" + arr[0] + "')" ); }
  if ( ndp == arr[0] ) { return true; }
  else
  {
    var span = eval( arr[2] + ".span" );
    eval( arr[2] + ".set" + mdt_functions[arr[0]] + "('" + val + "')" );
    var str = eval( arr[2] + ".get" + mdt_functions[arr[0]] + "()" );
    var txt = document.createTextNode( str );
    var inp = eval( arr[2] + ".editelement['" + arr[0] + "']" );
    var anc = eval( arr[2] + ".displayelement['" + arr[0] + "']" );
    while( anc.childNodes.length > 0 )
    {
      anc.removeChild( anc.firstChild );
    }
    anc.appendChild( txt );
    span.replaceChild( anc, inp );
    anc = eval( arr[2] + ".displayelement['" + ndp + "']" );
    inp = eval( arr[2] + ".editelement['" + ndp + "']" );
    if ( anc.firstChild.nodeType == 3 )
    {
      inp.setAttribute( "value", anc.firstChild.nodeValue );
      span.replaceChild( inp, anc );
      inp.focus();
      inp.select();
    }
    return false;
  }
}
function mdt_datepartInrange( bid, val )
{
  var leadingZero = false;
  var arr = bid.toString().split( "_" );
  switch( arr[0] )
  {
    case "M" :
      leadingZero = true;
    case "m" :
    case "K" :
    case "k" :
    case "L" :
    case "l" :
      if ( val < 1 ) val = 12;
      if ( val > 12 ) val = 1;
      break;
    case "D" :
      leadingZero = true;
    case "d" :
      var ld = eval( arr[2] + ".lastDay()" );
      if ( val < 1 ) val = ld;
      if ( val > ld ) val = 1;
      break;
    case "Y" :
      if ( val < 0 ) val = 1999;
      break;
    case "y" :
      leadingZero = true;
      if ( val < 0 ) val = 99;
      if ( val > 99 ) val = 0;
      break;
    case "H" :
      leadingZero = true;
    case "h" :
      if ( val < 0 ) val = 23;
      if ( val > 23 ) val = 0;
      break;
    case "N" :
      leadingZero = true;
    case "n" :
      if ( val < 0 ) val = 59;
      if ( val > 59 ) val = 0;
      break;
    case "S" :
      leadingZero = true;
    case "s" :
      if ( val < 0 ) val = 59;
      if ( val > 59 ) val = 0;
      break;
  }
  if ( leadingZero ) return mdt_zpad( val );
  else return val;
}
function mdt_adjoiningValue( eid, skipvalue, ascend )
{
  var dpart = eid.toString().split( "_" )[0];
  var elem = document.getElementById( eid );
  if ( elem )
  {
    if ( dpart == 'K' || dpart == 'k' || dpart == 'L' || dpart == 'l' )
    {
      var ix = mdt_monthIndex[elem.value.toString().substring(0,3).toLowerCase()];
      if ( ascend ) ix += skipvalue;
      else ix -= skipvalue;
      ix = mdt_datepartInrange( elem.id, ix + 1 ) - 1;
      if ( dpart == 'K' || dpart == 'k' ) elem.value = mdt_monthName[ix];
      else elem.value = mdt_monthShortName[ix];
      if ( dpart == 'K' || dpart == 'L' )
        elem.value = elem.value.toString().toUpperCase();
    }
    else
    {
      if ( ascend ) { elem.value = Number( elem.value ) + skipvalue; }
      else { elem.value = Number( elem.value ) - skipvalue; }
      elem.value = mdt_datepartInrange( elem.id, elem.value );
    }
    elem.select();
  }
}
function mdt_monthNameKey( eid, c )
{
  var cc;
  var elem = document.getElementById( eid );
  if ( elem )
  {
    var sc = String.fromCharCode( c );
    var lc = sc.toLowerCase();
    var lv = elem.value.toString().toLowerCase();
    var dpart = eid.toString().split( "_" )[0];
    if ( lv.length < 3 )
    {
      if ( dpart == 'K' || dpart == 'k' )
        cc = mdt_monthName[mdt_monthIndex[lv + lc]];
      else cc = mdt_monthShortName[mdt_monthIndex[lv + lc]];
    }
    else
    {
      if ( dpart == 'K' || dpart == 'k' )
        cc = mdt_monthName[mdt_monthIndex[lc]];
      else cc = mdt_monthShortName[mdt_monthIndex[lc]];
    }
    if ( cc == undefined ) { return true; }
    else
    {
      if ( dpart == 'K' || dpart == 'L' ) elem.value = cc.toUpperCase();
      else elem.value = cc;
      elem.select();
      return false;
    }
  }
  return true;
}
function mdt_isMonthName( eid )
{
  var dpart = eid.toString().split( "_" )[0];
  if ( dpart == 'K' || dpart == 'k' || dpart == 'L' || dpart == 'l' )
    return true;
  else return false;
}
function mdt_zpad( n )
{
  if ( n.toString().length == 1 ) n = '0' + n;
  return n;
}
function mdt_callRemote( el )
{
  var ref = el.toString().split( "_" )[2];
  var thisref = eval( ref );
  if ( thisref && thisref.blurrproc )
  {
    eval( thisref.blurrproc + "('" + ref + "')" );
  }
}
function mdt_isLeap( yr )
{
  if ( ( yr ) % 4 == 0 && ( yr ) % 100 != 0 || ( yr ) % 400 == 0 ) return 1;
  return 0;
}

// Global data.
var mdt_monthLength = [[31,28,31,30,31,30,31,31,30,31,30,31],[31,29,31,30,31,30,31,31,30,31,30,31]];
var mdt_weekdayName = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var mdt_weekdayShortName = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
var mdt_weekdayAbreviation = ["S","M","T","W","T","F","S"];
var mdt_monthName = ["January","February","March","April","May","June","July","August","September","October","November","December"];
var mdt_monthShortName = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var mdt_monthIndex = new Array();
mdt_monthIndex["jan"] = 0;
mdt_monthIndex["feb"] = 1;
mdt_monthIndex["mar"] = 2;
mdt_monthIndex["apr"] = 3;
mdt_monthIndex["may"] = 4;
mdt_monthIndex["jun"] = 5;
mdt_monthIndex["jul"] = 6;
mdt_monthIndex["aug"] = 7;
mdt_monthIndex["sep"] = 8;
mdt_monthIndex["oct"] = 9;
mdt_monthIndex["nov"] = 10;
mdt_monthIndex["dec"] = 11;
mdt_monthIndex["ja"] = 0;
mdt_monthIndex["ap"] = 3;
mdt_monthIndex["au"] = 7;
mdt_monthIndex["f"] = 1;
mdt_monthIndex["s"] = 8;
mdt_monthIndex["o"] = 9;
mdt_monthIndex["n"] = 10;
mdt_monthIndex["d"] = 11;

var mdt_functions = new Array();
mdt_functions["K"] = "ZMonthName";
mdt_functions["k"] = "MonthName";
mdt_functions["L"] = "ZMonthShortName";
mdt_functions["l"] = "MonthShortName";
mdt_functions["M"] = "ZMonth";
mdt_functions["m"] = "Month";
mdt_functions["D"] = "ZDay";
mdt_functions["d"] = "Day";
mdt_functions["Y"] = "Year";
mdt_functions["y"] = "ShortYear";
mdt_functions["H"] = "ZHour";
mdt_functions["h"] = "Hour";
mdt_functions["N"] = "ZMinute";
mdt_functions["n"] = "Minute";
mdt_functions["S"] = "ZSecond";
mdt_functions["s"] = "Second";

var mdt_cBackSpace = 8;
var mdt_cTab = 9;
var mdt_cEnter = 13;
var mdt_cShift = 16;
var mdt_cCtrl = 17;
var mdt_cAlt = 18;
var mdt_cEsc = 27;
var mdt_cSpace = 32;
var mdt_cPageUp = 33;
var mdt_cPageDown = 34;
var mdt_cPageEnd = 35;
var mdt_cPageHome = 36;
var mdt_cLeftArrow = 37;
var mdt_cUpArrow = 38;
var mdt_cRightArrow = 39;
var mdt_cDownArrow = 40;
var mdt_cPlus = 43;
var mdt_cComa = 44;
var mdt_cMinus = 45;
var mdt_cPeriod = 46;
var mdt_cForwardSlash = 47;
var mdt_cColon = 58;
var mdt_cSemiColon = 59;
var mdt_cBackSlash = 92;
var mdt_cDelete = 127;


