Harvest festival 2024.png

Dare to try out the Harvest Festival 2024!?

MediaWiki:VanaTime.js: Difference between revisions

From HorizonXI Wiki
No edit summary
No edit summary
Line 1: Line 1:
//*********************************************************************
/*********************************************************************
// Javascript below contributes to live Vana'diel Time listed in Sidebar
Javascript below contributes to Vana'diel Time displays throughout
// All code taken from: https://www.pyogenes.com/ffxi/timer/v2.html  
the HorizonXI Wiki
//***************************
Credits: ********
https://www.pyogenes.com/ffxi/timer/v2.html  
https://www.mithrapride.org/vana_time/index.html
https://www.rubydoc.info/gems/vanadiel-time/Vanadiel/Time
**********************************************************************/


/*
class timeElements {
Add the class tags below to incorporate current guild times
// List of all class names for each element in this model, for styling
<b><p class="page-alchemy_hours"></p></b>
 
static sidebar = "page-vanatime";
    static conquest = "vanatime-page-conquest-schedule"; // <span ... />
    static moonPhase = "vanatime-page-moon-phase";  // <span ... />
    static moonSchedule = "vanatime-page-moon-schedule-table";
    static rseSchedule = "vanatime-page-rse-schedule-table";
   
    static airships = {
        all : "vanatime-airship-schedule-table",
        jeuno : "vanatime-airship-schedule-jeuno-table",
        bastok : "vanatime-airship-schedule-bastok-table",
        sandy : "vanatime-airship-schedule-sandy-table",
        windy : "vanatime-airship-schedule-windy-table",
        kazham : "vanatime-airship-schedule-kazham-table",
    };


The following are valid class tags:
    static boats = {
page-alchemy_hours
        selbina : "vanatime-boat-schedule-selbina-table",
page-bonecraft_hours
        mhaura : "vanatime-boat-schedule-mhaura-table",
page-clothcraft_hours
        bibiki : "vanatime-boat-schedule-bibiki-table",
page-cooking_hours
        purgonorgoIsle : "vanatime-boat-schedule-purgonorgoIsle-table",
page-fishing_hours
        northLanding : "vanatime-boat-schedule-northLanding-table",
page-goldsmithing_hours
        centralLanding : "vanatime-boat-schedule-centralLanding-table",
page-leathercraft_hours
        southLanding : "vanatime-boat-schedule-southLanding-table"
page-smithing_hours
    };
page-woodworking_hours


*/
    static guilds = {
////////////////////////////////////////////////////////////////////
        alchemy : "vanatime-guild-schedule-alchemy",
//The following classnames are for <div>s throughout Vanatime.js
        smithing : "vanatime-guild-schedule-smithing",
const conquest_schedule = "vanatime-page-conquest-schedule";
        boneworking : "vanatime-guild-schedule-boneworking",
const moon_phase = "vanatime-page-moon-phase";
        goldsmithing : "vanatime-guild-schedule-goldsmithing",
const moon_phases_schedule = "vanatime-page-moon-phases-schedule";
        clothcrafting : "vanatime-guild-schedule-clothcrafting",
const crafting_guilds_schedule = "vanatime-page-crafting-guilds-schedule";
        woodworking : "vanatime-guild-schedule-woodworking",
////////////////////////////////////////////////////////////////////
        leathercrafting : "vanatime-guild-schedule-leatherworking",
        fishing : "vanatime-guild-schedule-fishing",
        cooking : "vanatime-guild-schedule-cooking",
        all : "vanatime-guild-schedule-all"
    };
}


////////////////////////////////////////////////////////////////////
//The following classnames are for tables throughout Vanatime.js
//const airship_schedule_table = "vanatime-page-airship-schedule-table";
const moon_phase_table = "vanatime-page-moon-phase-table";
const moon_phases_schedule_table = "vanatime-page-moon-phases-schedule-table";
const crafting_guilds_schedule_table = "vanatime-page-crafting-guilds-schedule-table";


class timeElements {
class schedule {
static ids = {
    //  All raw datea is from ASB
airships : {
    //  route definintion = [ 'Name of route', anim_arrive, anim_depart, timeOffset, time_interval, time_anim_arrive, time_waiting, time_anim_depart]
main : "vanatime-airship-schedule-table",
    //  Actual arrival time (when the player can enter the transport ) = time_offset + time_anim_arrive = [3] + [5]
jeuno : "vanatime-airship-schedule-jeuno-table",
    //  Departure time = arrival time + time_waiting = arrival_time + [6]
bastok : "vanatime-airship-schedule-bastok-table",
    //  All values listed are in VanaTime minutes, so 1440 is the total minutes in a game hour
sandy : "vanatime-airship-schedule-sandy-table",
   
        windy : "vanatime-airship-schedule-windy-table",
        static #airship_jeuno_sandy = ['Jeuno -> Sandoria',  0,  360, 12, 60, 12];
kazham : "vanatime-airship-schedule-kazham-table",
        static #airship_jeuno_windy = ['Jeuno -> Windurst',  90,  360, 12, 60, 12];
},
        static #airship_jeuno_bastok = ['Jeuno -> Bastok',    180, 360, 12, 60, 16];
boats : {
        static #airship_jeuno_kazham = ['Jeuno -> Kazham',    270, 360, 20, 50, 20];
selbina : "vanatime-boat-schedule-selbina-table",
        static #airship_bastok_jeuno = ['Bastok -> Jeuno',     0,  360, 14, 60, 16];
ahtUrhgan : "vanatime-boat-schedule-ahtUrhgan-table",
        static #airship_sandy_jeuno = ['Sandoria -> Jeuno',  180, 360, 12, 60, 16];
//bibiki : "vanatime-boat-schedule-bibiki-table", //consider removing this and refactoring
        static #airship_windy_jeuno = ['Windurst -> Jeuno',  270, 360, 18, 60, 14];
             bibiki : "vanatime-boat-schedule-bibikiFullSchedule-table",
        static #airship_kazham_jeuno = ['Kazham -> Jeuno',    90,  360, 20, 50, 20];
             purgonorgoIsle : "vanatime-boat-schedule-purgonorgoIsle-table",
   
             northLanding : "vanatime-boat-schedule-northLanding-table",
        static airships = {
             centralLanding : "vanatime-boat-schedule-centralLanding-table",
            jeuno : [
             southLanding : "vanatime-boat-schedule-southLanding-table"
                this.#airship_jeuno_bastok,
}
                this.#airship_jeuno_sandy,
}
                this.#airship_jeuno_windy,
                this.#airship_jeuno_kazham,
                this.#airship_bastok_jeuno,
                this.#airship_sandy_jeuno,
                this.#airship_windy_jeuno,
                this.#airship_kazham_jeuno
            ],
            bastok :   [ this.#airship_bastok_jeuno, this.#airship_jeuno_bastok],
            sandy :    [this.#airship_sandy_jeuno, this.#airship_jeuno_sandy],
            windy :    [this.#airship_windy_jeuno, this.#airship_jeuno_windy],
            kazham :    [this.#airship_kazham_jeuno, this.#airship_jeuno_kazham]
        }
   
        static #boat_selbina_mhaura = ['Selbina -> Mhaura',    382, 480, 18, 80, 17];
        static #boat_mhaura_selbina = ['Mhaura -> Selbina',    382, 480, 18, 80, 17];
        static #boat_mhaura_whitegate = ['Mhaura -> Whitegate', 142, 480, 18, 80, 17];
   
        static #boat_whitegate_mhaura = ['Whitegate -> Mhaura', 142, 480, 18, 80, 16];
        static #boat_whitegate_nashmau = ['Whitegate -> Nashmau', 282, 480, 18, 180, 17];
        static #boat_nashmau_whitegate = ['Nashmau -> Whitegate', 282, 480, 18, 180, 17];
   
        static #boat_bibiki_tours = ['Bibiki Bay -> Tours', 710, 720, 20, 40, 20];
        static #boat_bibiki_purgo = ['Bibiki Bay -> Purgonorgo Isle', 270, 720, 20, 40, 20];
        static #boat_purgo_bibiki = ['Purgonorgo Isle -> Bibiki Bay', 500, 720, 20, 40, 20];
   
        static #boat_barge_south_central_emfa = ['South Landing -> Central Landing EMFEA', 5, 1440, 15, 35, 15];
        static #boat_barge_central_south_newtpool1 = ['Central Landing -> South Landing NewtPool', 267, 1440, 12, 30, 15];
        static #boat_barge_south_oos = ['South Landing -> OOS', 1402, 1440, 33,  0,  0];
        static #boat_barge_south_north = ['South Landing -> North Landing', 560, 1440, 15, 35, 15];
        static #boat_barge_north_oos = ['North Landing -> OOS', 925, 1440, 40,  0,  0];
        static #boat_barge_north_central = ['North Landing -> Central Landing',  993, 1440, 12, 40, 15];
        static #boat_barge_central_south_newtpool2 = ['Central Landing -> South Landing NewtPool 2', 1148, 1440, 12, 30, 15];
        static #boat_barge_south_oos1 = ['South Landing -> OOS 2', 512, 1440, 33,  0, 0];
   
        static boats = {
            selbina : [ this.#boat_selbina_mhaura ],
            mhaura : [ this.#boat_mhaura_selbina, this.#boat_mhaura_whitegate ],
            whitegate : [ this.#boat_whitegate_mhaura, this.#boat_whitegate_nashmau],
            nashmau : [ this.#boat_nashmau_whitegate ],
             bibiki : [ this.#boat_bibiki_tours, this.#boat_bibiki_purgo],
             purgonorgoIsle : [ this.#boat_purgo_bibiki ],
             northLanding : [ this.#boat_barge_north_oos, this.#boat_barge_north_central ],
             centralLanding : [ this.#boat_barge_central_south_newtpool1, this.#boat_barge_central_south_newtpool2 ],
             southLanding : [ this.#boat_barge_south_central_emfa, this.#boat_barge_south_oos, this.#boat_barge_south_north, this.#boat_barge_south_oos1 ]
        }
   
        static #alchemy = [480, 1380, 5];
        static #smithing = [480, 1380, 2];
        static #boneworking = [480, 1380, 3];
        static #goldsmithing = [480, 1380, 4];
        static #clothcrafting = [360, 1260, 0];
        static  #woodworking = [360, 1260, 0];
        static #leathercrafting = [180, 1080, 4];
        static #fishing = [180, 1080, 5];
        static #cooking = [300, 1200, 7];
   
        static guilds = {
            // [ Open, Close, Holiday]
            alchemy : this.#alchemy,
            smithing : this.#smithing,
            boneworking : this.#boneworking,
            goldsmithing : this.#goldsmithing,
            clothcrafting : this.#clothcrafting,
            woodworking : this.#woodworking,
            leathercrafting : this.#leathercrafting,
            fishing : this.#fishing,
            cooking : this.#cooking,
            all : [ this.#alchemy, this.#smithing, this.#boneworking,this.#goldsmithing, this.#clothcrafting,this.#woodworking,this.#leathercrafting, this.#fishing, this.#cooking ]
        }
   
}
}


class schedule {
class VanaTime{
     static boats = {
      
         //All manaclipper data is copy/paste from ASB (manaclipper.lua)
    #elementalDay =     ["Firesday",    "Earthsday",        "Watersday",        "Windsday",         "Iceday",          "Lightningday",    "Lightsday",    "Darksday"];
         bibiki :  [
    #dayColor =         ["#FF0000",    "#AAAA00",         "#0000DD",           "#00AA22",         "#7799FF",         "#AA00AA",         "#AAAAAA",      "#333333"];
            { time :  10, act : "arrive", dest : "Dhalmel Rock" },     // 00:10
    #moonPhaseName =    ["New Moon",    "Waxing Crescent", "First Quarter",    "Waxing Gibbous",  "Full Moon",        "Waning Gibbous",   "Last Quarter", "Waning Crescent"];
            { time :  50, act : "depart", dest : "Dhalmel Rock" },      // 00:50
    #moonIcon =        ['\u{1F311}''\u{1F312}',        '\u{1F313}',        '\u{1F314}',        '\u{1F315}',        '\u{1F316}',        '\u{1F317}',    '\u{1F318}'];
            { time : 290, act : "arrive", dest : "Purgonorgo Isle" },  // 04:50
    #moonPercentages = ["(10%-0%-5%)", "(7%-38%)",         "(40%-55%)",       "(57%-88%)",       "(90%-100%-95%)",   "(93%-62%)",       "(60%-45%)",   "(43%-12%)"];
            { time : 330, act : "depart", dest : "Purgonorgo Isle" },   // 05:30
    #month =            ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
            { time :  730, act : "arrive", dest : "Maliyakaleya Reef" }, // 12:10
    #weekday =          ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
            { time :  770, act : "depart", dest : "Maliyakaleya Reef" }, // 12:50
    #rseRace =          ["M. Hume","F. Hume","M. Elvaan","F. Elvaan","M. TaruTaru","F. TaruTaru","Mithra","Galka"];
            { time : 1010, act : "arrive", dest : "Purgonorgo Isle" },   // 16:50
    #rseLocation =      ["Gusgen Mines","Shakrami Maze","Ordelle Caves"];
            { time : 1050, act : "depart", dest : "Purgonorgo Isle" },   // 17:30
 
        ],
   
        purgonorgoIsle : [
    // Conversions in Milliseconds
            { time :  510, act : "arrive", dest : "Bibiki Bay" },       // 08:30
    //#baseDate; // built at runtime: 1024844400000
            { time :  555, act : "depart", dest : "Bibiki Bay" },       // 09:15
    #moonDate =    1074997872000; // in milliseconds
            { time : 1230, act : "arrive", dest : "Bibiki Bay" },       // 20:30
    #VTIME_BIRTH    = 1024844400000; // vana birthday - in milliseconds
            { time : 1275, act : "depart", dest : "Bibiki Bay" },       // 21:15
    #VTIME_BASEDATE  = 1009810800;  // unix epoch - 1009810800 = se epoch (in earth seconds)
            { time : 1950, act : "arrive", dest : "Bibiki Bay" },       // 32:30
    rseDate =      1075281264000;
 
    #ONE_SECOND = 1000000;
    #ONE_MINUTE;
    #ONE_HOUR;
    #ONE_DAY;
    // #ONE_WEEK;
    // #ONE_MONTH;
    // #ONE_YEAR;
 
    // Conversions in Minutes
    #VTIME_YEAR  =      518400;  // 360 * GameDay
    #VTIME_MONTH =      43200;      // 30 * GameDay
    #VTIME_WEEK  =      11520;      // 8 * GameDay
    #VTIME_DAY  =      1440;      // 24 hours * GameHour
    #VTIME_HOUR  =      60;        // 60 minutes
    #VMULTIPLIER =      25;
    #MOON_CYCLE_DAYS =  84;
    // #MOON_CYCLE_PHASE = 17280;    // 1 moon phase cycle = 12 vana days = 12 * Gameday
 
    /*
        Some of the math...
 
        (((898 * 360) + 30) * 24 * 60 * 60) / (this.#VMULTIPLIER / 1000)..... 
        converts vana time to earth time by ( / 25 ) then getting to milliseconds ( * 1000 )
    */
    #vanaBirthday = (((898 * 360) + 30) * 24 * 60 * 60) / (25 / 1000); // 1117359360000 - in earth time milliseconds
    #difference = this.#vanaBirthday - this.#VTIME_BIRTH; // 92514960000 - earth time milliseconds
 
    getDifference(){ return this.#difference };
 
    /**
    * Common variables for quick reference to current Vana time
    * @returns - integer / number
    */
    // vana_currentTime_inEarthMS = ((898 * 360 + 30) * (24 * 60 * 60 * 1000)) + (this.earthDate.getTime() - this.#VTIME_BIRTH) * this.#VMULTIPLIER; // vana time, represented in earth milliseconds - used for making Date() objects
    // vana_currentTime = this.vana_currentTime_inEarthMS / (60 * 1000); // vana time in minutes
    // //vana_currentTime = ( ((this.earthDate.getTime() / 1000) - this.#VTIME_BASEDATE ) / 60.0 * this.#VMULTIPLIER) + (886 * this.#VTIME_YEAR); //returned in vana minutes
    // vana_year = this.vana_currentTime / this.#VTIME_YEAR;
    // vana_month  = (this.vana_currentTime / this.#VTIME_MONTH) % 12 + 1;
    // vana_date = (this.vana_currentTime / this.#VTIME_DAY) % 30 + 1;
    // vana_weekday  = Math.floor((this.vana_currentTime % this.#VTIME_WEEK) / this.#VTIME_DAY);
    // vana_hour = (this.vana_currentTime % this.#VTIME_DAY) / this.#VTIME_HOUR;
    // vana_mins  = this.vana_currentTime % this.#VTIME_HOUR;
    // vana_moonphase  = Math.floor((this.vana_currentTime % this.#MOON_CYCLE_PHASE) / this.#VTIME_DAY);
 
    /**
    * Helper functions for quick reference to any Vana time
    * @returns - integer / number
    */
    now_inEarthMS(){
        var now = new Date();
        return ((898 * 360 + 30) * (24 * 60 * 60 * 1000)) + (now.getTime() - this.#VTIME_BIRTH) * this.#VMULTIPLIER;
    }
 
    now(){ return this.now_inEarthMS() / ( 60 * 1000); }
 
    now_inMS(){
        var timenow = new Date();
        return ((timenow.getTime() - this.#VTIME_BIRTH) % (24 * 60 * 60 * 1000 / 25));
    }
 
    now_inMINS(){
        return this.now_inMS / ( 1000 * 60 );
    }
 
    today_inMS(){ // result in earth Milliseconds
        var now = this.now_inEarthMS();
        return ( now - ( now % (24 * 60 * 60 * 1000) ));
    }


        ],
    year(vanatime) {
        northLanding : [
         if (vanatime === undefined || vanatime == null) vanatime = this.now();
            { time :  965, act : "arrive", dest : "Central Landing" }, // 16:05 Arrive OOS
         return Math.floor(vanatime / this.#VTIME_YEAR);
            { time :  973, act : "depart", dest : "Central Landing" }, // 16:12 Depart OOS
            { time : 1005, act : "arrive", dest : "Central Landing" }, // 16:45 to Central
            { time : 1045, act : "depart", dest : "Central Landing" }, // 17:25 to Central
         ],
         centralLanding : [
            { time :  280, act : "arrive", dest : "South Landing" }, // 04:40 from South Landing - EMFEA
            { time :  310, act : "depart", dest : "South Landing" }, // 05:10 to South Landing - Newtpool
            { time : 1160, act : "arrive", dest : "South Landing" }, // 19:20 from North Landing
            { time : 1190, act : "depart", dest : "South Landing" }, // 19:50 to South Landing - Newtpool PM
        ],
        southLanding : [
            { time :  15, act : "arrive", dest : "Central Landing - EMFEA" }, // 00:15 from Central Landing - EMFEA
            { time :  50, act : "depart", dest : "Central Landing - EMFEA" }, // 00:50 to Central Landing - EMFEA
            { time :  540, act : "arrive", dest : "North Landing" }, // 09:00 Arrive OOS
            { time :  547, act : "depart", dest : "North Landing" }, // 09:07 Depart OOS
            { time :  575, act : "arrive", dest : "North Landing" }, // 09:35 Arrive from North Landing
            { time :  610, act : "depart", dest : "North Landing" }, // 10:10 to North Landing - Main Canal
            { time : 1420, act : "arrive", dest : "Central Landing - EMFEA" }, // 23:40 Arrive OOS
            { time : 1427, act : "depart", dest : "Central Landing - EMFEA" }, // 23:47 Depart OOS
        ]
       
     }
     }
}


class vanaTime {
    month(vanatime){
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return Math.floor((vanatime / this.#VTIME_MONTH) % 12) + 1;
    }


     #msGameDay = (24 * 60 * 60 * 1000 / 25);   // milliseconds in a game day = 3456000
     date(vanatime){
     #msRealDay = (24 * 60 * 60 * 1000);       // milliseconds in a real day = 86400000
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return Math.floor((vanatime / this.#VTIME_DAY) % 30) + 1;
     }
   
    weekDay(vanatime){
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return Math.floor((vanatime % this.#VTIME_WEEK) / this.#VTIME_DAY);
    }


     #vanaBirthDate = (((898 * 360) + 30) * 24 * 60 * 60) / (25 / 1000); // miliseconds since birth of Vanadiel =  1117359360000
     hour(vanatime){
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return Math.floor((vanatime % this.#VTIME_DAY) / this.#VTIME_HOUR);
    }


     #baseDate; // built at runtime
     mins(vanatime){
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return Math.floor(vanatime % this.#VTIME_HOUR);
    }


     constructor() {
     dayColor(vanatime){  
         this.#baseDate = new Date();
         if (vanatime === undefined || vanatime == null) vanatime = this.now();
         this.#baseDate.setUTCFullYear(2002, 5, 23); // Set date to 2003-06-23
         return this.#dayColor[this.weekDay()];
         this.#baseDate.setUTCHours(15, 0, 0, 0);   // Set time to 15:00:00.0000
    }
   
    dayLabel(day){
         if (day === undefined || day == null) return this.#elementalDay[this.weekDay()];
        else return this.#elementalDay[day]
     }
     }


    moonPhaseIcon(day){ 
        if (day === undefined || day == null) return this.#moonIcon[this.moonLatentPhase()];
        else return this.#moonIcon[day];
    }


     /**
    moonPhaseName(day){ 
     * @summary - gets current Vanadiel Time
        if (day === undefined || day == null) return this.#moonPhaseName[this.moonLatentPhase()];
     * @returns - value in milliseconds
        else return this.#moonPhaseName[day];
    }
 
    moonPhasePercentages(day){ 
        if (day === undefined || day == null) return this.#moonPercentages[this.moonLatentPhase()];
        else return this.#moonPercentages[day];
    }
 
     /**    
    * Time Helper functions - supports string generation for month/week details
     * @param  (required) - represents which RACE
     * @returns - string - from #rseRace or #rseLocation
     */
     */
     getVanaDate(){
     monthLabel(m){ return this.#month[m]; }
        var temp = new Date();
    weekdayLabel(w){ return this.#weekday[w]; }
        return ((898 * 360 + 30) * this.#msRealDay) + (temp.getTime() - this.#baseDate) * 25;
 
    /**   
    * RSE Helper functions - supports string generation for RSE details
    * @param r (required) - represents which RACE
    * @returns - string - from #rseRace or #rseLocation
    */
    rseRace(r){ return this.#rseRace[r]; }
 
    /**   
    * RSE Helper functions - supports string generation for RSE details
    * @param r (required) - represents which RACE
    * @returns - string - from #rseRace or #rseLocation
    */
    rseLocation(r){ return this.#rseLocation[r]; }
 
    constructor(){
        this.#ONE_MINUTE = 60  * this.#ONE_SECOND;
        this.#ONE_HOUR = 60  * this.#ONE_MINUTE;
        this.#ONE_DAY = 24  * this.#ONE_HOUR;
        // this.#ONE_WEEK = 8  * this.#ONE_DAY;
        // this.#ONE_MONTH = 30  * this.#ONE_DAY;
        // this.#ONE_YEAR = 360 * this.#ONE_DAY;
 
        // this.#MOON_CYCLE_PHASE = 12 * this.#VTIME_WEEK;
     }
     }


    /******************************** MOON PHASES **********************************
    0% NM  7% WXC    40% FQM  57% WXG  90% FM  93% WNG  60% LQM  43% WNC  10% NM
    2% NM  10% WXC    43% FQM  60% WXG  93% FM  90% WNG  57% LQM  40% WNC  7% NM
    5% NM  12% WXC    45% FQM  62% WXG  95% FM  88% WNG  55% LQM  38% WNC  5% NM
            14% WXC    48% FQM  64% WXG  98% FM  86% WNG  52% LQM  36% WNC  2% NM
            17% WXC    50% FQM  67% WXG  100% FM  83% WNG  50% LQM  33% WNC
            19% WXC    52% FQM  69% WXG  98% FM  81% WNG  48% LQM  31% WNC
            21% WXC    55% FQM  71% WXG  95% FM  79% WNG  45% LQM  29% WNC
            24% WXC              74% WXG          76% WNG          26% WNC
            26% WXC              76% WXG          74% WNG          24% WNC
            29% WXC              79% WXG          71% WNG          21% WNC
            31% WXC              81% WXG          69% WNG          19% WNC
            33% WXC              83% WXG          67% WNG          17% WNC
            36% WXC              86% WXG          64% WNG          14% WNC
            38% WXC              88% WXG          62% WNG          12% WNC
    ********************************************************************************/
    /**   
    * Private function - supports moon phase calculations
    * @param vanatime (required) - Vanadiel time, in MILLISECONDS
    * @returns - integer - represents the day in the 84 day moon phase cycle
    */
    #moonDays(vanatime){
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return  ((( vanatime /  this.#VTIME_DAY ) + 26) % this.#MOON_CYCLE_DAYS);
    } 


     /**
     /**
     * @summary - used for calculating transport schedules with predetermined offsets
     * Private function for doing arithmetic for moon phase percentage
     * @returns - current Vanadiel day with time 00:00 in milliseconds
     * @param vanatime (required) - Vanadiel time, in MILLISECONDS
     */
    * @returns - integer representing moon phase percentage
     _rawVanaToday(){
     */  
         var now = this.getVanaDate();
     #moonPercent(vanatime){  
         now = ( now - ( now % this.#msRealDay ));
         if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return now;
         return Math.abs( -Math.round((42 - Math.floor(this.#moonDays(vanatime))) / 42 * 100) );  
     }
     }


    /**
    * Helper function for getting moon phase percentage
    * @param vanatime (required) - Vanadiel time, in MILLISECONDS
    * @returns - integer representing moon phase percentage
    */
    getMoonPercent(vanatime) { return this.#moonPercent(vanatime)};


     /**
     /**
     * @param value - minutes to be converted
     * @param vanatime - Vanadiel time, in MILLISECONDS; default value is now()
     * @returns - value in milliseconds
     * @returns - integer representing waxing/waning/neither
     */
     */  
     _convertMinsToMiliseconds(value){ return value * (60 * 1000); }
     #moonDirection(vanatime){
      
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        var moondays = Math.floor(this.#moonDays(vanatime));
        //console.log(daysmod);
        if (moondays == 42 || moondays == 0) { return 0; }// neither waxing nor waning
        else if (moondays < 42){ return 1; } // waning
        else{ return 2; } // waxing
     }


     /**
     /**
     * @param time - Vanadiel time needing to be converted
     * @param vanatime - Vanadiel time, in MILLISECONDS; default value is now()
     * @returns - value in milliseconds
     * @returns - total milliseconds remaining until next conquest update
     */
     */  
     _convertToEarthTime(time){
     moonLatentPhase(vanatime){
         if (time === undefined) time = this.getVanaDate();
         if (vanatime === undefined || vanatime == null) vanatime = this.now();
         var earthTime = time / ( 25 );
        var moonPhase = this.#moonPercent(vanatime);
         return new Date(Math.floor(earthTime) - (this.#vanaBirthDate - this.#baseDate));
         var moonDirection = this.#moonDirection(vanatime);
 
        //console.log("*mP", moonPhase);
        //console.log("*mD", moonDirection);
          
        if (moonPhase <= 5 || (moonPhase <= 10 && moonDirection == 1)) {return 0;} // New Moon - 10% waning -> 5% waxing
        else if (moonPhase >= 7 && moonPhase <= 38 && moonDirection == 2) {return 1;}  // Waxing Crescent - 7% -> 38% waxing
        else if (moonPhase >= 40 && moonPhase <= 55 && moonDirection == 2){return 2;}  // First Quarter - 40%% -> 55% waxing
        else if (moonPhase >= 57 && moonPhase <= 88 && moonDirection == 2){return 3;}  // Waxing Gibbous - 57% -> 88%
        else if (moonPhase >= 95 || (moonPhase >= 90 && moonDirection == 2)){return 4;}  // Full Moon - waxing 90% -> waning 95%
        else if (moonPhase >= 62 && moonPhase <= 93 && moonDirection == 1){return 5;}  // Waning Gibbous - 93% -> 62%
        else if (moonPhase >= 45 && moonPhase <= 60 && moonDirection == 1){return 6;}  // Last Quarter - 60% -> 45%
        else{return 7;}  // Waning Crescent - 43% -> 12%
     }
     }


    /**
    * @returns - total milliseconds remaining until next conquest update
    */
    conquestRemainingTime(){
        var now =  new Date();
        //console.log(this.earthDate.getTime(), this.#VTIME_BIRTH);
        return (7 * (24 * 60 * 60 * 1000)) - ((now.getTime() - this.#VTIME_BIRTH) % (7 * (24 * 60 * 60 * 1000)));
    }


     /*
     /**
        Private functions assisting with the manipulation of Vana time for the string generators below
    * @returns - integer - total Vanadiel days remaining on current conquest
    */
    */  
    #getVanaDate_Year(currentVanaTime){    return Math.floor(currentVanaTime / (360 * this.#msRealDay)); }
     conquestRemainingVanaDays(){
    #getVanaDate_Month(currentVanaTime){    return Math.floor((currentVanaTime % (360 * this.#msRealDay)) / (30 * this.#msRealDay)) + 1; }
        return Math.ceil(this.conquestRemainingTime() / (24 * 60 * 60 * 1000 / 25));
     #getVanaDate_Date(currentVanaTime){     return Math.floor((currentVanaTime % (30 * this.#msRealDay)) / (this.#msRealDay)) + 1; }
     }
    #getVanaDate_Hour(currentVanaTime){    return Math.floor((currentVanaTime % (this.#msRealDay)) / (60 * 60 * 1000)); }
    #getVanaDate_Min(currentVanaTime){      return Math.floor((currentVanaTime % (60 * 60 * 1000)) / (60 * 1000)); }
     //#getVanaDate_Sec(currentVanaTime){      return Math.floor((currentVanaTime % (60 * 1000)) / 1000); }
 


     /**
     /**
     * @param time - Vanadiel time needing to be converted
     * @param time - Vanadiel time, in MILLISECONDS, needing to be converted  
     * @returns - string of HOURS:MINS
     * @returns {Date} - value as Date() object
     */
     */
     stringVanaTime(time){
     earthTime(time){
         if (time === undefined) time = this.getVanaDate();
         if (time === undefined) time = this.now_inEarthMS();
        //else time = time * 60 * 1000;
        var earthTime = time / ( this.#VMULTIPLIER );
        return new Date(Math.floor(earthTime) - (this.#vanaBirthday - this.#VTIME_BIRTH));
    }


         var vYear = this.#getVanaDate_Year(time);
 
         var vMonth = this.#getVanaDate_Month(time);
    /**
         var vDate = this.#getVanaDate_Date(time);
    * @param time - Vanadiel time, in minutes, needing to be converted
         var vHour = this.#getVanaDate_Hour(time);
    * @returns - string, formatted 00:00
         var vMin = this.#getVanaDate_Min(time);
    */
    stringVanaTime(time){
        if (time === undefined || time === null) time = this.now();
        //console.log(time);
         var vYear = this.year(time);
         var vMon  = this.month(time)
         var vDate = this.date(time);
         var vHour = this.hour(time);
         var vMin = this.mins(time);
        // var vSec  = time.getSeconds();
        // var vDay  = time.getDay();
         //seconds left our because we don't use them for any calcs
         //seconds left our because we don't use them for any calcs


         if (vYear < 1000)  vYear = "0" + vYear;  
         if (vYear < 1000)  vYear = "0" + vYear;  
         if (vMonth < 10) vMonth = "0" + vMonth;
         if (vMon < 10) vMon = "0" + vMon;
         if (vDate  < 10)  vDate  = "0" + vDate;
         if (vDate  < 10)  vDate  = "0" + vDate;
         if (vHour < 10)  vHour = "0" + vHour;  
         if (vHour < 10)  vHour = "0" + vHour;  
Line 194: Line 452:
         return vHour + ":" + vMin;  
         return vHour + ":" + vMin;  
     }
     }
 
   
    /**
    /**
     * @param {Date} time - Earth time needing to be converted
     * @param time - Vanadiel time, in milliseconds, needing to be converted
     * @returns - string formatted as HOURS:MINS
     * @returns - string, formatted 00:00:00
     */
     */
     stringEarthTime(time) {
     stringEarthTime(time) {
         var eTime = this._convertToEarthTime(time);
         var eTime = this.earthTime(time);
 
        // const monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
         //Most of these arent needed, left in for future inclusion if needed/wanted
         //Most of these arent needed, left in for future inclusion if needed/wanted
         // var eYear = eTime.getFullYear();
         // var eYear = eTime.getFullYear();
         var eMon  = eTime.getMonth();
         // var eMon  = monthNames[eTime.getMonth()];
         var eDate = eTime.getDate();
         var eDate = eTime.getDate();
         var eHour = eTime.getHours();
         var eHour = eTime.getHours();
Line 212: Line 470:
          
          
         // Assigns a leading zero if neccessary
         // Assigns a leading zero if neccessary
         if (eDate < 10)  eDate = "0" + eDate;  
         // if (eDate < 10)  eDate = "0" + eDate;  
         if (eHour < 10)  eHour = "0" + eHour;  
         if (eHour < 10)  eHour = "0" + eHour;  
         if (eMin < 10)  eMin  = "0" + eMin;   
         if (eMin < 10)  eMin  = "0" + eMin;   
         if (eSec < 10)  eSec  = "0" + eSec;   
         if (eSec < 10)  eSec  = "0" + eSec;   
       
        //var EarthDay      = new Array("SUN","MON","TUE","WED","THU","FRI","SAT");
        var EarthMonth    = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");


         //var str = EarthMonth[eMon] + " " + eDate + ", " + eYear + " (" + EarthDay[eDay] + ") " + eHour + ":" + eMin + ":" + eSec;
         // var str = eMon + " " + eDate + "," + eHour + ":" + eMin + ":" + eSec;
        //var str = EarthMonth[eMon] + " " + eDate + "," + eHour + ":" + eMin + ":" + eSec;
         var str = eHour + ":" + eMin + ":" + eSec;
         var str = eHour + ":" + eMin + ":" + eSec;
         return str;
         return str;
Line 227: Line 481:


     /**
     /**
     * @param  nextDeparture - Earth time needing to be converted
     * @param  nextTime - Vana time, in MINUTES, needing to be converted
     * @returns - string of HOURS:MINS
     * @returns - string of HOURS:MINS
     */
     */
     timeUntil(nextDeparture){
     timeUntil(nextTime){
         if (nextDeparture === undefined) { return "00:00:00"; }
         if (nextTime === undefined) { return "00:00:00"; }
        else if ( !(nextTime instanceof Date) ) var e = this.earthTime(nextTime); //earth time for next departure
        else e = nextTime;
          
          
        var e = this._convertToEarthTime(nextDeparture); //earth time for next departure
         var now = new Date(); // earth time now
         var now = new Date(); // earth time now
          
          
         //get difference between the next departure and current time... we want this to be in seconds, and Date()
         //get difference between the next departure and current time... we want this to be in seconds, and Date()
         //and nextDeparture should be in milliseconds, so we /1000
         //and nextDeparture should be in milliseconds, so we /1000
        var seconds = Math.floor((e.getTime() - now.getTime()) / 1000);


        var days = (e.getTime() - now.getTime()) / (24 * 60 * 60 * 1000);
        var hours = (days - Math.floor(days)) * 24;
        var minutes = (hours - Math.floor(hours)) * 60;
        var seconds = Math.floor((minutes - Math.floor(minutes)) * 60);
        days = Math.floor(days);
        hours = Math.floor(hours);
        minutes = Math.floor(minutes);
       
        if (hours < 10)  hours = "0" + hours;
        if (minutes < 10)  minutes  = "0" + minutes; 
        if (seconds < 10)  seconds  = "0" + seconds; 
       
        var str = minutes + ":" + seconds;
        if ( days > 0 ) { str = [days, hours, str].join(':'); }
        else if ( hours > 0 || typeof(hours) == 'string') { str = [hours, str].join(':'); }
        return str;
    }
    timer(time1, time2){
        var seconds = Math.floor((time1.getTime() - time2.getTime()) / 1000);
               
         //basic math functions to get each element of time separated  
         //basic math functions to get each element of time separated  
         var minutes = Math.floor(seconds / 60);
         var minutes = Math.floor(seconds / 60);
Line 249: Line 527:
         seconds = seconds-(days * 24 * 60 * 60 )-(hours * 60 * 60)-(minutes * 60);
         seconds = seconds-(days * 24 * 60 * 60 )-(hours * 60 * 60)-(minutes * 60);


         //dont need the vars to be numbers anymore anyway...
         seconds < 10 ? seconds = "0" + seconds : seconds;
         if (minutes < 10) minutes = "0" + minutes;
         minutes < 10 ? minutes = "0" + minutes : minutes;
         if (seconds < 10) seconds = "0" + seconds;
         hours < 10 ? hours = "0" + hours : hours;
 
       
         var str = minutes + ":" + seconds
         var str = hours + ":" + minutes + ":" + seconds;
         if ( hours > 0 ) str = [hours + ":", str].join('');
         if ( days != 0) str = [days, str].join(':');
         return str;
         return str;  
     }
     }


}/// end of 'class vanaTime'
}
////////////////////////////////////////////////////////////////////
const vanatime = new VanaTime();
////////////////////////////////////////////////////


 
function pageHasElement(element){
 
basisDate = new Date();
basisDate.setUTCFullYear(2002, 5, 23);
basisDate.setUTCHours(15, 0, 0, 0);   
 
Mndate = new Date();
Mndate.setUTCFullYear(2004, 0, 25); // Set date to 2004-01-25
Mndate.setUTCHours(2, 31, 12, 0);    // Set time to 02:31:12.0000
 
msGameDay = (24 * 60 * 60 * 1000 / 25); // milliseconds in a game day = 3456000
msRealDay = (24 * 60 * 60 * 1000); // milliseconds in a real day = 86400000
 
VanaDay = new Array("Firesday", "Earthsday", "Watersday", "Windsday", "Iceday", "Lightningday", "Lightsday", "Darksday");
DayColor = new Array("#FF0000", "#AAAA00", "#0000DD", "#00AA22", "#7799FF", "#AA00AA", "#AAAAAA", "#333333");
 
//PhaseName = new Array("Full Moon","Waning Gibbous","Last Quarter","Waning Crescent","New Moon","Waxing Crescent","First Quarter","Waxing Gibbous");
PhaseName = new Array('\u{1F315}','\u{1F316}','\u{1F317}','\u{1F318}','\u{1F311}','\u{1F312}','\u{1F313}','\u{1F314}');
 
sMonth = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
//RSErace = new Array("M. Hume","F. Hume","M. Elvaan","F. Elvaan","M. TaruTaru","F. TaruTaru","Mithra","Galka");
//RSEloc = new Array("Gusgen Mines","Shakrami Maze","Ordelle Caves");
 
BoatSched_selbina = new Array("08:00", "16:00", "00:00");
BoatSched_selbina2 = new Array("06:30", "14:30", "22:30");
 
BoatSched_ahtUrhgan = new Array("04:00", "12:00", "20:00");
BoatSched_ahtUrhgan2 = new Array("02:30", "10:30", "18:30");
 
BoatSched_bibiki = new Array("05:30", "17:30");
BoatSched_bibiki2 = new Array("04:50", "16:50");
 
BoatDayOffset = new Array(0,0,7);
 
var vanadate;
function resetGameTime() {
// **** Game time
var now = new Date();
vanaDate =  ((898 * 360 + 30) * msRealDay) + (now.getTime() - basisDate.getTime()) * 25;
 
vYear = Math.floor(vanaDate / (360 * msRealDay));
vMon  = Math.floor((vanaDate % (360 * msRealDay)) / (30 * msRealDay)) + 1;
vDate = Math.floor((vanaDate % (30 * msRealDay)) / (msRealDay)) + 1;
vHour = Math.floor((vanaDate % (msRealDay)) / (60 * 60 * 1000));
vMin  = Math.floor((vanaDate % (60 * 60 * 1000)) / (60 * 1000));
vSec  = Math.floor((vanaDate % (60 * 1000)) / 1000);
vDay  = Math.floor((vanaDate % (8 * msRealDay)) / (msRealDay));
 
if (vYear < 1000) { VanaYear = "0" + vYear; } else { VanaYear = vYear; }
if (vMon  < 10)  { VanaMon  = "0" + vMon; }  else { VanaMon  = vMon; }
if (vDate < 10)  { VanaDate = "0" + vDate; } else { VanaDate = vDate; }
if (vHour < 10)  { VanaHour = "0" + vHour; } else { VanaHour = vHour; }
if (vMin  < 10)  { VanaMin  = "0" + vMin; }  else { VanaMin  = vMin; }
if (vSec  < 10)  { VanaSec  = "0" + vSec; }  else { VanaSec  = vSec; }
// Moon phase
    function test(v){
var timenow = new Date();
        var i = document.getElementById(v);
    var localTime = timenow.getTime();
        var c = document.getElementsByClassName(v);
    var moonDays = (Math.floor((localTime - Mndate.getTime()) / msGameDay))  % 84;


    var mnElapsedTime = (localTime - Mndate.getTime()) % msGameDay;
        if ( i ) { return true; }
        if ( c[0] ) { return true; }
    }


     // determine phase percentage
     if (typeof(element) == 'string') return test(element);
    moonpercent = - Math.round((42 - moonDays) / 42 * 100);
    else {
    if (moonpercent <= -94) {
        for (const [k,v] of Object.entries(element) ){  
        mnPhase = 0;
            if (test(v) == true) return true;
         optPhase = 4;
         }
        toNextPhase = (3 - moonDays) * msGameDay - mnElapsedTime;
    }
        toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime;
    return false;
}


    }  else if (moonpercent >= 90) {
function updateSidebar() {
     mnPhase = 0;
     const page_vanatime = document.getElementsByClassName(timeElements.sidebar);
        optPhase = 4;
    if ( !page_vanatime) return;
        toNextPhase = (87 - moonDays) * msGameDay - mnElapsedTime;
        toOptimalPhase = (38 + 84 - moonDays) * msGameDay - mnElapsedTime;


    }  else if (moonpercent >= -93 && moonpercent <= -62) {
    var hour = vanatime.hour();
      mnPhase = 1;
    hour < 10 ? hour = ["0", hour].join('') : hour;
        optPhase = 4;
    var mins = vanatime.mins();
        toNextPhase = (17 - moonDays) * msGameDay - mnElapsedTime;
    mins < 10 ? mins = ["0", mins].join('') : mins;
        toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime;


    }  else if (moonpercent >= -61 && moonpercent <= -41)  {
    var sidebarTime = "<div><li><b>" + hour + ":" + mins + "</b>  ~ " + vanatime.year() + "-" + vanatime.month() + "-" + vanatime.date() + "</li>";  
      mnPhase = 2;
sidebarTime += "<li><span style=\"font-weight: bold; font-size:14px; color:" + vanatime.dayColor() + "\" >" + vanatime.dayLabel() + "</span><span style=\"font-size:14px;\"> ~ " + vanatime.moonPhaseIcon() + vanatime.getMoonPercent() + "%</span></li>";  
        optPhase = 4;
sidebarTime += "</div>";
        toNextPhase = (25 - moonDays) * msGameDay - mnElapsedTime;
        toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime;
 
    }  else if (moonpercent >= -40 && moonpercent <= -11)  {
      mnPhase = 3;
        optPhase = 4;
        toNextPhase = (38 - moonDays) * msGameDay - mnElapsedTime;
        toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime;
 
    }  else if (moonpercent >= -10 && moonpercent <= 6)  {
      mnPhase = 4;
        optPhase = 0;
        toNextPhase = (45 - moonDays) * msGameDay - mnElapsedTime;
        toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime;
 
    }  else if (moonpercent >= 7 && moonpercent <= 36) {
      mnPhase = 5;
        optPhase = 0;
        toNextPhase = (58 - moonDays) * msGameDay - mnElapsedTime;
        toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime;
 
    }  else if (moonpercent >= 37 && moonpercent <= 56)  {
      mnPhase = 6;
        optPhase = 0;
        toNextPhase = (66 - moonDays) * msGameDay - mnElapsedTime;
        toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime;
 
    }  else if (moonpercent >= 57 && moonpercent <= 89)  {
      mnPhase = 7;
        optPhase = 0;
        toNextPhase = (60 - moonDays) * msGameDay - mnElapsedTime;
        toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime;
    }
 
    mnpercent = PhaseName[mnPhase]  + Math.abs(moonpercent) + "%";
 
    if (moonpercent <= 5 && moonpercent >= -10) {
          mnpercent = "<FONT COLOR='#FF0000'>" + mnpercent+ "</FONT>";
    } else if (moonpercent >= 90 || moonpercent <= -95)  {
          mnpercent = "<FONT COLOR='#0000FF'>" + mnpercent+ "</FONT>";
    }
 
  //nextPhase = "Next phase (" + PhaseName[(mnPhase + 1) % 8] + "): " + formatCountdown(toNextPhase);
  //nextOptPhase = "Next " + PhaseName[optPhase] + ": " + formatCountdown(toOptimalPhase);
//draw to sidebar element
for (let i = 0; i < page_vanatime.length; i = i+1) { page_vanatime[i].innerHTML = sidebarTime; }
VanaTime = "<div><li><b>" + VanaHour + ":" + VanaMin + "</b>  ~  " + VanaYear + "-" + VanaMon + "-" + VanaDate + "</li>";  
}
VanaTime += "<li><span style=\"font-weight: bold; font-size:14px; color:" + DayColor[vDay] + "\" >"  + VanaDay[vDay] + "</span><span style=\"font-size:14px;\">  ~ " + mnpercent + "</span></li>";
VanaTime += "</div>";
alchemy_hours = guildHelper(8, 23, 6);
bonecraft_hours = guildHelper(8, 23, 3);
clothcraft_hours = guildHelper(6, 21, 0);
cooking_hours = guildHelper(5, 20, 7);
fishing_hours = guildHelper(3, 18, 5);
goldsmithing_hours = guildHelper(8, 23, 4);
leathercraft_hours = guildHelper(3, 18, 4);
smithing_hours = guildHelper(8, 23, 2);
woodworking_hours = guildHelper(6, 21, 0);


// Do not alter this line. This updates sidebar text for current time
function updateBoatSchedule() {
const sidebar_vanatime = document.getElementById("n-vanatime");
if (sidebar_vanatime) sidebar_vanatime.innerHTML = VanaTime;
const page_vanatime = document.getElementsByClassName("page-vanatime");
for (let i = 0; i < page_vanatime.length; i = i+1) { page_vanatime[i].textContent = VanaTime; }


const page_alchemy_hours = document.getElementsByClassName("page-alchemy_hours");
    if (!pageHasElement(timeElements.boats)) return;
for (let i = 0; i < page_alchemy_hours.length; i = i+1) { page_alchemy_hours[i].textContent = alchemy_hours; }
    populateTransportSchedule(timeElements.boats.selbina, schedule.boats.selbina, 3);
 
    populateTransportSchedule(timeElements.boats.mhaura, schedule.boats.mhaura, 3);
const page_bonecraft_hours = document.getElementsByClassName("page-bonecraft_hours");
    populateTransportSchedule(timeElements.boats.whitegate, schedule.boats.whitegate, 1);
for (let i = 0; i < page_bonecraft_hours.length; i = i+1) { page_bonecraft_hours[i].textContent = bonecraft_hours; }
    populateTransportSchedule(timeElements.boats.nashmau, schedule.boats.nashmau, 1);
    populateTransportSchedule(timeElements.boats.bibiki, schedule.boats.bibiki, 1);
const page_clothcraft_hours = document.getElementsByClassName("page-clothcraft_hours");
    populateTransportSchedule(timeElements.boats.purgonorgoIsle, schedule.boats.purgonorgoIsle, 1);
for (let i = 0; i < page_clothcraft_hours.length; i = i+1) { page_clothcraft_hours[i].textContent = clothcraft_hours; }
    populateTransportSchedule(timeElements.boats.northLanding, schedule.boats.northLanding, 1);
 
    populateTransportSchedule(timeElements.boats.centralLanding, schedule.boats.centralLanding, 1);
const page_cooking_hours = document.getElementsByClassName("page-cooking_hours");
    populateTransportSchedule(timeElements.boats.southLanding, schedule.boats.southLanding, 1);
for (let i = 0; i < page_cooking_hours.length; i = i+1) { page_cooking_hours[i].textContent = cooking_hours; }
}
const page_fishing_hours = document.getElementsByClassName("page-fishing_hours");
for (let i = 0; i < page_fishing_hours.length; i = i+1) { page_fishing_hours[i].textContent = fishing_hours; }
const page_goldsmithing_hours = document.getElementsByClassName("page-goldsmithing_hours");
for (let i = 0; i < page_goldsmithing_hours.length; i = i+1) { page_goldsmithing_hours[i].textContent = goldsmithing_hours; }
const page_leathercraft_hours = document.getElementsByClassName("page-leathercraft_hours");
for (let i = 0; i < page_leathercraft_hours.length; i = i+1) { page_leathercraft_hours[i].textContent = leathercraft_hours; }


const page_smithing_hours = document.getElementsByClassName("page-smithing_hours");
function updateAirshipSchedule(){
for (let i = 0; i < page_smithing_hours.length; i = i+1) { page_smithing_hours[i].textContent = smithing_hours; }
    if (!pageHasElement(timeElements.airships)) return;
const page_woodworking_hours = document.getElementsByClassName("page-woodworking_hours");
for (let i = 0; i < page_woodworking_hours.length; i = i+1) { page_woodworking_hours[i].textContent = woodworking_hours; }


  populateTransportSchedule(timeElements.airships.jeuno, schedule.airships.jeuno, 1);
  populateTransportSchedule(timeElements.airships.bastok, schedule.airships.bastok, 1);
  populateTransportSchedule(timeElements.airships.sandy, schedule.airships.sandy, 1);
  populateTransportSchedule(timeElements.airships.windy, schedule.airships.windy, 1);
  populateTransportSchedule(timeElements.airships.kazham, schedule.airships.kazham, 1);
}
}
           
function guildHelper(open, close, holiday)  {
  var timenow = new Date();
  var localTime = timenow.getTime();
  var elapsedTime = (localTime - basisDate.getTime()) % msGameDay;
  var dayStart = localTime - elapsedTime;


  // this conversion factor tells us time elapsed since the game day started in milliseconds
  var convFactor = 60 * 60 * 1000 / 25;
 
  vanaDate =  ((898 * 360 + 30) * msRealDay) + (localTime - basisDate.getTime()) * 25;
  vDay  = Math.floor((vanaDate % (8 * msRealDay)) / (msRealDay));


  open = open * convFactor;
function _transportScheduleHeader(classname){
  close = close * convFactor;
    var header = "<TABLE CLASS='" + classname + "' WIDTH='450' CELLSPACING='0' CELLPADDING='0'>";
 
header += "<TR><TH ALIGN='LEFT'>Destination</TH>";
  openTime = open + dayStart;
//header += "<TH ALIGN='LEFT'>Departure Day</TH>";
  closeTime = close + dayStart;
header += "<TH ALIGN='LEFT'>VanaTime</TH>";
  outputTxt = "";
    header += "<TH ALIGN='LEFT'>Earth Time</TH>";
  guildCountdown = 0;
header += "<TH ALIGN='LEFT'>Departs</TH></TR>";
 
return header;
  if (openTime >= localTime) {
      guildCountdown = openTime - localTime;
      outputTxt2 = "Currently Closed. Open tomorrow.";
      outputTxt1 = "Opens in: ";
  } else if ((openTime < localTime) && (closeTime > localTime)) {
      guildCountdown = closeTime - localTime;
      outputTxt2 = "Currently Open for business.";
      outputTxt1 = "Closes in: ";
  } else if (closeTime <= localTime)  {
      guildCountdown = (msGameDay - elapsedTime) + open;
      outputTxt2 = "Currently Closed. Open tomorrow.";
      outputTxt1 = "Opens in: ";    
  }
 
  // adjust for holiday
  if ((holiday == vDay) && (closeTime > localTime)) {
      guildCountdown = (msGameDay - elapsedTime) + open;
      outputTxt2 = "Currently Closed for Holiday.";
      outputTxt1 = "Opens in: ";
  } else if (((vDay + 1) == holiday) && (closeTime <= localTime))  {
      guildCountdown = (msGameDay - elapsedTime) + open + msGameDay;
      outputTxt2 = "Currently Closed. Holiday tomorrow.";
      outputTxt1 = "Opens in: ";
  }
 
  return outputTxt1 + formatCountdown(guildCountdown) + ". " + outputTxt2;
}
}


function formatCountdown(varTime) {
function _transportScheduleBody(schedule, numberOfEntries){
    var html = "";
   
    function _helper(sched){
        var offset = (sched[1] + sched[3] + sched[4]) * 60  * 1000 / 25;  // VANA MILLISECONDS
        //console.log("offset: ", offset, vanatime.now_inMS());
        while (offset <  vanatime.now_inMS() ) {
            offset +=  (sched[2] * 60 * 1000 / 25);
        }
        return offset; // VANA MILLISECONDS
    }


  var dayLeft = varTime / msRealDay;
    for( let x=0; x < schedule.length; x++ ){
  var hourLeft = (dayLeft - Math.floor(dayLeft)) * 24;
        var offset;
  var minLeft = (hourLeft - Math.floor(hourLeft)) * 60;
        for( let i=1 ; i <= numberOfEntries; i++ ){
  var secLeft = Math.floor((minLeft - Math.floor(minLeft)) * 60);
           
  var formattedTime = '';
            if ( i > 1 ) offset +=  (schedule[x][2] * 60 * 1000 / 25);
            else offset = _helper(schedule[x]);
           
            var earthdepTime = (vanatime.today_inMS() + ( offset * 25 ));
            var vanadepTime = earthdepTime  / ( 60 * 1000);
            //var arrTime = depTime - ( sched[2][4] * 60 * 1000); /// LEAVE THIS in the event someone wants to add ARRIVAL TIMES to future HTML tables


  dayLeft = Math.floor(dayLeft);
            html += '<TR><TD>' + schedule[x][0] + '</TD><TD>' + vanatime.stringVanaTime(vanadepTime) + '</TD><TD>' + vanatime.stringEarthTime(earthdepTime) + '</TD><TD>' + vanatime.timeUntil(earthdepTime)  +'</TD></TR>';
  hourLeft = Math.floor(hourLeft);
         }
  minLeft = Math.floor(minLeft);
    }
 
    return html;
  if (minLeft < 10) {minLeft = '0' + minLeft;}
  if (secLeft < 10) {secLeft = '0' + secLeft;}
 
  if (dayLeft > 0) {
      formattedTime = dayLeft + ':';
      if (hourLeft < 10) {
        formattedTime = formattedTime + '0' + hourLeft + ':';
      } else {
        formattedTime = formattedTime + hourLeft + ':';
      }          
  } else if (hourLeft > 0) {
      formattedTime = hourLeft + ':';
  }
 
  formattedTime = formattedTime + minLeft + ':' + secLeft;
  return formattedTime;
}
}


function pageHasElement(element){
function populateTransportSchedule(classname, schedule, numberOfEntries){
var _found = false;
   
     for (const [k,v] of Object.entries(element) ){
    if (numberOfEntries === 'undefined' || numberOfEntries === null) numberOfEntries = 1;
         var _ = document.getElementById(v);
      
         if ( _ ) { _found = true; break;
    const shipSched = document.getElementById(classname);
if (shipSched) {
         var _HTMLheader = _transportScheduleHeader(classname);
         var _HTMLbody = this._transportScheduleBody(schedule, numberOfEntries);
        shipSched.innerHTML = _HTMLheader + _HTMLbody + "</TABLE>";
     }
     }
    return _found;
}
}


function _airshipTablesHeader(header){
function updateGuilds(){
header += "<TR><TH ALIGN='LEFT'>Airship Route</TH>";
     if (!pageHasElement(timeElements.guilds)) return;
//header += "<TH ALIGN='LEFT'>Departure Day</TH>";
header += "<TH ALIGN='LEFT'>Arrival</TH>";
header += "<TH ALIGN='LEFT'>Departure</TH></TR>";
return header;
}
 
function getAirSched() {
var _found = false;
     for (const [k,v] of Object.entries(timeElements.ids.airships) ){
        var _ = document.getElementById(v);
        if ( _ ) { _found = true; break; } 
    }
  if (_found === false ) return;
   
  var timenow = new Date();
  var localTime = timenow.getTime();
  var elapsedTime = (localTime - basisDate.getTime()) % msGameDay;
  //var dayStart = localTime - elapsedTime;
  vanaDate = ((898 * 360 + 30) * msRealDay) + (localTime - basisDate.getTime()) * 25;
  vDay = Math.floor((vanaDate % (8 * msRealDay)) / (msRealDay));  


  var offset1 = ((1 * 60) + 10) * 60 * 1000 / 25; // 1:10 offset used by B->J J->S
const page_alchemy_hours = document.getElementById(timeElements.guilds.alchemy);
  var offset2 = ((2 * 60) + 40) * 60 * 1000 / 25; // 2:40 offset used by J->W K-J
    if ( page_alchemy_hours ) { page_alchemy_hours.innerHTML = _guildSchedule(schedule.guilds.alchemy); }
  var offset3 = ((4 * 60) + 10) * 60 * 1000 / 25; // 4:10 offset used by J->B S->J
  var offset4 = ((5 * 60) + 35) * 60 * 1000 / 25; // 5:35 offset used by J->K
  var offset5 = ((5 * 60) + 45) * 60 * 1000 / 25; // 5:45 offset used by W->J


  //var _table_headers = "";
const page_bonecraft_hours = document.getElementById(timeElements.guilds.boneworking);
const airships_main = document.getElementById(timeElements.ids.airships.main);
if ( page_bonecraft_hours ) { page_bonecraft_hours.innerHTML = _guildSchedule(schedule.guilds.boneworking); }
if (airships_main) {
var _HTMLout = "<TABLE CLASS='" + timeElements.ids.airships.main + "' WIDTH='400' CELLSPACING='0' CELLPADDING='0'>";
_HTMLout += _airshipTablesHeader(_HTMLout);
_HTMLout += AirHelper(elapsedTime, offset3, vDay, "Jeuno To Bastok");
_HTMLout += AirHelper(elapsedTime, offset4, vDay, "Jeuno To Kazham");
_HTMLout += AirHelper(elapsedTime, offset1, vDay, "Jeuno To San d'Oria");
_HTMLout += AirHelper(elapsedTime, offset2, vDay, "Jeuno To Windurst");
_HTMLout += AirHelper(elapsedTime, offset1, vDay, "Bastok To Jeuno");
_HTMLout += AirHelper(elapsedTime, offset2, vDay, "Kazham To Jeuno");
_HTMLout += AirHelper(elapsedTime, offset3, vDay, "San d'Oria To Jeuno");
_HTMLout += AirHelper(elapsedTime, offset5, vDay, "Windurst To Jeuno");
airships_main.innerHTML = _HTMLout + "</TABLE>";
}
const airships_bastok = document.getElementById(timeElements.ids.airships.bastok);
if (airships_bastok) {
var _HTMLout = "<TABLE CLASS='" + timeElements.ids.airships.bastok + "' WIDTH='400' CELLSPACING='0' CELLPADDING='0'>";
_HTMLout += _airshipTablesHeader(_HTMLout);
_HTMLout += AirHelper(elapsedTime, offset3, vDay, "Jeuno To Bastok");
_HTMLout += AirHelper(elapsedTime, offset1, vDay, "Bastok To Jeuno");
airships_bastok.innerHTML = _HTMLout + "</TABLE>";
}
const airships_sandy = document.getElementById(timeElements.ids.airships.sandy);
if (airships_sandy) {
var _HTMLout = "<TABLE CLASS='" + timeElements.ids.airships.sandy + "' WIDTH='400' CELLSPACING='0' CELLPADDING='0'>";
_HTMLout += _airshipTablesHeader(_HTMLout);
_HTMLout += AirHelper(elapsedTime, offset1, vDay, "Jeuno To San d'Oria");
_HTMLout += AirHelper(elapsedTime, offset3, vDay, "San d'Oria To Jeuno");
airships_sandy.innerHTML = _HTMLout + "</TABLE>";
}
const airships_windy = document.getElementById(timeElements.ids.airships.windy);
const page_clothcraft_hours = document.getElementById(timeElements.guilds.clothcrafting);
if (airships_windy) {
if ( page_clothcraft_hours ) { page_clothcraft_hours.innerHTML = _guildSchedule(schedule.guilds.clothcrafting); }
var _HTMLout = "<TABLE CLASS='" + timeElements.ids.airships.windy + "' WIDTH='400' CELLSPACING='0' CELLPADDING='0'>";
_HTMLout += _airshipTablesHeader(_HTMLout);
_HTMLout += AirHelper(elapsedTime, offset2, vDay, "Jeuno To Windurst");
_HTMLout += AirHelper(elapsedTime, offset5, vDay, "Windurst To Jeuno");
airships_windy.innerHTML = _HTMLout + "</TABLE>";
}
const airships_kazham = document.getElementById(timeElements.ids.airships.kazham);
if (airships_kazham) {
var _HTMLout = "<TABLE CLASS='" + timeElements.ids.airships.kazham + "' WIDTH='400' CELLSPACING='0' CELLPADDING='0'>";
_HTMLout += _airshipTablesHeader(_HTMLout);
_HTMLout += AirHelper(elapsedTime, offset4, vDay, "Jeuno To Kazham");
_HTMLout += AirHelper(elapsedTime, offset2, vDay, "Kazham To Jeuno");
airships_kazham.innerHTML = _HTMLout + "</TABLE>";
}
}  


function getShipSched()  {
const page_cooking_hours = document.getElementById(timeElements.guilds.cooking);
var _found = false;
if ( page_cooking_hours ) { page_cooking_hours.innerHTML = _guildSchedule(schedule.guilds.cooking);  }
    for (const [k,v] of Object.entries(timeElements.ids.boats) ){
        var _ = document.getElementById(v);
        if ( _ ) { _found = true; break; } 
    }
  if (_found === false ) return;
 
  var now = new Date();
  var timeDiff = now.getTime() - basisDate.getTime();
  var hours = Math.floor((timeDiff / ( msGameDay / 3)) % 3);
 
  var timeLeft = (msGameDay / 3 ) - (timeDiff % (msGameDay / 3));
  var repeatFerry = 5 ;
 
//    vanaDate =  ((898 * 360 + 30) * msRealDay) + (timeDiff) * 25;
//    vDay  = Math.floor((vanaDate % (8 * msRealDay)) / (msRealDay));
    // Boats depart at 00:00, 08:00, 16:00 from both Selbina and Mhuara
const page_fishing_hours = document.getElementById(timeElements.guilds.fishing);
  // Boats arrive at 06:30, 14:30, 22:30 which is 216 seconds before they leave
if ( page_fishing_hours ) { page_fishing_hours.innerHTML = _guildSchedule(schedule.guilds.fishing); }
const boats_selbina = document.getElementById(timeElements.ids.boats.selbina);
if (boats_selbina) {
var bSched = "<TABLE CLASS='" + timeElements.ids.boats.selbina + "' CELLSPACING='0' CELLPADDING='0'>";
bSched += "<TR><TH ALIGN='left'>Arrives</TH>";
bSched += "<TH ALIGN='left'>ETA</TH>";
bSched += "<TH ALIGN='left'>Departs</TH>";
bSched += "<TH ALIGN='left'>ETD</TH></TR>";
 
for ( i = 0; i < repeatFerry; i++) {
  timeLeftLoop = timeLeft + ( i* msGameDay / 3);
  //dPos = (vDay + Math.floor((hours + 1 + i)/3)) % 8;
  //dPos2 = (dPos + BoatDayOffset[(hours + i) % 3]) % 8;
  arrivalTime = timeLeftLoop - 216000;
  if (arrivalTime <= 0)
    arrivalTime = 0;
//bSched = bSched + '<TR><TD><FONT COLOR="' + DayColor[dPos2] + '">' + VanaDay[dPos2] + '</FONT></TD><TD>' + BoatSched2[(hours + i) % 3] + '</TD><TD>' + formatCountdown(arrivalTime) + '</TD><TD><FONT COLOR="' + DayColor[dPos] + '">' + VanaDay[dPos] + '</FONT></TD><TD>' + BoatSched[(hours + i) % 3] + '</TD><TD ALIGN="left">' + formatCountdown(timeLeftLoop) + '</TD></TR>';
bSched = bSched + '<TR><TD>' + BoatSched_selbina2[(hours + i) % 3] + '</TD><TD>' + formatCountdown(arrivalTime) + '</TD><TD>' + BoatSched_selbina[(hours + i) % 3] + '</TD><TD ALIGN="left">' + formatCountdown(timeLeftLoop) + '</TD></TR>';
}
  if (repeatFerry < 1) { out = ''; } else { out = bSched + "</TABLE>"; }
const page_goldsmithing_hours = document.getElementById(timeElements.guilds.goldsmithing);
 
if ( page_goldsmithing_hours ) { page_goldsmithing_hours.innerHTML = _guildSchedule(schedule.guilds.goldsmithing); }
boats_selbina.innerHTML = out;
}
const boats_ahturhgan = document.getElementById(timeElements.ids.boats.ahtUrhgan);
const page_leathercraft_hours = document.getElementById(timeElements.guilds.leathercrafting);
if (boats_ahturhgan) {
if ( page_leathercraft_hours ) { page_leathercraft_hours.innerHTML = _guildSchedule(schedule.guilds.leathercrafting); }
var bSched = "<TABLE CLASS='" + timeElements.ids.boats.ahtUrhgan + "' CELLSPACING='0' CELLPADDING='0'>";
bSched += "<TR><TH ALIGN='left'>Arrives</TH>";
bSched += "<TH ALIGN='left'>ETA</TH>";
bSched += "<TH ALIGN='left'>Departs</TH>";
bSched += "<TH ALIGN='left'>ETD</TH></TR>";
 
for ( i = 0; i < repeatFerry; i++) {
  timeLeftLoop = timeLeft + ( i* msGameDay / 3);
// dPos = (vDay + Math.floor((hours + 1 + i)/3)) % 8;
  //dPos2 = (dPos + BoatDayOffset[(hours + i) % 3]) % 8;
  arrivalTime = timeLeftLoop - 216000;
  if (arrivalTime <= 0)
    arrivalTime = 0;
//bSched = bSched + '<TR><TD><FONT COLOR="' + DayColor[dPos2] + '">' + VanaDay[dPos2] + '</FONT></TD><TD>' + BoatSched2[(hours + i) % 3] + '</TD><TD>' + formatCountdown(arrivalTime) + '</TD><TD><FONT COLOR="' + DayColor[dPos] + '">' + VanaDay[dPos] + '</FONT></TD><TD>' + BoatSched[(hours + i) % 3] + '</TD><TD ALIGN="left">' + formatCountdown(timeLeftLoop) + '</TD></TR>';
bSched = bSched + '<TR><TD>' + BoatSched_ahtUrhgan2[(hours + i) % 3] + '</TD><TD>' + formatCountdown(arrivalTime) + '</TD><TD>' + BoatSched_ahtUrhgan[(hours + i) % 3] + '</TD><TD ALIGN="left">' + formatCountdown(timeLeftLoop) + '</TD></TR>';
}


  if (repeatFerry < 1) { out = ''; } else { out = bSched + "</TABLE>"; }
const page_smithing_hours = document.getElementById(timeElements.guilds.smithing);
boats_ahturhgan.innerHTML = out;
if ( page_smithing_hours ) { page_smithing_hours.innerHTML = _guildSchedule(schedule.guilds.smithing); }  
}
    // TESTING DEPARTURE SCHEDULE
const page_woodworking_hours = document.getElementById(timeElements.guilds.woodworking);
    populateShipSchedule(timeElements.ids.boats.bibiki, schedule.boats.bibiki, 7);
if ( page_woodworking_hours ) { page_woodworking_hours.innerHTML = _guildSchedule(schedule.guilds.woodworking); }
    populateShipSchedule(timeElements.ids.boats.purgonorgoIsle, schedule.boats.purgonorgoIsle, 7);
    populateShipSchedule(timeElements.ids.boats.northLanding, schedule.boats.northLanding, 5);
    populateShipSchedule(timeElements.ids.boats.southLanding, schedule.boats.southLanding, 8);
    populateShipSchedule(timeElements.ids.boats.centralLanding, schedule.boats.centralLanding, 5);


    const page_allguilds_hours = document.getElementById(timeElements.guilds.all);
if ( page_allguilds_hours ) { 
       
        var guildOut = "<TABLE CLASS='"+ timeElements.guilds.all + "' CELLSPACING='0' CELLPADDING='0' border='1px solid black'>";
        guildOut = guildOut + "<TR><TH ALIGN='center' WIDTH=100 >Guild</TH>";
        guildOut = guildOut + "<TH ALIGN='center' WIDTH=175 >Status</TH></TR>";
        guildOut = guildOut + "<TR><TH> Alchemy</TH><td>" +        _guildSchedule(schedule.guilds.alchemy)        + "</td></TR>";
        guildOut = guildOut + "<TR><TH> Blacksmithing</TH><td>" +  _guildSchedule(schedule.guilds.smithing)     + "</td></TR>";
        guildOut = guildOut + "<TR><TH> Boneworking</TH><td>" +    _guildSchedule(schedule.guilds.boneworking) + "</td></TR>";
        guildOut = guildOut + "<TR><TH> Goldsmithing</TH><td>" +    _guildSchedule(schedule.guilds.goldsmithing) + "</td></TR>";
        guildOut = guildOut + "<TR><TH> Clothcrafting</TH><td>" +  _guildSchedule(schedule.guilds.clothcrafting) + "</td></TR>";
        guildOut = guildOut + "<TR><TH> Woodworking</TH><td>" +    _guildSchedule(schedule.guilds.woodworking) + "</td></TR>";
        guildOut = guildOut + "<TR><TH> Leatherworking </TH><td>" + _guildSchedule(schedule.guilds.leathercrafting) + "</td></TR>";
        guildOut = guildOut + "<TR><TH> Fishing</TH><td>" +        _guildSchedule(schedule.guilds.fishing)     + "</td></TR>";
        guildOut = guildOut + "<TR><TH> Cooking</TH><td>" +        _guildSchedule(schedule.guilds.cooking)     + "</td></TR>";
        guildOut = guildOut + "</TABLE>";
   
        page_allguilds_hours.innerHTML = guildOut;
    }
}
}


/**
function _guildSchedule(guild) {
* @param {timeElements} classname - class name from timeElements to be used for the table class
    if (guild === 'undefined') return "_guildSchedule: error";
* @param {schedule} scheduleID - from schedule array for current query
* @param {*} scheduleSize - total number of lines to display in the resulting table
*/
function populateShipSchedule(classname, scheduleID, scheduleSize){


     const shipSched = document.getElementById(classname);
     var now = vanatime.now_inMS();
if (shipSched) {
    var guildOpens = guild[0] * 60 * 1000 / 25;
        var bSched = "<TABLE CLASS='" + classname + "' WIDTH='400' CELLSPACING='0' CELLPADDING='0'>";
    var guildCloses = guild[1] * 60 * 1000 / 25;
bSched += "<TR><TH ALIGN='left'>VanaTime</TH>";
bSched += "<TH ALIGN='left'>Earth Time</TH>";
bSched += "<TH ALIGN='left'>Departure</TH>";
bSched += "<TH ALIGN='left'>Location</TH></TR>";


         var vanatime = new vanaTime();
    // Guild open/close check
         var currentTime = vanatime.getVanaDate();
    var nextOpenTime = 0;
    var outputTxt1 = "", outputTxt2 = "";
    if (guildOpens >= now) {
         nextOpenTime = (((guildOpens - now) * 25) + vanatime.now_inEarthMS());
        outputTxt2 = "Currently Closed. Open tomorrow.";
        outputTxt1 = "Opens in: ";
    } else if ((guildOpens < now) && (guildCloses > now)) {
        nextOpenTime = (((guildCloses - now) * 25) + vanatime.now_inEarthMS());
         outputTxt2 = "Currently Open for business.";
        outputTxt1 = "Closes in: ";
    } else if (guildCloses <= now)  {
        nextOpenTime = ((24 * 60 * 60 * 1000 / 25) - now ) + (guildOpens * 25) + vanatime.now_inEarthMS();
        outputTxt2 = "Currently Closed. Open tomorrow.";
        outputTxt1 = "Opens in: ";
    }
   


        // trying to get _count - this is the start point for the schedule based on current time
    // Holiday check
        // stops after 20 loops, just in case...  
    if ((guild[2] == vanatime.weekDay()) && (guildCloses > now)) {
        var _startPoint = 0;
        nextOpenTime = ((24 * 60 * 60 * 1000 / 25)  - now + guildOpens) * 25 + vanatime.now_inEarthMS();
        while ( _startPoint < scheduleID.length && _startPoint < 20) {
         outputTxt2 = "Currently Closed for Guild Holiday.";
            var scheduleDeparts = vanatime._rawVanaToday() + vanatime._convertMinsToMiliseconds(scheduleID[_startPoint].time);
         outputTxt1 = "Opens in: ";
            timerCountdown = scheduleDeparts - currentTime;
    } else if (((vanatime.weekDay() + 1) == guild[2]) && (guildCloses <= now)) {
            if (timerCountdown >= 0 ) { break;}
        nextOpenTime = ((24 * 60 * 60 * 1000 / 25)  - now) + (guildOpens * 25) + (24 * 60 * 60 * 1000 / 25) + vanatime.now_inEarthMS();
            _startPoint++;
        outputTxt2 = "Currently Closed. Guild Holiday tomorrow.";
        }
         outputTxt1 = "Opens in: ";
       
         var _dayMultiplier = 0; // helps us add another day if we need to calc any time on the next days schedule
         var _displayCounter = 0;  // # of entries in the printed schedule
       
        var kill = scheduleSize * 3;
        while ( _displayCounter < scheduleSize ){
            if ( _startPoint >= scheduleID.length){ //if we reach the end of the schedule array, then we need to start over and add 1440 to the times, so we can calc for the next day
                        _startPoint = 0;
                        _dayMultiplier++;
                    }
            var _nextTime = scheduleID[_startPoint].time + ( _dayMultiplier * 1440 );
           
           
            var scheduleDeparts = vanatime._rawVanaToday() + vanatime._convertMinsToMiliseconds(_nextTime) ;
            timerCountdown = scheduleDeparts - currentTime;
                if (timerCountdown >= 0 && scheduleID[_startPoint].act == "depart") {
                    bSched = bSched + '<TR><TD>' + vanatime.stringVanaTime(scheduleDeparts) + '</TD><TD>' + vanatime.stringEarthTime(scheduleDeparts) + '</TD><TD>' + vanatime.timeUntil(scheduleDeparts) + '</TD><TD>' + scheduleID[_startPoint].dest +'</TD></TR>';
                    _displayCounter++;
                }
                _startPoint++;
           
            // failsafe to prevent infinite loop
            kill--;
            if ( kill == 0 ) { console.log("populateShipSchedule: kill == 0 "); break; }
        }
       
         shipSched.innerHTML = bSched + "</TABLE>";
     }
     }
   
    return outputTxt1 + vanatime.timeUntil(nextOpenTime) + ". " + outputTxt2;
}
}


function updateConquest()  {
    if (!pageHasElement(timeElements.conquest)) return;
   
    function stringNextConquest(remaining){
        //if (nextConquest === undefined) { return "stringConquestTimer: timer undefined"; }
        const now = new Date();
        remaining = now.getTime() + remaining;


        var nextConquest = new Date(remaining);
        var tempHour = nextConquest.getHours();
        var tempMin  = nextConquest.getMinutes();
        var tempSec  = nextConquest.getSeconds();


function AirHelper(elapsed, offset, day, city) {
        if (tempHour < 10) tempHour = "0" + tempHour;
        if (tempMin < 10)  tempMin  = "0" + tempMin; 
        if (tempSec < 10)  tempSec  = "0" + tempSec; 


  var newOffset = offset;
        var strNextConquest = nextConquest.toDateString() + " " + tempHour + ":" + tempMin + ":" + tempSec;
  var count = 0;
  while (newOffset < elapsed) {
      count += 1;
      newOffset += (msGameDay / 4);
  }
  if (count >= 4) {
      day = (day + 1) % 8;  
  }


  output = "<TR><TD>" + city + "</TD>";  
            // var remaining = (temp.getTime() - now.getTime()) / (24 * 60 * 60 * 1000);
  //output += "<TD><FONT COLOR=" + DayColor[day] + ">" + VanaDay[day] + "</FONT></TD>";
            // var hours = (remaining - Math.floor(remaining)) * 24;
  arrivalTime = newOffset - elapsed - 144000;
            // var mins = (hours - Math.floor(hours)) * 60;
  if (arrivalTime < 0) {
            // var secs = Math.floor((mins - Math.floor(mins)) * 60);
      arrivalTime = 0;
  }
  output += "<TD>" + formatCountdown(arrivalTime,1) + "</TD>";
  output += "<TD>" + formatCountdown(newOffset - elapsed,1) + "</TD></TR>";  
 
  return output;
}


function getConquest() {
            // remaining = Math.floor(remaining);
            // hours = Math.floor(hours);
            // mins = Math.floor(mins);


  var now = new Date();
            // if (hours < 10) hours = "0" + hours;  
  var timeLeft = (7 * msRealDay) - ((now.getTime() - basisDate.getTime()) % (7 * msRealDay));
            // if (mins < 10)   mins  = "0" + mins;
  vanaConq = Math.floor(timeLeft / (msGameDay)) + 1;
            // if (secs < 10)   secs  = "0" + secs;


  conqDays = timeLeft / msRealDay;
            // // tempDays < 10 ? ["0", tempDays].join(':') : tempDays;
  conqHours = (conqDays - Math.floor(conqDays)) * 24;
            // // tempDays > 0 ? [tempDays, strTimer].join(':') : null;
  conqMin = (conqHours - Math.floor(conqHours)) * 60;
  conqSec = Math.floor((conqMin - Math.floor(conqMin)) * 60);


  if (conqDays < 10) { conqDays = '0' + Math.floor(conqDays); } else { conqDays = Math.floor(conqDays); }
            // strDiff = hours + ":" + mins + ":" + secs;
  if (conqHours < 10) { conqHours = '0' + Math.floor(conqHours ); } else { conqHours = Math.floor(conqHours ); }
  if (conqMin < 10) { conqMin = '0' + Math.floor(conqMin ); } else { conqMin = Math.floor(conqMin ); }
  if (conqSec < 10) { conqSec = '0' + Math.floor(conqSec ); } else { conqSec = Math.floor(conqSec ); }
 
  conqDate = formatDate(now.getTime() + timeLeft, 2);


  conq = vanaConq + ' Vana´diel Days <BR>' + conqDate + ' (' + formatCountdown(timeLeft) + ')';
        //return strNextConquest + "(" + strDiff + ")";
        return strNextConquest + "(" + vanatime.timeUntil(nextConquest) + ")";
    }
   
    const now = new Date();
    var remaining = vanatime.conquestRemainingTime();
    remainingVanaDaysOnConquest = vanatime.conquestRemainingVanaDays();
   
    conq = remainingVanaDaysOnConquest + ' Vana´diel Days <BR>';
    conq += stringNextConquest(remaining); //+ ' (' + timer.getHours() + ":" + timer.getMinutes() + ":" + timer.getSeconds() + ')';


  const conquest_time = document.getElementById(conquest_schedule);
    const conquest_time = document.getElementById(timeElements.conquest);
  if (conquest_time) conquest_time.innerHTML = conq;  
    if (conquest_time) conquest_time.innerHTML = conq;  
}
}


function updateMoonPhaseSchedule(){
    if (!pageHasElement(timeElements.moonSchedule)) return;


function getMoonPhase() {
    populateMoonPhaseSchedule(timeElements.moonSchedule, 7);
}


  var timenow = new Date();
function _moonPhaseScheduleHeader(classname){
  var localTime = timenow.getTime();
    var header = "<TABLE CLASS='" + classname + "' WIDTH='500' CELLSPACING='0' CELLPADDING='0'>";
  var moonDays = (Math.floor((localTime - Mndate.getTime()) / msGameDay))  % 84;
header += "<TR><TH ALIGN='LEFT'>Moon Phase</TH>";
header += "<TH ALIGN='LEFT'>Start Time</TH>";
header += "<TH ALIGN='LEFT'>End Time</TH>";
    //header += "<TH ALIGN='LEFT'>Phase Ends in...</TH>";
    header += "</TR>";
return header;
}


  var mnElapsedTime = (localTime - Mndate.getTime()) % msGameDay;
function _moonPhaseScheduleBody(numberOfEntries){
    var html = "";
   
    if ( numberOfEntries === undefined || numberOfEntries === null ) numberOfEntries = 7;
        var vTempTime = vanatime.today_inMS() / (60 * 1000); // VANA TIME IN TOTAL MINUTES
        var thisMoonPhase = vanatime.moonLatentPhase(vTempTime);  


  // determine phase percentage
        var lunarOffset = 0;
        moonpercent = - Math.round((42 - moonDays) / 42 * 100);
        for(var x = 0 ; x < numberOfEntries; x++ ){
        if (moonpercent <= -94)  {
            mnPhase = 0;
            optPhase = 4;
            toNextPhase = (3 - moonDays) * msGameDay - mnElapsedTime;
            toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime;


        }  else if (moonpercent >= 90) {
            if ( x > 0 ){
    mnPhase = 0;
                if (thisMoonPhase > 7) thisMoonPhase = 0;
            optPhase = 4;
                if ( thisMoonPhase == 1 || thisMoonPhase == 3 || thisMoonPhase == 5 || thisMoonPhase == 7) lunarOffset += 14;
            toNextPhase = (87 - moonDays) * msGameDay - mnElapsedTime;
                else lunarOffset += 7;
            toOptimalPhase = (38 + 84 - moonDays) * msGameDay - mnElapsedTime;
                thisMoonPhase++;
            }


        }  else if (moonpercent >= -93 && moonpercent <= -62) {
            var phaseStartTime;
      mnPhase = 1;
            for( var i = 1 ; i >= -13 ; i-- ) {
             optPhase = 4;
                var _time = vTempTime + (60 * 24 * lunarOffset) + (60 * 24 * (i - 1)); // VANA MINUTES
            toNextPhase = (17 - moonDays) * msGameDay - mnElapsedTime;
             //console.log("s", thisMoonPhase, lunarOffset, vanatime.moonLatentPhase(_time));
            toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime;
                if ( vanatime.moonLatentPhase(_time) != thisMoonPhase ) break;
                else phaseStartTime = _time * 60; // VANA SECONDS
            }


        }  else if (moonpercent >= -61 && moonpercent <= -41) {
            var phaseEndTime;
      mnPhase = 2;
            for( var i = -1 ; i <= 14 ; i++ ) {
             optPhase = 4;
                var _time = vTempTime + (60 * 24 * lunarOffset) + (60 * 24 * (i + 1));// VANA MINUTES
            toNextPhase = (25 - moonDays) * msGameDay - mnElapsedTime;
             //console.log("e", thisMoonPhase,lunarOffset,vanatime.moonLatentPhase(_time));
            toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime;
                if ( vanatime.moonLatentPhase(_time) != thisMoonPhase ) break;
                else phaseEndTime = (_time + (60 * 24)) * 60; // VANA SECONDS
                // for loop breaks when _time is at 00:00 for the day the moon phase changes...
                // we add another day to this (60 + 24) to get the start of the next day for the table
            }


        }  else if (moonpercent >= -40 && moonpercent <= -11) {
            const startDate = new Date(Math.floor(phaseStartTime / (25 / 1000)) - vanatime.getDifference() );
      mnPhase = 3;
             const endDate = new Date(Math.floor(phaseEndTime / (25 / 1000)) - vanatime.getDifference() );
             optPhase = 4;
            toNextPhase = (38 - moonDays) * msGameDay - mnElapsedTime;
            toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime;


        }  else if (moonpercent >= -10 && moonpercent <= 6) {
            var strDetails = vanatime.moonPhaseIcon(thisMoonPhase) + " " + vanatime.moonPhaseName(thisMoonPhase) + " " + vanatime.moonPhasePercentages(thisMoonPhase);          
      mnPhase = 4;
            optPhase = 0;
            toNextPhase = (45 - moonDays) * msGameDay - mnElapsedTime;
            toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime;


        }  else if (moonpercent >= 7 && moonpercent <= 36) {
            function dateString(date){
      mnPhase = 5;
                var sec = date.getSeconds(), hrs = date.getHours(), mins = date.getMinutes();
            optPhase = 0;
                sec < 10 ? sec = "0" + sec : sec;
            toNextPhase = (58 - moonDays) * msGameDay - mnElapsedTime;
                hrs < 10 ? hrs = "0" + hrs : hrs;
             toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime;
                mins < 10 ? mins = "0" + mins : mins;
                return vanatime.weekdayLabel(date.getDay()) + ", " + date.getDate() + " " + vanatime.monthLabel(date.getMonth()) + " " + hrs + ":" + mins + ":" + sec;
             }


        }  else if (moonpercent >= 37 && moonpercent <= 56)  {
            html += '<TR><TD>' + strDetails + '</TD><TD>' + dateString(startDate) + '</TD><TD>' + dateString(endDate) + '</TD>';
      mnPhase = 6;
            optPhase = 0;
            toNextPhase = (66 - moonDays) * msGameDay - mnElapsedTime;
            toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime;


        }  else if (moonpercent >= 57 && moonpercent <= 89) {
            // const now = new Date();
      mnPhase = 7;
             // var strTimer = vanatime.timer(endDate, now);
             optPhase = 0;
             // html += '<TD>' + strTimer + '</TD>';
            toNextPhase = (60 - moonDays) * msGameDay - mnElapsedTime;
             toOptimalPhase = (80 - moonDays) * msGameDay - mnElapsedTime;
        }


        mnpercent = PhaseName[mnPhase] + " (" + Math.abs(moonpercent) + "%)";
            html += '</TR>';
        }
    return html;
}


        if (moonpercent <= 5 && moonpercent >= -10) {
function populateMoonPhaseSchedule(classname, numberOfEntries){
              mnpercent = "<FONT COLOR='#FF0000'>" + mnpercent+ "</FONT>";
   
        } else if (moonpercent >= 90 || moonpercent <= -95)  {
    if (numberOfEntries === undefined || numberOfEntries === null) numberOfEntries = 7;
              mnpercent = "<FONT COLOR='#0000FF'>" + mnpercent+ "</FONT>";
   
        }
    const moonSchedule = document.getElementById(classname);
 
    if (moonSchedule) {
  nextPhase = "Next phase (" + PhaseName[(mnPhase + 1) % 8] + "): " + formatCountdown(toNextPhase);
        var _HTMLheader = this._moonPhaseScheduleHeader(classname);
  nextOptPhase = "Next " + PhaseName[optPhase] + ": " + formatCountdown(toOptimalPhase);
        var _HTMLbody = this._moonPhaseScheduleBody(numberOfEntries);
 
        moonSchedule.innerHTML = _HTMLheader + _HTMLbody + "</TABLE>";
  //mnpercent = "<DIV onmouseover='javascript:getMoonDetails()'>" + mnpercent + "</DIV>  ";
    }
//document.getElementById("mPhase").innerHTML = mnpercent + nextPhase + "<BR>" + nextOptPhase;
const moon_phase_div = document.getElementById(moon_phase);
if (moon_phase_div) moon_phase_div.innerHTML = mnpercent + nextPhase + "<BR>" + nextOptPhase;;
 
 
  // new moon starts on day 38 (-10%)
  // full moon starts at 80 (90%)
  // Moon cycle lasts 84 game days.
 
  // Determine most recent full moon
  var fullMoonBasis = Mndate.getTime() + (3 * msGameDay);
  var repeatCal = 5;
 
  moonCal = "<TABLE CLASS='blank' CELLSPACING='0' CELLPADDING='0' border='1px solid black'><TR><TH WIDTH='115' ALIGN='left'>New Moon Start</TH><TH WIDTH='115' ALIGN='left'>New Moon End</TH><TH WIDTH='115' ALIGN='left'>Full Moon Start</TH><TH WIDTH='115' ALIGN='left'>Full Moon End</TH></TR>";
  for ( i = 0; i < repeatCal; i++)  {
      elapsedCycles = Math.floor( (localTime - fullMoonBasis) / (84 * msGameDay) ) + i;
      FullEnd = fullMoonBasis + (elapsedCycles * 84 * msGameDay);
      //Full Moon starts 7 games days prior to end
      FullStart = FullEnd - 7 * msGameDay;
      //New Moon starts 49 games days prior to Full Moon end
      NewStart = FullEnd - 49 * msGameDay;
      //New Moon ends 42 games days prior to Full Moon end
      NewEnd = FullEnd - 42 * msGameDay;
 
      moonCal = moonCal + "<TR><TD>" + formatDate(NewStart, 2) + "</TD><TD>" + formatDate(NewEnd, 2) + "</TD><TD>" + formatDate(FullStart,2) + "</TD><TD>" + formatDate(FullEnd, 2) + "</TD></TR>";
  }
  if (repeatCal < 1) { moonCal = ""; } else { moonCal = moonCal + '</TABLE>'; }
 
  // moon_phases
  //document.getElementById("mCalendar").innerHTML = moonCal;
  const moon_phases_schedule_div = document.getElementById(moon_phases_schedule);
if (moon_phases_schedule_div) moon_phases_schedule_div.innerHTML = moonCal;
}
}


function formatDate(varTime, showDay) {


  var varDate = new Date(varTime);
function updateRSE() {
  var yyyy = varDate.getYear();
    if (!pageHasElement(timeElements.rseSchedule)) return;
        function formatDate(varTime, showDay) {


  var mm = varDate.getMonth() + 1;
            var varDate = new Date(varTime);
  if (mm < 10) { mm = "0" + mm; }
            var yyyy = varDate.getYear();
       
            var mm = varDate.getMonth() + 1;
            if (mm < 10) { mm = "0" + mm; }
       
            var dd = varDate.getDate();
            if (dd < 10) { dd = "0" + dd; }
       
            var day = varDate.getDay();
       
            var hh = varDate.getHours();
           
            if (hh < 10) { hh = "0" + hh; }
       
            var min = varDate.getMinutes();
            if (min < 10) { min = "0" + min; }
       
            var ss = varDate.getSeconds();
            if (ss < 10) { ss = "0" + ss; }
            if (showDay == 1)  {
            dateString = vanatime.weekdayLabel(day) + ", " + vanatime.monthLabel(mm-1) + ' ' + dd + ', ' + yyyy + " " + hh + ":" + min + ":" + ss;
            } else if (showDay == 2)  {
            dateString = vanatime.monthLabel(mm-1) + " " + dd + ",  " + hh + ":" + min + ":" + ss;
            }
            return dateString;
        }
   
    var timenow = new Date();
    var localtime = timenow.getTime();


   var dd = varDate.getDate();
    var repeatCal = 10;
   if (dd < 10) { dd = "0" + dd; }
    var race = 8;
    if (race > 7) {
      RSECal = "<TABLE CLASS=\'" + timeElements.rseSchedule + "\' WIDTH='500' CELLSPACING='0' CELLPADDING='0'><TR><TH ALIGN='LEFT'>Date & Time</TH><TH ALIGN='LEFT'>Race</TH><TH ALIGN='LEFT'>Location</TH></TR>"
      for ( i = 0; i < repeatCal; i++) {
          elapsedWeeks = Math.floor( (localtime - vanatime.rseDate) / (8 * (24 * 60 * 60 * 1000 / 25)) ) + i;
          RSEstart = vanatime.rseDate + (elapsedWeeks * 8 * (24 * 60 * 60 * 1000 / 25));
          RSECal = RSECal + "<TR><TD>" + formatDate(RSEstart,2) + '</TD><TD>' + vanatime.rseRace(elapsedWeeks % 8) + '</TD><TD>';
          //RSECal = RSECal + "<A HREF=#  onmousedown='javascript:getRSEDetails(" + (elapsedWeeks % 3) + ")'>";
          RSECal = RSECal + vanatime.rseLocation(elapsedWeeks % 3);
          RSECal = RSECal + '</A></TD></TR>';
      }
      if (repeatCal < 1) { RSECal = ""; } else { RSECal = RSECal + '</TABLE>'; }
    }
    // else {
    //   RSECal = "<TABLE CLASS='blank' CELLPADDING='0' CELLSPACING='0'><TR><TH WIDTH='120' ALIGN='LEFT'>Start</TH><TH WIDTH='120' ALIGN='LEFT'>End</TH><TH WIDTH='60' ALIGN='LEFT'>Location</TH></TR>"
    //    offsetTime = race * 8 * msGameDay;
    //    for ( i = 0; i < repeatCal; i++) {
    //      elapsedWeeks = Math.floor( (localtime - vanatime.rseDate) / (64 * msGameDay) ) + i;
         
    //      elapsedLocationWeeks = Math.floor( (localtime - vanatime.rseDate) / (8 * msGameDay) ) + (8 * i);
    //      raceOffset = race - (elapsedLocationWeeks % 8);
    //      elapsedLocationWeeks = elapsedLocationWeeks + raceOffset;
    //      RSEstart = vanatime.rseDate + (elapsedWeeks * 64 * msGameDay) + offsetTime ;
    //      RSEend = RSEstart + (8 * msGameDay);
    //      RSECal = RSECal + "<TR><TD>" + formatDate(RSEstart,2) + "</TD><TD>" + formatDate(RSEend,2) + "</TD><TD>";
    //      //RSECal = RSECal + "<A HREF=#  onmousedown='javascript:getRSEDetails(" + (elapsedLocationWeeks % 3) + ")'>";
    //      RSECal = RSECal + RSEloc[(elapsedLocationWeeks) % 3]
    //      RSECal = RSECal + "</A></TD></TR>";
    //   }
    //  if (repeatCal < 1) { RSECal = ""; } else { RSECal = RSECal + '</TABLE>'; }
    // }
    document.getElementById(timeElements.rseSchedule).innerHTML = RSECal;
}


  var day = varDate.getDay();
function gametick(){
 
  var hh = varDate.getHours();
 
  if (hh < 10) { hh = "0" + hh; }
 
  var min = varDate.getMinutes();
  if (min < 10) { min = "0" + min; }
 
  var ss = varDate.getSeconds();
  if (ss < 10) { ss = "0" + ss; }
 
  if (showDay == 1)  {
      dateString = EarthDay[day] + ", " + sMonth[mm-1] + ' ' + dd + ', ' + yyyy + " " + hh + ":" + min + ":" + ss;
  } else if (showDay == 2)  {
      dateString = sMonth[mm-1] + " " + dd + ",  " + hh + ":" + min + ":" + ss;
  }
  return dateString;
}
 
function getGuildHours() {
      
      
  alchemy = guildHelper(8, 23, 6);
    updateSidebar();
  blacksmith = guildHelper(8, 23, 2);
    updateAirshipSchedule();
  bonework = guildHelper(8, 23, 3);
    updateBoatSchedule();
  goldsmith = guildHelper(8, 23, 4);
    updateGuilds();
  cloth = guildHelper(6, 21, 0);
updateConquest();
  wood = guildHelper(6, 21, 0);
    updateMoonPhaseSchedule();
  leather = guildHelper(3, 18, 4);
    updateRSE();
  fishing = guildHelper(3, 18, 5);
  cooking = guildHelper(5, 20, 7);


  guildOut = "<TABLE CLASS='"+ crafting_guilds_schedule_table + "' CELLSPACING='0' CELLPADDING='0' border='1px solid black'>";
  guildOut = guildOut + "<TR><TH ALIGN='center' WIDTH=100 >Guild</TH>";
  guildOut = guildOut + "<TH ALIGN='center' WIDTH=175 >Status</TH></TR>";
  guildOut = guildOut + "<TR><TH> Alchemy</TH><td>" + alchemy + "</td></TR>";
  guildOut = guildOut + "<TR><TH> Blacksmithing</TH><td>" + blacksmith + "</td></TR>";
  guildOut = guildOut + "<TR><TH> Boneworking</TH><td>" + bonework + "</td></TR>";
  guildOut = guildOut + "<TR><TH> Goldsmithing</TH><td>" + goldsmith + "</td></TR>";
  guildOut = guildOut + "<TR><TH> Clothcrafting</TH><td>" + cloth + "</td></TR>";
  guildOut = guildOut + "<TR><TH> Woodworking</TH><td>" + wood + "</td></TR>";
  guildOut = guildOut + "<TR><TH> Leatherworking </TH><td>" + leather + "</td></TR>";
  guildOut = guildOut + "<TR><TH> Fishing</TH><td>" + fishing + "</td></TR>";
  guildOut = guildOut + "<TR><TH> Cooking</TH><td>" + cooking + "</td></TR>";
  guildOut = guildOut + "</TABLE>";
 
//document.getElementById(crafting_guilds_schedule).innerHTML = guildOut;
const crafting_guilds_schedule_div = document.getElementById(crafting_guilds_schedule);
if (crafting_guilds_schedule_div) crafting_guilds_schedule_div.innerHTML = guildOut;
}
function gametick(){
resetGameTime();
getConquest();
getMoonPhase();
getAirSched();
getShipSched();
getGuildHours();
setTimeout("gametick()", 500);
setTimeout("gametick()", 500);
}
}


gametick();
gametick();

Revision as of 22:51, 11 December 2023

/*********************************************************************
Javascript below contributes to Vana'diel Time displays throughout
the HorizonXI Wiki
Credits: ********
https://www.pyogenes.com/ffxi/timer/v2.html 
https://www.mithrapride.org/vana_time/index.html
https://www.rubydoc.info/gems/vanadiel-time/Vanadiel/Time
**********************************************************************/

class timeElements {
// List of all class names for each element in this model, for styling 

	static sidebar = "page-vanatime";
    static conquest = "vanatime-page-conquest-schedule"; // <span ... />
    static moonPhase = "vanatime-page-moon-phase";   //  <span ... />
    static moonSchedule = "vanatime-page-moon-schedule-table";
    static rseSchedule = "vanatime-page-rse-schedule-table";
    
    static airships = {
        all : "vanatime-airship-schedule-table",
        jeuno : "vanatime-airship-schedule-jeuno-table",
        bastok : "vanatime-airship-schedule-bastok-table",
        sandy : "vanatime-airship-schedule-sandy-table",
        windy : "vanatime-airship-schedule-windy-table",
        kazham : "vanatime-airship-schedule-kazham-table",
    };

    static boats = {
        selbina : "vanatime-boat-schedule-selbina-table",
        mhaura : "vanatime-boat-schedule-mhaura-table",
        bibiki : "vanatime-boat-schedule-bibiki-table",
        purgonorgoIsle : "vanatime-boat-schedule-purgonorgoIsle-table",
        northLanding : "vanatime-boat-schedule-northLanding-table",
        centralLanding : "vanatime-boat-schedule-centralLanding-table",
        southLanding : "vanatime-boat-schedule-southLanding-table"
    };

    static guilds = {
        alchemy : "vanatime-guild-schedule-alchemy",
        smithing : "vanatime-guild-schedule-smithing",
        boneworking : "vanatime-guild-schedule-boneworking",
        goldsmithing : "vanatime-guild-schedule-goldsmithing",
        clothcrafting : "vanatime-guild-schedule-clothcrafting",
        woodworking : "vanatime-guild-schedule-woodworking",
        leathercrafting : "vanatime-guild-schedule-leatherworking",
        fishing : "vanatime-guild-schedule-fishing",
        cooking : "vanatime-guild-schedule-cooking",
        all : "vanatime-guild-schedule-all"
    };
}


class schedule {
    //  All raw datea is from ASB 
    //  route definintion = [ 'Name of route', anim_arrive, anim_depart, timeOffset, time_interval, time_anim_arrive, time_waiting, time_anim_depart]
    //  Actual arrival time (when the player can enter the transport ) = time_offset + time_anim_arrive = [3] + [5]
    //  Departure time = arrival time + time_waiting = arrival_time + [6]
    //  All values listed are in VanaTime minutes, so 1440 is the total minutes in a game hour
    
        static #airship_jeuno_sandy = ['Jeuno -> Sandoria',   0,   360, 12, 60, 12];
        static #airship_jeuno_windy = ['Jeuno -> Windurst',   90,  360, 12, 60, 12];
        static #airship_jeuno_bastok = ['Jeuno -> Bastok',     180, 360, 12, 60, 16];
        static #airship_jeuno_kazham = ['Jeuno -> Kazham',     270, 360, 20, 50, 20];
        static #airship_bastok_jeuno = ['Bastok -> Jeuno',     0,   360, 14, 60, 16];
        static #airship_sandy_jeuno = ['Sandoria -> Jeuno',   180, 360, 12, 60, 16];
        static #airship_windy_jeuno = ['Windurst -> Jeuno',   270, 360, 18, 60, 14];
        static #airship_kazham_jeuno = ['Kazham -> Jeuno',     90,  360, 20, 50, 20];
    
        static airships = {
            jeuno : [
                this.#airship_jeuno_bastok,
                this.#airship_jeuno_sandy,
                this.#airship_jeuno_windy,
                this.#airship_jeuno_kazham,
                this.#airship_bastok_jeuno,
                this.#airship_sandy_jeuno,
                this.#airship_windy_jeuno,
                this.#airship_kazham_jeuno
            ],
            bastok :    [ this.#airship_bastok_jeuno, this.#airship_jeuno_bastok],
            sandy :     [this.#airship_sandy_jeuno, this.#airship_jeuno_sandy],
            windy :     [this.#airship_windy_jeuno, this.#airship_jeuno_windy],
            kazham :    [this.#airship_kazham_jeuno, this.#airship_jeuno_kazham]
        }
    
        static #boat_selbina_mhaura = ['Selbina -> Mhaura',     382, 480, 18, 80, 17];
        static #boat_mhaura_selbina = ['Mhaura -> Selbina',     382, 480, 18, 80, 17];
        static #boat_mhaura_whitegate = ['Mhaura -> Whitegate', 142, 480, 18, 80, 17];
    
        static #boat_whitegate_mhaura = ['Whitegate -> Mhaura', 142, 480, 18, 80, 16];
        static #boat_whitegate_nashmau = ['Whitegate -> Nashmau', 282, 480, 18, 180, 17];
        static #boat_nashmau_whitegate = ['Nashmau -> Whitegate', 282, 480, 18, 180, 17];
    
        static #boat_bibiki_tours = ['Bibiki Bay -> Tours', 710, 720, 20, 40, 20];
        static #boat_bibiki_purgo = ['Bibiki Bay -> Purgonorgo Isle', 270, 720, 20, 40, 20];
        static #boat_purgo_bibiki = ['Purgonorgo Isle -> Bibiki Bay', 500, 720, 20, 40, 20];
    
        static #boat_barge_south_central_emfa = ['South Landing -> Central Landing EMFEA', 5, 1440, 15, 35, 15];
        static #boat_barge_central_south_newtpool1 = ['Central Landing -> South Landing NewtPool', 267, 1440, 12, 30, 15];
        static #boat_barge_south_oos = ['South Landing -> OOS', 1402, 1440, 33,  0,  0];
        static #boat_barge_south_north = ['South Landing -> North Landing', 560, 1440, 15, 35, 15];
        static #boat_barge_north_oos = ['North Landing -> OOS', 925, 1440, 40,  0,  0];
        static #boat_barge_north_central = ['North Landing -> Central Landing',  993, 1440, 12, 40, 15];
        static #boat_barge_central_south_newtpool2 = ['Central Landing -> South Landing NewtPool 2', 1148, 1440, 12, 30, 15];
        static #boat_barge_south_oos1 = ['South Landing -> OOS 2', 512, 1440, 33,  0,  0];
    
        static boats = {
            selbina :  [ this.#boat_selbina_mhaura ],
            mhaura :  [ this.#boat_mhaura_selbina, this.#boat_mhaura_whitegate ],
            whitegate : [ this.#boat_whitegate_mhaura, this.#boat_whitegate_nashmau],
            nashmau : [ this.#boat_nashmau_whitegate ],
            bibiki :  [ this.#boat_bibiki_tours, this.#boat_bibiki_purgo],
            purgonorgoIsle : [ this.#boat_purgo_bibiki ],
            northLanding : [ this.#boat_barge_north_oos, this.#boat_barge_north_central ],
            centralLanding : [ this.#boat_barge_central_south_newtpool1, this.#boat_barge_central_south_newtpool2 ],
            southLanding : [ this.#boat_barge_south_central_emfa, this.#boat_barge_south_oos, this.#boat_barge_south_north, this.#boat_barge_south_oos1 ]
        }
    
        static #alchemy = [480, 1380, 5];
        static #smithing = [480, 1380, 2];
        static #boneworking = [480, 1380, 3];
        static #goldsmithing = [480, 1380, 4];
        static #clothcrafting = [360, 1260, 0];
        static  #woodworking = [360, 1260, 0];
        static #leathercrafting = [180, 1080, 4];
        static #fishing = [180, 1080, 5];
        static #cooking = [300, 1200, 7];
    
        static guilds = {
            // [ Open, Close, Holiday]
            alchemy : this.#alchemy,
            smithing : this.#smithing,
            boneworking : this.#boneworking,
            goldsmithing : this.#goldsmithing,
            clothcrafting : this.#clothcrafting,
            woodworking : this.#woodworking,
            leathercrafting : this.#leathercrafting,
            fishing : this.#fishing,
            cooking : this.#cooking,
            all : [ this.#alchemy, this.#smithing, this.#boneworking,this.#goldsmithing, this.#clothcrafting,this.#woodworking,this.#leathercrafting, this.#fishing, this.#cooking ]
        }
    
}

class VanaTime{
    
    #elementalDay =     ["Firesday",    "Earthsday",        "Watersday",        "Windsday",         "Iceday",           "Lightningday",     "Lightsday",    "Darksday"];
    #dayColor =         ["#FF0000",     "#AAAA00",          "#0000DD",           "#00AA22",         "#7799FF",          "#AA00AA",          "#AAAAAA",      "#333333"];
    #moonPhaseName =    ["New Moon",    "Waxing Crescent",  "First Quarter",    "Waxing Gibbous",   "Full Moon",        "Waning Gibbous",   "Last Quarter", "Waning Crescent"];
    #moonIcon =         ['\u{1F311}',   '\u{1F312}',        '\u{1F313}',        '\u{1F314}',        '\u{1F315}',        '\u{1F316}',        '\u{1F317}',    '\u{1F318}'];
    #moonPercentages =  ["(10%-0%-5%)", "(7%-38%)",         "(40%-55%)",        "(57%-88%)",        "(90%-100%-95%)",    "(93%-62%)",       "(60%-45%)",    "(43%-12%)"];
    #month =            ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
    #weekday =          ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
    #rseRace =          ["M. Hume","F. Hume","M. Elvaan","F. Elvaan","M. TaruTaru","F. TaruTaru","Mithra","Galka"];
    #rseLocation =      ["Gusgen Mines","Shakrami Maze","Ordelle Caves"];

    
    // Conversions in Milliseconds
    //#baseDate; // built at runtime: 1024844400000
    #moonDate =     1074997872000; // in milliseconds
    #VTIME_BIRTH     = 1024844400000; // vana birthday - in milliseconds
    #VTIME_BASEDATE  = 1009810800;  // unix epoch - 1009810800 = se epoch (in earth seconds)
    rseDate =      1075281264000;

    #ONE_SECOND = 1000000;
    #ONE_MINUTE;
    #ONE_HOUR;
    #ONE_DAY;
    // #ONE_WEEK;
    // #ONE_MONTH;
    // #ONE_YEAR;

    // Conversions in Minutes
    #VTIME_YEAR  =      518400;   // 360 * GameDay
    #VTIME_MONTH =      43200;      // 30 * GameDay
    #VTIME_WEEK  =      11520;      // 8 * GameDay
    #VTIME_DAY   =      1440;       // 24 hours * GameHour
    #VTIME_HOUR  =      60;         // 60 minutes
    #VMULTIPLIER =      25;
    #MOON_CYCLE_DAYS =  84;
    // #MOON_CYCLE_PHASE = 17280;     // 1 moon phase cycle = 12 vana days = 12 * Gameday

    /*
        Some of the math...

        (((898 * 360) + 30) * 24 * 60 * 60) / (this.#VMULTIPLIER / 1000).....  
        converts vana time to earth time by ( / 25 ) then getting to milliseconds ( * 1000 )
    */
    #vanaBirthday = (((898 * 360) + 30) * 24 * 60 * 60) / (25 / 1000); // 1117359360000 - in earth time milliseconds
    #difference = this.#vanaBirthday - this.#VTIME_BIRTH; // 92514960000 - earth time milliseconds

    getDifference(){ return this.#difference };

    /**
     * Common variables for quick reference to current Vana time
     * @returns - integer / number
     */
    // vana_currentTime_inEarthMS = ((898 * 360 + 30) * (24 * 60 * 60 * 1000)) + (this.earthDate.getTime() - this.#VTIME_BIRTH) * this.#VMULTIPLIER; // vana time, represented in earth milliseconds - used for making Date() objects
    // vana_currentTime = this.vana_currentTime_inEarthMS / (60 * 1000); // vana time in minutes
    // //vana_currentTime = ( ((this.earthDate.getTime() / 1000) - this.#VTIME_BASEDATE ) / 60.0 * this.#VMULTIPLIER) + (886 * this.#VTIME_YEAR); //returned in vana minutes
    // vana_year = this.vana_currentTime / this.#VTIME_YEAR;
    // vana_month  = (this.vana_currentTime / this.#VTIME_MONTH) % 12 + 1;
    // vana_date = (this.vana_currentTime / this.#VTIME_DAY) % 30 + 1;
    // vana_weekday  = Math.floor((this.vana_currentTime % this.#VTIME_WEEK) / this.#VTIME_DAY);
    // vana_hour = (this.vana_currentTime % this.#VTIME_DAY) / this.#VTIME_HOUR;
    // vana_mins  = this.vana_currentTime % this.#VTIME_HOUR;
    // vana_moonphase  = Math.floor((this.vana_currentTime % this.#MOON_CYCLE_PHASE) / this.#VTIME_DAY);

    /**
     * Helper functions for quick reference to any Vana time
     * @returns - integer / number
     */
    now_inEarthMS(){ 
        var now = new Date();
        return ((898 * 360 + 30) * (24 * 60 * 60 * 1000)) + (now.getTime() - this.#VTIME_BIRTH) * this.#VMULTIPLIER; 
    }

    now(){ return this.now_inEarthMS() / ( 60 * 1000); }

    now_inMS(){
        var timenow = new Date();
        return ((timenow.getTime() - this.#VTIME_BIRTH) % (24 * 60 * 60 * 1000 / 25));
    }

    now_inMINS(){
        return this.now_inMS / ( 1000 * 60 );
    }

    today_inMS(){ // result in earth Milliseconds
        var now = this.now_inEarthMS();
        return ( now - ( now % (24 * 60 * 60 * 1000) ));
    }

    year(vanatime) {
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return Math.floor(vanatime / this.#VTIME_YEAR);
    }

    month(vanatime){
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return Math.floor((vanatime / this.#VTIME_MONTH) % 12) + 1;
    }

    date(vanatime){
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return Math.floor((vanatime / this.#VTIME_DAY) % 30) + 1;
    }
    
    weekDay(vanatime){
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return Math.floor((vanatime % this.#VTIME_WEEK) / this.#VTIME_DAY);
    }

    hour(vanatime){
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return Math.floor((vanatime % this.#VTIME_DAY) / this.#VTIME_HOUR);
    }

    mins(vanatime){
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return Math.floor(vanatime % this.#VTIME_HOUR);
    }

    dayColor(vanatime){ 
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return this.#dayColor[this.weekDay()];
    }
    
    dayLabel(day){ 
        if (day === undefined || day == null) return this.#elementalDay[this.weekDay()];
        else return this.#elementalDay[day]
    }

    moonPhaseIcon(day){  
        if (day === undefined || day == null) return this.#moonIcon[this.moonLatentPhase()];
        else return this.#moonIcon[day];
    }

    moonPhaseName(day){  
        if (day === undefined || day == null) return this.#moonPhaseName[this.moonLatentPhase()];
        else return this.#moonPhaseName[day];
    }

    moonPhasePercentages(day){  
        if (day === undefined || day == null) return this.#moonPercentages[this.moonLatentPhase()];
        else return this.#moonPercentages[day];
    }

    /**     
     * Time Helper functions - supports string generation for month/week details
     * @param  (required) - represents which RACE 
     * @returns - string - from #rseRace or #rseLocation
     */
    monthLabel(m){ return this.#month[m]; }
    weekdayLabel(w){ return this.#weekday[w]; }

    /**     
     * RSE Helper functions - supports string generation for RSE details
     * @param r (required) - represents which RACE 
     * @returns - string - from #rseRace or #rseLocation
     */ 
    rseRace(r){ return this.#rseRace[r]; }

    /**     
     * RSE Helper functions - supports string generation for RSE details
     * @param r (required) - represents which RACE 
     * @returns - string - from #rseRace or #rseLocation
     */ 
    rseLocation(r){ return this.#rseLocation[r]; }

    constructor(){
        this.#ONE_MINUTE = 60  * this.#ONE_SECOND;
        this.#ONE_HOUR = 60  * this.#ONE_MINUTE;
        this.#ONE_DAY = 24  * this.#ONE_HOUR;
        // this.#ONE_WEEK = 8   * this.#ONE_DAY;
        // this.#ONE_MONTH = 30  * this.#ONE_DAY;
        // this.#ONE_YEAR = 360 * this.#ONE_DAY;

        // this.#MOON_CYCLE_PHASE = 12 * this.#VTIME_WEEK;
    }

    /******************************** MOON PHASES **********************************
 
     0% NM   7% WXC    40% FQM   57% WXG   90% FM  93% WNG  60% LQM  43% WNC  10% NM 
     2% NM  10% WXC    43% FQM   60% WXG   93% FM  90% WNG  57% LQM  40% WNC   7% NM
     5% NM  12% WXC    45% FQM   62% WXG   95% FM  88% WNG  55% LQM  38% WNC   5% NM
            14% WXC    48% FQM   64% WXG   98% FM  86% WNG  52% LQM  36% WNC   2% NM
            17% WXC    50% FQM   67% WXG  100% FM  83% WNG  50% LQM  33% WNC
            19% WXC    52% FQM   69% WXG   98% FM  81% WNG  48% LQM  31% WNC
            21% WXC    55% FQM   71% WXG   95% FM  79% WNG  45% LQM  29% WNC
            24% WXC              74% WXG           76% WNG           26% WNC
            26% WXC              76% WXG           74% WNG           24% WNC
            29% WXC              79% WXG           71% WNG           21% WNC
            31% WXC              81% WXG           69% WNG           19% WNC
            33% WXC              83% WXG           67% WNG           17% WNC
            36% WXC              86% WXG           64% WNG           14% WNC
            38% WXC              88% WXG           62% WNG           12% WNC
    ********************************************************************************/
    /**     
     * Private function - supports moon phase calculations 
     * @param vanatime (required) - Vanadiel time, in MILLISECONDS
     * @returns - integer - represents the day in the 84 day moon phase cycle
     */ 
    #moonDays(vanatime){ 
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return  ((( vanatime /  this.#VTIME_DAY ) + 26) % this.#MOON_CYCLE_DAYS); 
    }  

    /**
     * Private function for doing arithmetic for moon phase percentage
     * @param vanatime (required) - Vanadiel time, in MILLISECONDS
     * @returns - integer representing moon phase percentage
     */ 
    #moonPercent(vanatime){ 
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        return Math.abs( -Math.round((42 - Math.floor(this.#moonDays(vanatime))) / 42 * 100) ); 
    }

    /**
     * Helper function for getting moon phase percentage
     * @param vanatime (required) - Vanadiel time, in MILLISECONDS
     * @returns - integer representing moon phase percentage
     */ 
    getMoonPercent(vanatime) { return this.#moonPercent(vanatime)};

    /**
     * @param vanatime - Vanadiel time, in MILLISECONDS; default value is now()
     * @returns - integer representing waxing/waning/neither
     */ 
    #moonDirection(vanatime){
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        var moondays = Math.floor(this.#moonDays(vanatime));
        //console.log(daysmod);
        if (moondays == 42 || moondays == 0) { return 0; }// neither waxing nor waning
        else if (moondays < 42){ return 1; } // waning
        else{ return 2; } // waxing
    }

    /**
     * @param vanatime - Vanadiel time, in MILLISECONDS; default value is now()
     * @returns - total milliseconds remaining until next conquest update
     */ 
    moonLatentPhase(vanatime){
        if (vanatime === undefined || vanatime == null) vanatime = this.now();
        var moonPhase = this.#moonPercent(vanatime);
        var moonDirection = this.#moonDirection(vanatime);

        //console.log("*mP", moonPhase);
        //console.log("*mD", moonDirection);
        
        if (moonPhase <= 5 || (moonPhase <= 10 && moonDirection == 1)) {return 0;} // New Moon - 10% waning -> 5% waxing
        else if (moonPhase >= 7 && moonPhase <= 38 && moonDirection == 2) {return 1;}  // Waxing Crescent - 7% -> 38% waxing
        else if (moonPhase >= 40 && moonPhase <= 55 && moonDirection == 2){return 2;}  // First Quarter - 40%% -> 55% waxing
        else if (moonPhase >= 57 && moonPhase <= 88 && moonDirection == 2){return 3;}  // Waxing Gibbous - 57% -> 88%
        else if (moonPhase >= 95 || (moonPhase >= 90 && moonDirection == 2)){return 4;}  // Full Moon - waxing 90% -> waning 95%
        else if (moonPhase >= 62 && moonPhase <= 93 && moonDirection == 1){return 5;}  // Waning Gibbous - 93% -> 62%
        else if (moonPhase >= 45 && moonPhase <= 60 && moonDirection == 1){return 6;}  // Last Quarter - 60% -> 45%
        else{return 7;}  // Waning Crescent - 43% -> 12%
    }

    /**
     * @returns - total milliseconds remaining until next conquest update
     */ 
    conquestRemainingTime(){ 
        var now =  new Date();
        //console.log(this.earthDate.getTime(), this.#VTIME_BIRTH);
        return (7 * (24 * 60 * 60 * 1000)) - ((now.getTime() - this.#VTIME_BIRTH) % (7 * (24 * 60 * 60 * 1000)));
    }

    /**
     * @returns - integer - total Vanadiel days remaining on current conquest
     */ 
    conquestRemainingVanaDays(){
        return Math.ceil(this.conquestRemainingTime() / (24 * 60 * 60 * 1000 / 25));
    }

    /**
     * @param time - Vanadiel time, in MILLISECONDS, needing to be converted 
     * @returns {Date} - value as Date() object
     */
    earthTime(time){
        if (time === undefined) time = this.now_inEarthMS();
        //else time = time * 60 * 1000;
        var earthTime = time / ( this.#VMULTIPLIER );
        return new Date(Math.floor(earthTime) - (this.#vanaBirthday - this.#VTIME_BIRTH));
    }


     /**
     * @param time - Vanadiel time, in minutes, needing to be converted
     * @returns - string, formatted 00:00
     */
     stringVanaTime(time){ 
        if (time === undefined || time === null) time = this.now();
        //console.log(time);
        var vYear = this.year(time);
        var vMon  = this.month(time)
        var vDate = this.date(time);
        var vHour = this.hour(time);
        var vMin  = this.mins(time);
        // var vSec  = time.getSeconds();
        // var vDay  = time.getDay();
        //seconds left our because we don't use them for any calcs

        if (vYear < 1000)  vYear = "0" + vYear; 
        if (vMon  < 10) vMon  = "0" + vMon;
        if (vDate  < 10)  vDate  = "0" + vDate;
        if (vHour < 10)  vHour = "0" + vHour; 
        if (vMin  < 10)  vMin  = "0" + vMin; 

        //return vYear + ":" + vMonth + ":" + vDate + " [" + vHour + ":" + vMin + "]" ; // for testing
        return vHour + ":" + vMin; 
    }
    
    /**
     * @param time - Vanadiel time, in milliseconds, needing to be converted
     * @returns - string, formatted 00:00:00
     */
    stringEarthTime(time) {
        var eTime = this.earthTime(time);  
        // const monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
        //Most of these arent needed, left in for future inclusion if needed/wanted
        // var eYear = eTime.getFullYear();
        // var eMon  = monthNames[eTime.getMonth()];
        var eDate = eTime.getDate();
        var eHour = eTime.getHours();
        var eMin  = eTime.getMinutes();
        var eSec  = eTime.getSeconds();
        var eDay  = eTime.getDay();
        
        // Assigns a leading zero if neccessary
        // if (eDate < 10)  eDate = "0" + eDate; 
        if (eHour < 10)  eHour = "0" + eHour; 
        if (eMin < 10)   eMin  = "0" + eMin;  
        if (eSec < 10)   eSec  = "0" + eSec;  

        // var str = eMon + " " + eDate + "," + eHour + ":" + eMin + ":" + eSec;
        var str = eHour + ":" + eMin + ":" + eSec;
        return str;
    }

    /**
     * @param  nextTime - Vana time, in MINUTES, needing to be converted
     * @returns - string of HOURS:MINS
     */
    timeUntil(nextTime){
        if (nextTime === undefined) { return "00:00:00"; }
        else if ( !(nextTime instanceof Date) ) var e = this.earthTime(nextTime); //earth time for next departure
        else e = nextTime;
        
        var now = new Date(); // earth time now
        
        //get difference between the next departure and current time... we want this to be in seconds, and Date()
        //and nextDeparture should be in milliseconds, so we /1000

        var days = (e.getTime() - now.getTime()) / (24 * 60 * 60 * 1000);
        var hours = (days - Math.floor(days)) * 24;
        var minutes = (hours - Math.floor(hours)) * 60;
        var seconds = Math.floor((minutes - Math.floor(minutes)) * 60);

        days = Math.floor(days);
        hours = Math.floor(hours);
        minutes = Math.floor(minutes);
        
        if (hours < 10)  hours = "0" + hours; 
        if (minutes < 10)   minutes  = "0" + minutes;  
        if (seconds < 10)   seconds  = "0" + seconds;  
        
        var str = minutes + ":" + seconds;

        if ( days > 0 ) { str = [days, hours, str].join(':'); }
        else if ( hours > 0 || typeof(hours) == 'string') { str = [hours, str].join(':'); }

        return str;
    }

    timer(time1, time2){
        var seconds = Math.floor((time1.getTime() - time2.getTime()) / 1000); 
                
        //basic math functions to get each element of time separated 
        var minutes = Math.floor(seconds / 60);
        var hours = Math.floor(minutes / 60);
        var days = Math.floor(hours / 24);

        hours = hours-(days * 24);
        minutes = minutes-(days * 24 * 60)-(hours * 60);
        seconds = seconds-(days * 24 * 60 * 60 )-(hours * 60 * 60)-(minutes * 60);

        seconds < 10 ? seconds = "0" + seconds : seconds;
        minutes < 10 ? minutes = "0" + minutes : minutes;
        hours < 10 ? hours = "0" + hours : hours;
        
        var str = hours + ":" + minutes + ":" + seconds;
        if ( days != 0) str = [days, str].join(':');
        return str; 
    }

}
const vanatime = new VanaTime();
////////////////////////////////////////////////////

function pageHasElement(element){
	
    function test(v){
        var i = document.getElementById(v);
        var c = document.getElementsByClassName(v);

        if ( i ) { return true; }
        if ( c[0] ) { return true; }
    }

    if (typeof(element) == 'string') return test(element);
    else { 
        for (const [k,v] of Object.entries(element) ){ 
            if (test(v) == true) return true;
        }
    }
    return false;
}

function updateSidebar() {
    const page_vanatime = document.getElementsByClassName(timeElements.sidebar);
    if ( !page_vanatime) return;

    var hour = vanatime.hour();
    hour < 10 ? hour = ["0", hour].join('') : hour;
    var mins = vanatime.mins();
    mins < 10 ? mins = ["0", mins].join('') : mins;

    var sidebarTime = "<div><li><b>" + hour + ":" + mins + "</b>  ~  " + vanatime.year() + "-" + vanatime.month() + "-" + vanatime.date() + "</li>"; 
	sidebarTime +=	"<li><span style=\"font-weight: bold; font-size:14px; color:" + vanatime.dayColor() + "\" >"  + vanatime.dayLabel() + "</span><span style=\"font-size:14px;\">  ~ " + vanatime.moonPhaseIcon() + vanatime.getMoonPercent() + "%</span></li>"; 
	sidebarTime += "</div>";
	
	for (let i = 0; i < page_vanatime.length; i = i+1) { page_vanatime[i].innerHTML = sidebarTime; }
}

function updateBoatSchedule()  {

    if (!pageHasElement(timeElements.boats)) return;
    populateTransportSchedule(timeElements.boats.selbina, schedule.boats.selbina, 3);
    populateTransportSchedule(timeElements.boats.mhaura, schedule.boats.mhaura, 3);
    populateTransportSchedule(timeElements.boats.whitegate, schedule.boats.whitegate, 1);
    populateTransportSchedule(timeElements.boats.nashmau, schedule.boats.nashmau, 1);
    populateTransportSchedule(timeElements.boats.bibiki, schedule.boats.bibiki, 1);
    populateTransportSchedule(timeElements.boats.purgonorgoIsle, schedule.boats.purgonorgoIsle, 1);
    populateTransportSchedule(timeElements.boats.northLanding, schedule.boats.northLanding, 1);
    populateTransportSchedule(timeElements.boats.centralLanding, schedule.boats.centralLanding, 1);
    populateTransportSchedule(timeElements.boats.southLanding, schedule.boats.southLanding, 1);
}

function updateAirshipSchedule(){
    if (!pageHasElement(timeElements.airships)) return;

   populateTransportSchedule(timeElements.airships.jeuno, schedule.airships.jeuno, 1);
   populateTransportSchedule(timeElements.airships.bastok, schedule.airships.bastok, 1);
   populateTransportSchedule(timeElements.airships.sandy, schedule.airships.sandy, 1);
   populateTransportSchedule(timeElements.airships.windy, schedule.airships.windy, 1);
   populateTransportSchedule(timeElements.airships.kazham, schedule.airships.kazham, 1);
}
            


function _transportScheduleHeader(classname){
    var header = "<TABLE CLASS='" + classname + "' WIDTH='450' CELLSPACING='0' CELLPADDING='0'>";
	header += "<TR><TH ALIGN='LEFT'>Destination</TH>";
	//header += "<TH ALIGN='LEFT'>Departure Day</TH>";
	header += "<TH ALIGN='LEFT'>VanaTime</TH>";
    header += "<TH ALIGN='LEFT'>Earth Time</TH>";
	header += "<TH ALIGN='LEFT'>Departs</TH></TR>";
	return header;
}

function _transportScheduleBody(schedule, numberOfEntries){
    var html = "";
    
    function _helper(sched){
        var offset = (sched[1] + sched[3] + sched[4]) * 60  * 1000 / 25;  // VANA MILLISECONDS 
        //console.log("offset: ", offset, vanatime.now_inMS());
        while (offset <  vanatime.now_inMS() ) { 
            offset +=  (sched[2] * 60 * 1000 / 25);
        }
        return offset; // VANA MILLISECONDS
    }

    for( let x=0; x < schedule.length; x++ ){ 
        var offset;
        for( let i=1 ; i <= numberOfEntries; i++ ){ 
            
            if ( i > 1 ) offset +=  (schedule[x][2] * 60 * 1000 / 25); 
            else offset = _helper(schedule[x]);
            
            var earthdepTime = (vanatime.today_inMS() + ( offset * 25 ));
            var vanadepTime = earthdepTime  / ( 60 * 1000);
            //var arrTime = depTime - ( sched[2][4] * 60 * 1000);  /// LEAVE THIS in the event someone wants to add ARRIVAL TIMES to future HTML tables

            html += '<TR><TD>' + schedule[x][0] + '</TD><TD>' + vanatime.stringVanaTime(vanadepTime) + '</TD><TD>' + vanatime.stringEarthTime(earthdepTime) + '</TD><TD>' + vanatime.timeUntil(earthdepTime)  +'</TD></TR>';
        }
    }
    return html;
}

function populateTransportSchedule(classname, schedule, numberOfEntries){
    
    if (numberOfEntries === 'undefined' || numberOfEntries === null) numberOfEntries = 1;
    
    const shipSched = document.getElementById(classname);
	if (shipSched) {
        var _HTMLheader = _transportScheduleHeader(classname);
        var _HTMLbody = this._transportScheduleBody(schedule, numberOfEntries);
        shipSched.innerHTML = _HTMLheader + _HTMLbody + "</TABLE>";
    }
}

function updateGuilds(){
    if (!pageHasElement(timeElements.guilds)) return;

	const page_alchemy_hours = document.getElementById(timeElements.guilds.alchemy);
    if ( page_alchemy_hours ) { page_alchemy_hours.innerHTML = _guildSchedule(schedule.guilds.alchemy);  }

	const page_bonecraft_hours = document.getElementById(timeElements.guilds.boneworking);
	if ( page_bonecraft_hours ) { page_bonecraft_hours.innerHTML = _guildSchedule(schedule.guilds.boneworking);  }
	
	const page_clothcraft_hours = document.getElementById(timeElements.guilds.clothcrafting);
	if ( page_clothcraft_hours ) { page_clothcraft_hours.innerHTML = _guildSchedule(schedule.guilds.clothcrafting);  }

	const page_cooking_hours = document.getElementById(timeElements.guilds.cooking);
	if ( page_cooking_hours ) { page_cooking_hours.innerHTML = _guildSchedule(schedule.guilds.cooking);  }
	
	const page_fishing_hours = document.getElementById(timeElements.guilds.fishing);
	if ( page_fishing_hours ) { page_fishing_hours.innerHTML = _guildSchedule(schedule.guilds.fishing);  }
	
	const page_goldsmithing_hours = document.getElementById(timeElements.guilds.goldsmithing);
	if ( page_goldsmithing_hours ) {  page_goldsmithing_hours.innerHTML = _guildSchedule(schedule.guilds.goldsmithing);  }
	
	const page_leathercraft_hours = document.getElementById(timeElements.guilds.leathercrafting);
	if ( page_leathercraft_hours ) { page_leathercraft_hours.innerHTML = _guildSchedule(schedule.guilds.leathercrafting);  }

	const page_smithing_hours = document.getElementById(timeElements.guilds.smithing);
	if ( page_smithing_hours ) { page_smithing_hours.innerHTML = _guildSchedule(schedule.guilds.smithing); } 
	
	const page_woodworking_hours = document.getElementById(timeElements.guilds.woodworking);
	if ( page_woodworking_hours ) { page_woodworking_hours.innerHTML = _guildSchedule(schedule.guilds.woodworking); } 

    const page_allguilds_hours = document.getElementById(timeElements.guilds.all);
	if ( page_allguilds_hours ) {  
        
        var guildOut = "<TABLE CLASS='"+ timeElements.guilds.all + "' CELLSPACING='0' CELLPADDING='0' border='1px solid black'>";
        guildOut = guildOut + "<TR><TH ALIGN='center' WIDTH=100 >Guild</TH>";
        guildOut = guildOut + "<TH ALIGN='center' WIDTH=175 >Status</TH></TR>";
        guildOut = guildOut + "<TR><TH> Alchemy</TH><td>" +         _guildSchedule(schedule.guilds.alchemy)         + "</td></TR>";
        guildOut = guildOut + "<TR><TH> Blacksmithing</TH><td>" +   _guildSchedule(schedule.guilds.smithing) 	    + "</td></TR>";
        guildOut = guildOut + "<TR><TH> Boneworking</TH><td>" +     _guildSchedule(schedule.guilds.boneworking) 	+ "</td></TR>";
        guildOut = guildOut + "<TR><TH> Goldsmithing</TH><td>" +    _guildSchedule(schedule.guilds.goldsmithing) 	+ "</td></TR>";
        guildOut = guildOut + "<TR><TH> Clothcrafting</TH><td>" +   _guildSchedule(schedule.guilds.clothcrafting) 	+ "</td></TR>";
        guildOut = guildOut + "<TR><TH> Woodworking</TH><td>" +     _guildSchedule(schedule.guilds.woodworking) 	+ "</td></TR>";
        guildOut = guildOut + "<TR><TH> Leatherworking </TH><td>" + _guildSchedule(schedule.guilds.leathercrafting) + "</td></TR>";
        guildOut = guildOut + "<TR><TH> Fishing</TH><td>" +         _guildSchedule(schedule.guilds.fishing) 	    + "</td></TR>";
        guildOut = guildOut + "<TR><TH> Cooking</TH><td>" +         _guildSchedule(schedule.guilds.cooking) 	    + "</td></TR>";
        guildOut = guildOut + "</TABLE>";
    
        page_allguilds_hours.innerHTML = guildOut; 
    } 
}

function _guildSchedule(guild) {
    if (guild === 'undefined') return "_guildSchedule: error";

    var now = vanatime.now_inMS();
    var guildOpens = guild[0] * 60 * 1000 / 25;
    var guildCloses = guild[1] * 60 * 1000 / 25;

    // Guild open/close check
    var nextOpenTime = 0;
    var outputTxt1 = "", outputTxt2 = "";
    if (guildOpens >= now) {
        nextOpenTime = (((guildOpens - now) * 25) + vanatime.now_inEarthMS());
        outputTxt2 = "Currently Closed. Open tomorrow.";
        outputTxt1 = "Opens in: ";
    } else if ((guildOpens < now) && (guildCloses > now)) {
        nextOpenTime = (((guildCloses - now) * 25) + vanatime.now_inEarthMS());
        outputTxt2 = "Currently Open for business.";
        outputTxt1 = "Closes in: ";
    } else if (guildCloses <= now)  {
        nextOpenTime = ((24 * 60 * 60 * 1000 / 25) - now ) + (guildOpens * 25) + vanatime.now_inEarthMS();
        outputTxt2 = "Currently Closed. Open tomorrow.";
        outputTxt1 = "Opens in: "; 
    }
    

    // Holiday check 
    if ((guild[2] == vanatime.weekDay()) && (guildCloses > now)) {
        nextOpenTime = ((24 * 60 * 60 * 1000 / 25)  - now + guildOpens) * 25 + vanatime.now_inEarthMS();
        outputTxt2 = "Currently Closed for Guild Holiday.";
        outputTxt1 = "Opens in: ";
    } else if (((vanatime.weekDay() + 1) == guild[2]) && (guildCloses <= now))  {
        nextOpenTime = ((24 * 60 * 60 * 1000 / 25)  - now) + (guildOpens * 25) + (24 * 60 * 60 * 1000 / 25) + vanatime.now_inEarthMS();
        outputTxt2 = "Currently Closed. Guild Holiday tomorrow.";
        outputTxt1 = "Opens in: ";
    }
    
    return outputTxt1 + vanatime.timeUntil(nextOpenTime) + ". " + outputTxt2;

}

function updateConquest()  {
    if (!pageHasElement(timeElements.conquest)) return;
    
    function stringNextConquest(remaining){
        //if (nextConquest === undefined) { return "stringConquestTimer: timer undefined"; }
        const now = new Date();
        remaining = now.getTime() + remaining;

        var nextConquest = new Date(remaining);
        var tempHour = nextConquest.getHours();
        var tempMin  = nextConquest.getMinutes();
        var tempSec  = nextConquest.getSeconds();

        if (tempHour < 10)  tempHour = "0" + tempHour; 
        if (tempMin < 10)   tempMin  = "0" + tempMin;  
        if (tempSec < 10)   tempSec  = "0" + tempSec;  

        var strNextConquest = nextConquest.toDateString() + " " + tempHour + ":" + tempMin + ":" + tempSec;

            // var remaining = (temp.getTime() - now.getTime()) / (24 * 60 * 60 * 1000);
            // var hours = (remaining - Math.floor(remaining)) * 24;
            // var mins = (hours - Math.floor(hours)) * 60;
            // var secs = Math.floor((mins - Math.floor(mins)) * 60);

            // remaining = Math.floor(remaining);
            // hours = Math.floor(hours);
            // mins = Math.floor(mins);

            // if (hours < 10)  hours = "0" + hours; 
            // if (mins < 10)   mins  = "0" + mins;  
            // if (secs < 10)   secs  = "0" + secs;  

            // // tempDays < 10 ? ["0", tempDays].join(':') : tempDays;
            // // tempDays > 0 ? [tempDays, strTimer].join(':') : null;

            // strDiff = hours + ":" + mins + ":" + secs;

        //return strNextConquest + "(" + strDiff + ")";
        return strNextConquest + "(" + vanatime.timeUntil(nextConquest) + ")";
    }
    
    const now = new Date();
    var remaining = vanatime.conquestRemainingTime();
    remainingVanaDaysOnConquest = vanatime.conquestRemainingVanaDays();
    
    conq = remainingVanaDaysOnConquest + ' Vana´diel Days <BR>';
    conq += stringNextConquest(remaining); //+ ' (' + timer.getHours() + ":" + timer.getMinutes() + ":" + timer.getSeconds() + ')';

    const conquest_time = document.getElementById(timeElements.conquest);
    if (conquest_time) conquest_time.innerHTML = conq; 
}

function updateMoonPhaseSchedule(){
    if (!pageHasElement(timeElements.moonSchedule)) return;

    populateMoonPhaseSchedule(timeElements.moonSchedule, 7);
}

function _moonPhaseScheduleHeader(classname){
    var header = "<TABLE CLASS='" + classname + "' WIDTH='500' CELLSPACING='0' CELLPADDING='0'>";
	header += "<TR><TH ALIGN='LEFT'>Moon Phase</TH>";
	header += "<TH ALIGN='LEFT'>Start Time</TH>";
	header += "<TH ALIGN='LEFT'>End Time</TH>";
    //header += "<TH ALIGN='LEFT'>Phase Ends in...</TH>";
    header += "</TR>";
	return header;
}

function _moonPhaseScheduleBody(numberOfEntries){
    var html = "";
    
    if ( numberOfEntries === undefined || numberOfEntries === null ) numberOfEntries = 7;
        var vTempTime = vanatime.today_inMS() / (60 * 1000); // VANA TIME IN TOTAL MINUTES
        var thisMoonPhase = vanatime.moonLatentPhase(vTempTime); 

        var lunarOffset = 0;
        for(var x = 0 ; x < numberOfEntries; x++ ){

            if ( x > 0 ){
                if (thisMoonPhase > 7) thisMoonPhase = 0;
                if ( thisMoonPhase == 1 || thisMoonPhase == 3 || thisMoonPhase == 5 || thisMoonPhase == 7) lunarOffset += 14;
                else lunarOffset += 7;
                thisMoonPhase++;
            }

            var phaseStartTime;
            for( var i = 1 ; i >= -13 ; i-- ) {
                var _time = vTempTime + (60 * 24 * lunarOffset) + (60 * 24 * (i - 1)); // VANA MINUTES
            //console.log("s", thisMoonPhase, lunarOffset, vanatime.moonLatentPhase(_time));
                if ( vanatime.moonLatentPhase(_time) != thisMoonPhase ) break;
                else phaseStartTime = _time * 60; // VANA SECONDS
            }

            var phaseEndTime; 
            for( var i = -1 ; i <= 14 ; i++ ) {
                var _time = vTempTime + (60 * 24 * lunarOffset) + (60 * 24 * (i + 1));// VANA MINUTES
            //console.log("e", thisMoonPhase,lunarOffset,vanatime.moonLatentPhase(_time));
                if ( vanatime.moonLatentPhase(_time) != thisMoonPhase ) break;
                else phaseEndTime = (_time + (60 * 24)) * 60; // VANA SECONDS
                // for loop breaks when _time is at 00:00 for the day the moon phase changes... 
                // we add another day to this (60 + 24) to get the start of the next day for the table
            } 

            const startDate = new Date(Math.floor(phaseStartTime / (25 / 1000)) - vanatime.getDifference() );
            const endDate = new Date(Math.floor(phaseEndTime / (25 / 1000)) - vanatime.getDifference() );

            var strDetails = vanatime.moonPhaseIcon(thisMoonPhase) + " " + vanatime.moonPhaseName(thisMoonPhase) + " " + vanatime.moonPhasePercentages(thisMoonPhase);            

            function dateString(date){
                var sec = date.getSeconds(), hrs = date.getHours(), mins = date.getMinutes(); 
                sec < 10 ? sec = "0" + sec : sec;
                hrs < 10 ? hrs = "0" + hrs : hrs;
                mins < 10 ? mins = "0" + mins : mins;
                return vanatime.weekdayLabel(date.getDay()) + ", " + date.getDate() + " " + vanatime.monthLabel(date.getMonth()) + " " + hrs + ":" + mins + ":" + sec;
            }

            html += '<TR><TD>' + strDetails + '</TD><TD>' + dateString(startDate) + '</TD><TD>' + dateString(endDate)  + '</TD>';

            // const now = new Date();
            // var strTimer = vanatime.timer(endDate, now);
            // html += '<TD>' + strTimer + '</TD>';

            html += '</TR>';
        }
    return html;
}

function populateMoonPhaseSchedule(classname, numberOfEntries){
    
    if (numberOfEntries === undefined || numberOfEntries === null) numberOfEntries = 7;
    
    const moonSchedule = document.getElementById(classname);
    if (moonSchedule) {
        var _HTMLheader = this._moonPhaseScheduleHeader(classname);
        var _HTMLbody = this._moonPhaseScheduleBody(numberOfEntries);
        moonSchedule.innerHTML = _HTMLheader + _HTMLbody + "</TABLE>";
    }
}


function updateRSE()  {
    if (!pageHasElement(timeElements.rseSchedule)) return;
        function formatDate(varTime, showDay) {

            var varDate = new Date(varTime);
            var yyyy = varDate.getYear();
        
            var mm = varDate.getMonth() + 1;
            if (mm < 10) { mm = "0" + mm; }
        
            var dd = varDate.getDate();
            if (dd < 10) { dd = "0" + dd; }
        
            var day = varDate.getDay();
        
            var hh = varDate.getHours();
            
            if (hh < 10) { hh = "0" + hh; }
        
            var min = varDate.getMinutes();
            if (min < 10) { min = "0" + min; }
        
            var ss = varDate.getSeconds();
            if (ss < 10) { ss = "0" + ss; }
            if (showDay == 1)  {
            dateString = vanatime.weekdayLabel(day) + ", " + vanatime.monthLabel(mm-1) + ' ' + dd + ', ' + yyyy + " " + hh + ":" + min + ":" + ss;
            } else if (showDay == 2)  {
            dateString = vanatime.monthLabel(mm-1) + " " + dd + ",  " + hh + ":" + min + ":" + ss;
            }
            return dateString;
        }
     
    var timenow = new Date();
    var localtime = timenow.getTime();

    var repeatCal = 10;
    var race = 8;
 
    if (race > 7) {
       RSECal = "<TABLE CLASS=\'" + timeElements.rseSchedule + "\' WIDTH='500' CELLSPACING='0' CELLPADDING='0'><TR><TH ALIGN='LEFT'>Date & Time</TH><TH ALIGN='LEFT'>Race</TH><TH ALIGN='LEFT'>Location</TH></TR>"
       for ( i = 0; i < repeatCal; i++) {
          elapsedWeeks = Math.floor( (localtime - vanatime.rseDate) / (8 * (24 * 60 * 60 * 1000 / 25)) ) + i;
          RSEstart = vanatime.rseDate + (elapsedWeeks * 8 * (24 * 60 * 60 * 1000 / 25));
          RSECal = RSECal + "<TR><TD>" + formatDate(RSEstart,2) + '</TD><TD>' + vanatime.rseRace(elapsedWeeks % 8) + '</TD><TD>';
          //RSECal = RSECal + "<A HREF=#  onmousedown='javascript:getRSEDetails(" + (elapsedWeeks % 3) + ")'>";
          RSECal = RSECal + vanatime.rseLocation(elapsedWeeks % 3);
          RSECal = RSECal + '</A></TD></TR>';
       }
      if (repeatCal < 1) { RSECal = ""; } else { RSECal = RSECal + '</TABLE>'; }
    } 
    // else {
    //    RSECal = "<TABLE CLASS='blank' CELLPADDING='0' CELLSPACING='0'><TR><TH WIDTH='120' ALIGN='LEFT'>Start</TH><TH WIDTH='120' ALIGN='LEFT'>End</TH><TH WIDTH='60' ALIGN='LEFT'>Location</TH></TR>"
    //    offsetTime = race * 8 * msGameDay;
 
    //    for ( i = 0; i < repeatCal; i++) {
    //       elapsedWeeks = Math.floor( (localtime - vanatime.rseDate) / (64 * msGameDay) ) + i;
          
    //       elapsedLocationWeeks = Math.floor( (localtime - vanatime.rseDate) / (8 * msGameDay) ) + (8 * i);
    //       raceOffset = race - (elapsedLocationWeeks % 8);
    //       elapsedLocationWeeks = elapsedLocationWeeks + raceOffset;
 
    //       RSEstart = vanatime.rseDate + (elapsedWeeks * 64 * msGameDay) + offsetTime ;
    //       RSEend = RSEstart + (8 * msGameDay);
    //       RSECal = RSECal + "<TR><TD>" + formatDate(RSEstart,2) + "</TD><TD>" + formatDate(RSEend,2) + "</TD><TD>";
    //       //RSECal = RSECal + "<A HREF=#  onmousedown='javascript:getRSEDetails(" + (elapsedLocationWeeks % 3) + ")'>";
    //       RSECal = RSECal + RSEloc[(elapsedLocationWeeks) % 3] 
    //       RSECal = RSECal + "</A></TD></TR>";
    //    }
    //   if (repeatCal < 1) { RSECal = ""; } else { RSECal = RSECal + '</TABLE>'; }
 
    // }
 
    document.getElementById(timeElements.rseSchedule).innerHTML = RSECal;
 
 }

function gametick(){
    
    updateSidebar();
    updateAirshipSchedule();
    updateBoatSchedule();
    updateGuilds();
	updateConquest();
    updateMoonPhaseSchedule();
    updateRSE();

	setTimeout("gametick()", 500);
}

gametick();