startCountDown = function()
{
    countdown(cd_date);
}

countdown = function(eventDateString)
{
    if (document.getElementById && document.getElementById('cd_days'))
    {
        setTimeout(startCountDown, 200);
        
        var curDate = new Date();
        var eventDate = new Date();
        eventDate.setTime(Date.parse(eventDateString));
        
        //start setting fields
        
        if (curDate.getTime() < eventDate.getTime())
        {
            var diff = Math.floor((eventDate.getTime() - curDate.getTime()) / 1000);
            
            // seconds
            document.getElementById('cd_seconds').firstChild.nodeValue = diff % 60;
            diff = Math.floor(diff / 60);
            
            // minutes
            document.getElementById('cd_minutes').firstChild.nodeValue = diff % 60;
            diff = Math.floor(diff / 60);
            
            document.getElementById('cd_hours').firstChild.nodeValue = diff % 24;
            diff = Math.floor(diff / 24);
            
            document.getElementById('cd_days').firstChild.nodeValue = diff;
            
        }
        else
        {
            document.getElementById('cd_days').firstChild.nodeValue = '0';
            document.getElementById('cd_hours').firstChild.nodeValue = '0';
            document.getElementById('cd_minutes').firstChild.nodeValue = '0';
            document.getElementById('cd_seconds').firstChild.nodeValue = '0';
            return; // exit function
        }
    }
}

if(window.attachEvent)
    window.attachEvent("onload", startCountDown);
else
    window.addEventListener("load", startCountDown, false);
