/*
-------------------------------------------------------------------------------
Drivers' Club Oy JavaScript
Author: Frametic
Version: 24.01.2010

Copyright (c) 2009-2010 Frametic. All rights reserved.
---------------------------------------------------------------------------- */

function countdown(year, month, day) {
    // Initialize the variables
    var seconds = "00";
    var minutes = "00";
    var hours = "00";
    var days = "00";

    var timestamp_now = new Date();
    var timestamp_target = new Date(year, month, day, 17, 0, 0);

    if (timestamp_now < timestamp_target) {
        var difference = timestamp_target - timestamp_now;

        // Converting the remaining time into seconds, minutes, hours and days
        seconds = Math.floor(difference / 1000);
        minutes = Math.floor(seconds / 60);
        hours = Math.floor(minutes / 60);
        days = Math.floor(hours / 24);

        // Storing the remaining ones
        seconds %= 60;
        minutes %= 60;
        hours %= 24;

        if (seconds < 10) {
            seconds = "0" + seconds;
        }

        if (minutes < 10) {
            minutes = "0" + minutes;
        }

        if (hours < 10) {
            hours = "0" + hours;
        }

        if (days < 10) {
            days = "0" + days;
        }

        // Update the DOM
        populate_dom_countdown(days, hours, minutes, seconds);
    } else {
        // Update the DOM
        populate_dom_countdown(days, hours, minutes, seconds);
    }
}

function populate_dom_countdown(days, hours, minutes, seconds) {
    // Update the DOM elements of the countdown
    document.getElementById("days").innerHTML = days;
    document.getElementById("hours").innerHTML = hours;
    document.getElementById("minutes").innerHTML = minutes;
    document.getElementById("seconds").innerHTML = seconds;
}

