﻿var start = new Date();
var epochs = Math.floor(start.getTime() / 1000);

function hms(s) {
    if (s > -1) {
        hours = Math.floor(s / 3600);
        minutes = Math.floor(s / 60) % 60;
        seconds = s % 60;
        if (hours > 0) t = hours + ":";
        else t = "";
        if (minutes < 10) { t += "0"; } t += minutes + ":";
        if (seconds < 10) { t += "0"; } t += seconds;
    }
    else {
        t = "00:00";
        if (s > -2 && s <= -1) {
            location = location;
        }
    }
    return "{" + t + "}";
}

function cd(id) {
    var now = new Date();
    var epochn = Math.floor(now.getTime() / 1000);
    var show = eval(id) - epochn + epochs;
    document.getElementById(id).innerHTML = hms(show);
    if (show > -1) setTimeout("cd('" + id + "')", 1000);
}

function acc(id, amt) {
    var now = new Date();
    var epochn = Math.floor(now.getTime() / 1000);
    var show = eval(id) + Math.floor((epochn - epochs) * amt / 3600);
    //	var localed = show.toLocaleString();
    //	var without_decimals = localed.substring(0, localed.length - 3);
    document.getElementById(id).innerHTML = show;
    setTimeout("acc('" + id + "'," + amt + ")", 1000);
}

function dec(id, amt) {
    var now = new Date();
    var epochn = Math.floor(now.getTime() / 1000);
    var show = eval(id) - Math.floor((epochn - epochs) / amt);
    //	var localed = show.toLocaleString();
    //	var without_decimals = localed.substring(0, localed.length - 3);
    document.getElementById(id).innerHTML = show;
    setTimeout("dec('" + id + "'," + amt + ")", 1000);
}

function hms_bomb(s, launch_code) {
    if (s > -1) {
        hours = Math.floor(s / 3600);
        minutes = Math.floor(s / 60) % 60;
        seconds = s % 60;
        t = "";
        if (seconds < 10) { t += "0"; }
        t += seconds;
    }
    else {
        t = "!!!!";
        location = location + "&launch_code=" + launch_code;
    }
    return "{{" + t + "}}";
}


function cd_bomb(id, launch_code) {
    var now = new Date();
    var epochn = Math.floor(now.getTime() / 1000);
    var show = eval(id) - epochn + epochs;
    document.getElementById(id).innerHTML = hms_bomb(show, launch_code);
    if (show > -1) setTimeout("cd_bomb('" + id + "','" + launch_code + "')", 300);
}
