/*
    $Id$
 */

var fso = new ActiveXObject("Scripting.FileSystemObject");
// Helper functies
// 2013-11-13T07:00:00
function xmltojsdate(datestamp)
{
  var pattern = /^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)$/;
  var pieces = datestamp.match(pattern);
  if(!pieces || pieces.length < 6)
    return null;

  return new Date(pieces[1], pieces[2]-1, pieces[3], pieces[4], pieces[5], pieces[6]);
}
function jsdatextoxml(dt)
{
  return toDateString(dt) + "T" + toTimeString(dt);
}
function jsdatetosqls(jsDate)
{
  return jsDate.getVarDate();
}
function padout(number) { return (number < 10) ? "0" + number : String(number); }

// Noot: altijd jaar vooraan, goed voor logfiles, niet bedoeld voor presentatie
function toDateString(jsDate)
{
    return padout(jsDate.getFullYear()) + "-" + padout(jsDate.getMonth() + 1) + "-" + padout(jsDate.getDate());
}
function toTimeString(jsDate)
{
    return padout(jsDate.getHours()) + ":" + padout(jsDate.getMinutes()) + ":" + padout(jsDate.getSeconds());
}
function __Log(s, level)
{
    WScript.Echo(s);
    var dt = new Date;
    var logname = "fclt2unit4_" + padout(dt.getFullYear())  + "_" + padout(dt.getMonth() + 1) + ".log";
    var flog = fso.OpenTextFile(logname, 8 /* ForAppending */, true /* create */);
    var tms = toDateString(new Date) + " " + toTimeString(new Date);
    flog.WriteLine(tms + " " + s);
    flog.Close();
}
