var timerID;
var past_time = 0;

function UpdateClocks() {
    past_time++;
    
    var dt = new Date();
    var startDST = new Date(dt.getFullYear(), 3, 1);
    while (startDST.getDay() != 0)
        startDST.setDate(startDST.getDate() + 1);
    var endDST = new Date(dt.getFullYear(), 9, 31);
    while (endDST.getDay() != 0)
        endDST.setDate(endDST.getDate() - 1);
    var ds_active;
    if (startDST < dt && dt < endDST) ds_active = 1; else ds_active = 0;
    var printstr = "";
    gmdt = new Date();
    for (n = 0; n < ct.length; n++) {
        ct[n].ct = new Date((ct[n].ts + past_time) * 1000);
    } 
    document.getElementById('Clockk0').innerHTML = ClockString(ct[0].ct);
    document.getElementById('Clockk1').innerHTML = ClockString(ct[1].ct);
    document.getElementById('Clockk2').innerHTML = ClockString(ct[2].ct);
    document.getElementById('Clockk3').innerHTML = ClockString(ct[3].ct);
    document.getElementById('Clockk4').innerHTML = ClockString(ct[4].ct);
    document.getElementById('Clockk5').innerHTML = ClockString(ct[5].ct);
    timerID = window.setTimeout("UpdateClocks()", 1001);
}

function ClockString(dt) {
    var stemp;
    var dt_year = dt.getUTCFullYear();
    var dt_month = dt.getUTCMonth() + 1;
    var dt_day = dt.getUTCDate();
    var dt_hour = dt.getUTCHours();
    var dt_minute = dt.getUTCMinutes();
    var dt_second = dt.getUTCSeconds();
    dt_year = dt_year.toString();
    if (dt_hour < 10)
        dt_hour = '0' + dt_hour;
    if (dt_minute < 10)
        dt_minute = '0' + dt_minute;

    if (dt_second < 10)
        dt_second = '0' + dt_second;

    stemp = dt_month + '-' + dt_day;
    stemp = stemp + ' ' + dt_hour + ":" + dt_minute + ":" + dt_second;
    return stemp;
}


function DrawImage(ImgD, width, height) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= width / height) {
            if (image.width > width) {
                ImgD.width = width;
                ImgD.height = (image.height * width) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        else {
            if (image.height > height) {
                ImgD.height = height;
                ImgD.width = (image.width * height) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
}
