function updateTimes() {
    updateCurrentTime();
    updateEorzeaTime();
}
function updateCurrentTime() {
    var curTime = new Date();
    var curHours = curTime.getHours();
    var curMins = curTime.getMinutes();
    var curSecs = curTime.getSeconds();
    var timeOfDay = (curHours < 12) ? "AM" : "PM";

    curHours = (curHours < 12) ? curHours - 12 : curHours;
    curHours = ((curHours < 10) ? "0" : "") + curHours;
    curMins = ((curMins < 10) ? "0" : "") + curMins;
    curSecs = ((curSecs < 10) ? "0" : "") + curSecs;

    // var timeString = curHours + ":" + curMins + ":" + curSecs + " " + timeOfDay;
    var timeString = curTime.toLocaleTimeString();

    document.getElementById("currenttime").firstChild.nodeValue = timeString;
}
function updateEorzeaTime() {
    // Vars to be used below
    var ratioRealToGame = (1440 / 70);

    // Convert local time to GMT
    var curTime = new Date();

    // Check for DST, and counter if necessary
    var arr = DstDetect();
    var isDST = 1;
    if (curTime >= arr[0] && curTime <= arr[1]) {
        isDST = 0;
    }
    var localTime = curTime.getTime();
    var d = (curTime.getTimezoneOffset() + (isDST * 60));
    var localOffest = (curTime.getTimezoneOffset() + (isDST * 60)) * 60000;  // Convert to miliseconds
    var utc = localTime + localOffest;
    var offset = 9;  // JP Offset
    var japan = utc + (3600000 * offset);
    var jpTime = new Date(japan);

    // Get time span since epoch in millis
    var Epoch = new Date(2010, 6, 12, 0, 0, 0, 0);
    var curMillis = jpTime.getTime();
    var epochMillis = Epoch.getTime();
    var diffInMillis = (curMillis - epochMillis);
    var diffInSeconds = ((diffInMillis / 1000) - 90000);

    // Convert to game time
    var delta = (diffInSeconds * ratioRealToGame);

    var gameSecond = (delta % 60) | 0;
    delta -= gameSecond;
    delta /= 60.0;

    var gameMinute = (delta % 60) | 0;
    delta -= gameMinute;
    delta /= 60.0;

    var gameHour = (delta % 24) | 0;
    delta -= gameHour;
    delta /= 24.0;

    var gameDay = (delta % 32) | 0;
    delta -= gameDay;
    delta /= 32.0;

    var gameMonth = (delta % 12) | 0;
    delta -= gameMonth;
    delta /= 12.0;

    var gameYear = delta | 0;

    gameDay++;
    gameMonth++;
    gameMinute++;

    if(gameMinute == 60) {
	gameHour++;
	gameMinute = 00;
    }
    gameMonth = ((gameMonth < 10 ? "0" : "") + gameMonth);
    gameDay = ((gameDay < 10 ? "0" : "") + gameDay);
    gameMinute = ((gameMinute < 10 ? "0" : "") + gameMinute);
    // Display
    document.getElementById("eorzeatime").firstChild.nodeValue = gameMonth + "/" + gameDay + "/" + gameYear + " ~ " + gameHour + ":" + gameMinute;
    //document.title = "Time in Japan: " + jpTime.toDateString() + " " + jpTime.toTimeString();
}
function TimezoneDetect() {
    var dtDate = new Date('1/1/' + (new Date()).getUTCFullYear());
    var intOffset = 10000; //set initial offset high so it is adjusted on the first attempt
    var intMonth;
    var intHoursUtc;
    var intHours;
    var intDaysMultiplyBy;

    //go through each month to find the lowest offset to account for DST
    for (intMonth = 0; intMonth < 12; intMonth++) {
        //go to the next month
        dtDate.setUTCMonth(dtDate.getUTCMonth() + 1);

        //To ignore daylight saving time look for the lowest offset.
        //Since, during DST, the clock moves forward, it'll be a bigger number.
        if (intOffset > (dtDate.getTimezoneOffset() * (-1))) {
            intOffset = (dtDate.getTimezoneOffset() * (-1));
        }
    }

    return intOffset;
}
//Find start and end of DST
function DstDetect() {
    var dtDstDetect = new Date();
    var dtDstStart = '';
    var dtDstEnd = '';
    var dtDstStartHold = ''; //Temp date hold
    var intYearDayCount = 732; //366 (include leap year) * 2 (for two years)
    var intHourOfYear = 1;
    var intDayOfYear;
    var intOffset = TimezoneDetect(); //Custom function. Make sure you include it.

    //Start from a year ago to make sure we include any previously starting DST
    dtDstDetect = new Date()
    dtDstDetect.setUTCFullYear(dtDstDetect.getUTCFullYear() - 1);
    dtDstDetect.setUTCHours(0, 0, 0, 0);

    //Going hour by hour through the year will detect DST with shorter code but that could result in 8760
    //FOR loops and several seconds of script execution time. Longer code narrows this down a little.
    //Go one day at a time and find out approx time of DST and if there even is DST on this computer.
    //Also need to make sure we catch the most current start and end cycle.
    for (intDayOfYear = 1; intDayOfYear <= intYearDayCount; intDayOfYear++) {
        dtDstDetect.setUTCDate(dtDstDetect.getUTCDate() + 1);

        if ((dtDstDetect.getTimezoneOffset() * (-1)) != intOffset && dtDstStartHold == '') {
            dtDstStartHold = new Date(dtDstDetect);
        }
        if ((dtDstDetect.getTimezoneOffset() * (-1)) == intOffset && dtDstStartHold != '') {
            dtDstStart = new Date(dtDstStartHold);
            dtDstEnd = new Date(dtDstDetect);
            dtDstStartHold = '';

            //DST is being used in this timezone. Narrow the time down to the exact hour the change happens
            //Remove 48 hours (a few extra to be on safe side) from the start/end date and find the exact change point
            //Go hour by hour until a change in the timezone offset is detected.
            dtDstStart.setUTCHours(dtDstStart.getUTCHours() - 48);
            dtDstEnd.setUTCHours(dtDstEnd.getUTCHours() - 48);

            //First find when DST starts
            for (intHourOfYear = 1; intHourOfYear <= 48; intHourOfYear++) {
                dtDstStart.setUTCHours(dtDstStart.getUTCHours() + 1);

                //If we found it then exit the loop. dtDstStart will have the correct value left in it.
                if ((dtDstStart.getTimezoneOffset() * (-1)) != intOffset) {
                    break;
                }
            }

            //Now find out when DST ends
            for (intHourOfYear = 1; intHourOfYear <= 48; intHourOfYear++) {
                dtDstEnd.setUTCHours(dtDstEnd.getUTCHours() + 1);

                //If we found it then exit the loop. dtDstEnd will have the correct value left in it.
                if ((dtDstEnd.getTimezoneOffset() * (-1)) != (intOffset + 60)) {
                    break;
                }
            }

            //Check if DST is currently on for this time frame. If it is then return these values.
            //If not then keep going. The function will either return the last values collected
            //or another value that is currently in effect
            if ((new Date()).getTime() >= dtDstStart.getTime() && (new Date()).getTime() <= dtDstEnd.getTime()) {
                return new Array(dtDstStart, dtDstEnd);
            }

        }
    }
    return new Array(dtDstStart, dtDstEnd);
}
