// <script type="text/javascript" src="timer.js"></script>
// only included in the tweedbar.php if $meta_refresh true
// <span id="cd"></span>
//var minute      = nowDate.getMinutes();
//var second      = now.getSeconds();
//var hour = nowDate.getHours();
//var day         = nowDate.getDate();
//var monthnumber = now.getMonth();
//var year        = nowDate.getYear();
var secondsplus = 10;
var nowDate = new Date();
//here We Have The Time until The countdown ends
var year = nowDate.getFullYear();    //nowDate.getYear();        // this year
var month = nowDate.getMonth();      // this month
var day = nowDate.getDate();         // this day
var hour = nowDate.getHours();       // this hour
var minute = nowDate.getMinutes();   // this Minute
var seconds = nowDate.getSeconds();  // this Seconds
var tz = 10;     // offset in hours from UTC to your timezone
var lab = 'cd';  // id of the entry on the page where the counter is to be inserted

function start() {
  displayCountdown(setCountdown(year,month,day,hour,minute,seconds,secondsplus,tz),lab);
}
window.onload = start;
// Countdown Javascript
// copyright 20th April 2005, 1st April 2006 by Stephen Chapman
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
// you may change the start function if required
function setCountdown(year,month,day,hour,minute,seconds,secondsplus,tz) {
  var toDate = new Date();
  toDate.setDate(day);
  toDate.setYear(year);
  toDate.setMonth(month);
  toDate.setHours(hour);
  toDate.setMinutes(minute - (tz*60));
  toDate.setSeconds(seconds + secondsplus); //ie +10 Seconds
  var fromDate = new Date();
  fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
  var diffDate = new Date(0);
  diffDate.setMilliseconds(toDate - fromDate);
  //alert("Countdown From: " + toDate);
  return Math.floor(diffDate.valueOf()/1000);
}

function displayCountdown(countdn,cd) {
  if (countdn < 0) {
    document.getElementById(cd).innerHTML = "Sorry, you need to Refresh The Page Manually.";
  }else {
    var secs = countdn % 60; 
    //if (secs < 10) { secs = '0'+secs; }
    var sectext = ' seconds';
    if (secs < 2) { sectext = ' second '; }
    var countdn1 = (countdn - secs) / 60;
    var mins = countdn1 % 60;
    if (mins < 10) { mins = '0'+mins; }
    countdn1 = (countdn1 - mins) / 60;
    var hours = countdn1 % 24;
    var days = (countdn1 - hours) / 24;
    //document.getElementById(cd).innerHTML = days+' days + '+hours+' : '+mins+' : '+secs;
    document.getElementById(cd).innerHTML = secs + sectext;
    setTimeout('displayCountdown('+(countdn-1)+',\''+cd+'\');',999);
  }
}