// Script c/o  jakob.aggernaes@get2net.dk

// Type in event and time below.
// After "var event" inbetween the double-quotes, type what you want to say after "until" and "after"
var event   = "your taxes are due!"
// After "var eYear" type the year that the countdown will expire in
var eYear   = 2012  // from AD.101 to AD.4500
// After "var eMonth" type the Month that the countdown will expire in Starting at 0 Jan=0 Dec=11
var eMonth  =  3    // 0..11  ( 0=january, 11=december )
// After "var eDay" type the date that the countdown will expire on (i.e. 15 = the 15th)
var eDay    = 15    // 1..31
var eHour   = 00    // 0..23
var eMinute = 00    // 0..59
var eSecond = 00    // 0..59


var debugOn = false;
function debug(str) { if (debugOn==true) debugOn = confirm(str); };


function setTarget ( tid, year, month, day, hour, minute, second ) {
  this.tEvent  = tid;    // string
  this.tYear   = year;   // range 1970..2037
  this.tMonth  = month;  // range 0..11 (jan=0, dec=11)
  this.tDay    = day;    // range 0..31
  this.tHour   = hour;   // range 0..23
  this.tMinute = minute; // range 0..59
  this.tSecond = second; // range 0..59
  this.tDate   = new Date( year, month, day, hour, minute, second );
  this.t       = Date.parse( this.tDate.toGMTString() );
debug ("setTarget: tSecond = " +this.tSecond);
  return this;
}; // end setTarget( ... ) -> object

var target = new setTarget ( event, eYear, eMonth, eDay, eHour, eMinute, eSecond );

function setDelta() {
  this.nDate    = new Date();
  this.n        = Date.parse( this.nDate.toGMTString() );
  this.dSecond = Math.round( ( target.t -this.n ) / 1000 );
debug ("setTarget: dSecond = " +this.dSecond);
  if ( 0 > this.dSecond ) {
    this.dSecond = -this.dSecond;
    this.d = 1;
  } else {
    this.d = -1;
  };
  this.dMinute = Math.floor( this.dSecond/60 );
  this.dSecond = this.dSecond -(this.dMinute * 60)
  this.dHour   = Math.floor( this.dMinute/60 );
  this.dMinute = this.dMinute -(this.dHour * 60)
  this.dDay    = Math.floor( this.dHour/24 );
  this.dHour   = this.dHour -(this.dDay * 24);
  return this;
}; // end setTarget( ... ) -> object

var delta  = new setDelta ();

var digits = new Array( "0", "1", "2", "3",
         "4", "5", "6", "7", "8", "9", "none" );
for (i=0; digits.length>i; i++) {
  digits[i] = "images/ciffer"+digits[i]+".gif";
};

var imgOff = -1; // index of document.images["c0"];
var charTab = "0123456789 "; // de anvendte billeder

function showVal ( val, size, offset ) {
  var i = 0;
  if (0 > imgOff) {
    for (i=0; (document.images.length>i) && (0>imgOff); i++) {
      if (document.images[i]==document.images.c0) {
        imgOff = i;
      }; //endif
    }; //endfor
    if (0 > imgOff ) {
             debug( "showVal: imgOff value not found" );
    } else { debug( "showVal: imgOff = " +imgOff );
    }; //endif
  }; //endif
  var txVal = ":    "+val;
  txVal = txVal.substring(txVal.length-size);
  for (i=0; txVal.length>i; i++) {
    document.images[i+offset+imgOff].src =
        digits[ charTab.indexOf( txVal.substring(i,i+1) ) ]
  }; //endfor
}; //end showVal ( number, length, offset )

var updateHand = setInterval("showTimeLeft()",1000);

function showTimeLeft() {
  var increment = delta.d;
  delta = new setDelta();
  if (delta.d != increment) window.location.reload();
  showVal( delta.dDay, 4, 0 );
  showVal( delta.dHour, 2, 4 );
  showVal( delta.dMinute, 2, 6 );
  showVal( delta.dSecond, 2, 8 );
}; //end showTimeLeft()


