function countDown(d,h,m,s) {
    
//    if (h < 10 && String(h).charAt(0) != '0') h = "0"+h;
//    if (m < 10 && String(m).charAt(0) != '0') m = "0"+m;
//    if (s < 10 && String(s).charAt(0) != '0') s = "0"+s;

    if (String(d).length == 1) d = "0"+d;
    if (String(h).length == 1) h = "0"+h;
    if (String(m).length == 1) m = "0"+m;
    if (String(s).length == 1) s = "0"+s;

    $("#countdownTimer").html('<div id="days">'+d+'</div><div id="hours">'+h+'</div><div id="minutes">'+m+'</div><div id="seconds">'+s+'</div>');
    t=setTimeout(function (){
        if (s > 0) {
            s = s-1;
        } else {
            s = 59;
            if (m > 0) {
                m = m-1;
            } else {
                m = 59;
                if (h > 0) {
                    h = h-1;
                } else {
                    h = 23;
                    if (d > 0) {
                        d = d-1;
                    }
                }
            }
        }

        countDown(d,h,m,s);
    }, 1000);
}

window.onload = function () {
    $.get("time.php", function(data){

       days = Math.floor(data / 86400);
       hours = Math.floor((data - (days * 86400)) / 3600);
       minutes = Math.floor((data - (days * 86400) - (hours * 3600)) / 60);
       seconds = Math.floor(data - (days * 86400) - (hours * 3600) - (minutes * 60));

       countDown(days,hours,minutes,seconds);
    });
}

