// fill input fields
function labelup() {
  if (document.getElementById) {
    var labels = document.getElementsByTagName('label');
    for (var i=0; i < labels.length; i++) {
      x=labels[i].attributes['for'].nodeValue; // .htmlFor
      y=labels[i].firstChild.data;
      labels[i].className='yank';
      elx = document.getElementById(x);
      elx.value = y;
      elx.onclick = function(){ this.select() };
    };
  }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {window.onload = func;}
  else {
    window.onload = function() {
      if (oldonload) { oldonload(); }
      func();
    }
  }
}



// countdown timer
var preloaded = new Array();
function preload_images() {
  for (var i = 0; i < arguments.length; i++){
    preloaded[i] = document.createElement('img');
    preloaded[i].setAttribute('src',arguments[i]);
  };
};

var pathToGrafix = "fileadmin/templates/countdown/";

preload_images( pathToGrafix + '0.gif',  pathToGrafix + '1.gif',  pathToGrafix + '2.gif',  pathToGrafix + '3.gif',  pathToGrafix + '4.gif',  pathToGrafix + '5.gif',  pathToGrafix + '6.gif',  pathToGrafix + '7.gif',  pathToGrafix + '8.gif',  pathToGrafix + '9.gif',  pathToGrafix + 'sep.gif');

function setclock(year, month, day, hour, minute) {
   html_code =
    '<p id="countdown">' +
      '<img id="day0"    src="fileadmin/templates/countdown/0.gif"   height="57" />' +
      '<img id="day1"    src="fileadmin/templates/countdown/0.gif"   height="57" />' +
      '<img id="day2"    src="fileadmin/templates/countdown/0.gif"   height="57" />' +
      '<img id="sep0"    src="fileadmin/templates/countdown/sep.gif" height="57" />' +
      '<img id="hour0"   src="fileadmin/templates/countdown/0.gif"   height="57" />' +
      '<img id="hour1"   src="fileadmin/templates/countdown/0.gif"   height="57" />' +
      '<img id="sep1"    src="fileadmin/templates/countdown/sep.gif" height="57" />' +
      '<img id="minute0" src="fileadmin/templates/countdown/0.gif"   height="57" />' +
      '<img id="minute1" src="fileadmin/templates/countdown/0.gif"   height="57" />' +
      '<img id="sep2"    src="fileadmin/templates/countdown/sep.gif" height="57" />' +
      '<img id="second0" src="fileadmin/templates/countdown/0.gif"   height="57" />' +
      '<img id="second1" src="fileadmin/templates/countdown/0.gif"   height="57" />' +
    '</p>';

   document.write(html_code);
   countdown(year, month, day, hour, minute);
}

function countdown(year, month, day, hour, minute) {
  // get UTC date
  now = new Date();
  localTime = now.getTime();
  offset = now.getTimezoneOffset() * 60000;
  today = new Date(localTime + offset);
  todaysYear = today.getFullYear();
  todaysMonth = today.getMonth();
  // dates to miliseconds
  todaysDate = (new Date(todaysYear, todaysMonth, today.getDate(), today.getHours(), today.getMinutes(), today.getSeconds())).getTime();                                 
  targetDate = (new Date(year, month - 1, day, hour, minute, 00)).getTime();                  
  timeLeft = Math.round((targetDate - todaysDate) / 1000);
  if(timeLeft < 0) timeLeft = 0;

  // double digits
  days = Math.floor(timeLeft / (60 * 60 * 24));
    if (days < 100 && days >= 10) {days = '0' + days;}
    else
       if (days <  10) {days = '00' + days;}
  timeLeft %= (60 * 60 * 24);
  hours = Math.floor(timeLeft / (60 * 60));
    if (hours < 10) {hours = '0' + hours;}
  timeLeft %= (60 * 60);
  minutes = Math.floor(timeLeft / 60);
    if (minutes < 10) {minutes = '0' + minutes;}
  timeLeft %= 60;
  seconds = timeLeft;
    if (seconds < 10) {seconds = '0' + seconds;}

  d0New = days.toString().charAt(0);
  d1New = days.toString().charAt(1);
  d2New = days.toString().charAt(2);
  h1New = hours.toString().charAt(0);
  h2New = hours.toString().charAt(1);
  m1New = minutes.toString().charAt(0);
  m2New = minutes.toString().charAt(1);
  s1New = seconds.toString().charAt(0);
  s2New = seconds.toString().charAt(1);

if( typeof d0 === 'undefined' || neq(d0New,d0) ) { d0 = d0New; document.getElementById("day0"   ).src = pathToGrafix + d0 + '.gif'; }
if( typeof d1 === 'undefined' || neq(d1New,d1) ) { d1 = d1New; document.getElementById("day1"   ).src = pathToGrafix + d1 + '.gif'; }
if( typeof d2 === 'undefined' || neq(d2New,d2) ) { d2 = d2New; document.getElementById("day2"   ).src = pathToGrafix + d2 + '.gif'; }
if( typeof h1 === 'undefined' || neq(h1New,h1) ) { h1 = h1New; document.getElementById("hour0"  ).src = pathToGrafix + h1 + '.gif'; }
if( typeof h2 === 'undefined' || neq(h2New,h2) ) { h2 = h2New; document.getElementById("hour1"  ).src = pathToGrafix + h2 + '.gif'; }
if( typeof m1 === 'undefined' || neq(m1New,m1) ) { m1 = m1New; document.getElementById("minute0").src = pathToGrafix + m1 + '.gif'; }
if( typeof m2 === 'undefined' || neq(m2New,m2) ) { m2 = m2New; document.getElementById("minute1").src = pathToGrafix + m2 + '.gif'; }
if( typeof s1 === 'undefined' || neq(s1New,s1) ) { s1 = s1New; document.getElementById("second0").src = pathToGrafix + s1 + '.gif'; }
if( typeof s2 === 'undefined' || neq(s2New,s2) ) { s2 = s2New; document.getElementById("second1").src = pathToGrafix + s2 + '.gif'; }

/*
  document.getElementById('countdown').innerHTML  = '<img src="' + pathToGrafix + d0 + '.gif" alt="' + d0+d1+d2  + ':' + h1+h2 + ':' + m1+m2 +'" height="57"/>';
  document.getElementById('countdown').innerHTML += '<img src="' + pathToGrafix + d1 + '.gif" alt="" height="57"/>';
  document.getElementById('countdown').innerHTML += '<img src="' + pathToGrafix + d2 + '.gif" alt="" height="57"/><img src="' + pathToGrafix + 'sep.gif" alt="" height="57" />';
  document.getElementById('countdown').innerHTML += '<img src="' + pathToGrafix + h1 + '.gif" alt="" height="57"/>';
  document.getElementById('countdown').innerHTML += '<img src="' + pathToGrafix + h2 + '.gif" alt="" height="57"/><img src="' + pathToGrafix + 'sep.gif" alt="" height="57" />';
  document.getElementById('countdown').innerHTML += '<img src="' + pathToGrafix + m1 + '.gif" alt="" height="57"/>';
  document.getElementById('countdown').innerHTML += '<img src="' + pathToGrafix + m2 + '.gif" alt="" height="57"/><img src="' + pathToGrafix + 'sep.gif" alt="" height="57" />';
  document.getElementById('countdown').innerHTML += '<img src="' + pathToGrafix + s1 + '.gif" alt="" height="57"/>';
  document.getElementById('countdown').innerHTML += '<img src="' + pathToGrafix + s2 + '.gif" alt="" height="57"/>';
*/  
  //document.getElementById('countdown').innerHTML += days + ' : ' + hours + ' : ' + minutes + ' : ' + seconds;
  setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ');', 1000);
}

function neq( a, b )
{
   return a != b;
}







//addLoadEvent(labelup);

// hitslink
/*
wa_account="OperaDragonfly"; wa_location=27;
wa_pageName=location.pathname;  // you can customize the page name here
document.cookie='__support_check=1';wa_hp='http';
wa_rf=document.referrer;wa_sr=window.location.search;
wa_tz=new Date();if(location.href.substr(0,6).toLowerCase()=='https:')
wa_hp='https';wa_data='&an='+escape(navigator.appName)+ 
'&sr='+escape(wa_sr)+'&ck='+document.cookie.length+
'&rf='+escape(wa_rf)+'&sl='+escape(navigator.systemLanguage)+
'&av='+escape(navigator.appVersion)+'&l='+escape(navigator.language)+
'&pf='+escape(navigator.platform)+'&pg='+escape(wa_pageName);
wa_data=wa_data+'&cd='+
screen.colorDepth+'&rs='+escape(screen.width+ ' x '+screen.height)+
'&tz='+wa_tz.getTimezoneOffset()+'&je='+ navigator.javaEnabled();
wa_img=new Image();wa_img.src=wa_hp+'://counter.hitslink.com/statistics.asp'+
'?v=1&s='+wa_location+'&acct='+wa_account+wa_data+'&tks='+wa_tz.getTime();
document.getElementById('wa_u').src=wa_hp+'://counter.hitslink.com/track.js';
*/
