// Formats date and time as "2000.01.20 17:00"
Date.prototype.toFormattedString = function(include_time)
{
   str = this.getFullYear() + "." + Date.padded2(this.getMonth()+1) + "." + Date.padded2(this.getDate());
   if (include_time) { str += " " + this.getHours() + ":" + this.getPaddedMinutes(); }
   return str;
}

Date.parseFormattedString = function (string) 
{
  var regexp = '([0-9]{2,4})(\.([0-9]{1,2})(\.([0-9]{1,2})( ([0-9]{1,2}):([0-9]{2})? *)?)?)?';
  var d = string.match(new RegExp(regexp, "i"));

  if (d==null) return Date.parse(string); // at least give javascript a crack at it.
  var offset = 0;
  
  if (d[1] && d[1].length == 2) {
    // we got only two digits for the year...
    d[1] = Number(d[1]);
    if (d[1] > 30)
      d[1] += 1900;
    else
      d[1] += 2000;
  }
  var date = new Date(d[1], 0, 1);
  if (d[3]) { date.setMonth(d[3] - 1); }
  if (d[5]) { date.setDate(d[5]); }
  if (d[7]) {
    date.setHours(parseInt(d[7], 10));    
  }
  if (d[8]) { date.setMinutes(d[8]); }
  if (d[10]) { date.setSeconds(d[10]); }
  return date;
}

