User:Charitest/monaco.js

// Usage:  Functions to calculate and format timing data for FFXI // Written by:  Pyogenes from www.pyogenes.com

/////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// //                                                              // //    CODE IS FREE FOR USE AS LONG AS YOU GIVE CREDIT            // //   1.  List my website as the source                          // //   2.  Place a link on the page the code is used in           // //                                                              // /////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////

// basis date is used to convert real time to game time. // Use UTC functions to allow calculations to work for any timezone basisDate = new Date; basisDate.setUTCFullYear(2002, 5, 23); // Set date to 2003-06-23 basisDate.setUTCHours(15, 0, 0, 0);   // Set time to 15:00:00.0000

// moon date is used to determien the current hase of the moon. // Use UTC functions to allow calculations to work for any timezone 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

// basis date for RSE calculations RSEdate = new Date; RSEdate.setUTCFullYear(2004, 0, 28); // Set date to 2004-01-28 RSEdate.setUTCHours(9, 14, 24, 0);   // Set time to 09:14:24.0000

// basis date for day of week calculations Daydate = new Date; Daydate.setUTCFullYear(2004, 0, 28); // Set date to 2004-01-28 Daydate.setUTCHours(9, 14, 24, 0);   // Set time to 09:14:24.0000

EarthDay = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); VanaDay = new Array("Firesday", "Earthsday", "Watersday", "Windsday", "Iceday", "Lightningday", "Lightsday", "Darksday"); DayColor = new Array("#DD000", "#AAAA00", "#0000DD", "#00AA22", "#7799FF", "#AA00AA", "#AAAAAA", "#333333"); weakMagic = new Array("Ice","Lightning","Fire","Earth","Wind","Water","Darkness","Light"); weakColor = new Array("#7799FF", "#AA00AA", "#DD000", "#AAAA00", "#00AA22", "#0000DD", "#333333", "#AAAAAA"); PhaseName = new Array("Full Moon","Waning Gibbous","Last Quarter","Waning Crescent","New Moon","Waxing Crescent","First Quarter","Waxing Gibbous");

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 = new Array("08:00", "16:00", "00:00"); BoatSched2 = new Array("06:30", "14:30", "22:30"); BoatDayOffset = new Array(0,0,7);

msGameDay	= (24 * 60 * 60 * 1000 / 25); // milliseconds in a game day msRealDay	= (24 * 60 * 60 * 1000); // milliseconds in a real day

balJug = new Array("","Entry ","Match ","Closing Ceremony ","",""); balPas = new Array("", "", "", "Entry ","Match ","Closing Ceremony "); balMer = new Array("Match ","Closing Ceremony ", "", "", "", "Entry "); balJugTeam = new Array("San D'oria vs Bastok", "Bastok vs Windurst", "San D'oria vs Windurst"); balPasTeam = new Array("Bastok vs Windurst", "San D'oria vs Windurst", "San D'oria vs Bastok"); balMerTeam = new Array("San D'oria vs Windurst", "San D'oria vs Bastok", "Bastok vs Windurst");

//************** // Functions ** //**************

function getVanadielTime {

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; }

VanaTime = "" + VanaDay[vDay] + ": " VanaTime += VanaYear + "-" + VanaMon + "-" + VanaDate + " " + VanaHour + ":" + VanaMin + ":" + VanaSec + "";

document.getElementById("vTime").innerHTML = VanaTime; getBallistaSummary(vDate, vMon); }

function getBallistaSummary(vDate, vMon) { out = ""; for ( i = 0; i < 3; i++) { vDate = vDate + 1; if (vDate > 30) { vDate = 1; vMon = vMon + 1; }

if (vDate <= 6) { balLimit = "30"; } else if (vDate <=12) { balLimit = "40"; } else if (vDate <=18) { balLimit = "50"; } else if (vDate <=24) { balLimit = "60"; } else if (vDate <=30) { balLimit = "None"; }

balTeam = Math.floor((vMon - 1) / 4); balJugner = balJug[vDate % 6]; if (balJugner != "") { balJugner = "Jugner Forest: " + balJugner + "for " + balJugTeam[balTeam] + " with a level cap of: " + balLimit + ""; }     balPashhow = balPas[vDate % 6]; if (balPashhow != "") { balPashhow = "Pashhow Marshlands: " + balPashhow + "for " + balPasTeam[balTeam] + " with a level cap of: " + balLimit + ""; }     balMeriph = balMer[vDate % 6]; if (balMeriph != "") { balMeriph = "Meriphataud Mountains: " + balMeriph + "for " + balMerTeam[balTeam] + " with a level cap of: " + balLimit + ""; }     out = out + balJugner + balPashhow + balMeriph + ""; }

}

function dayDetails(firstDay) {

out = ' ' document.getElementById("Details").innerHTML = out;

}

function clearDetails {

document.getElementById("Details").innerHTML = '';

}

function getEarthTime {

var now = new Date; earthTime = formatDate(now.getTime, 1); document.getElementById("eTime").innerHTML = earthTime;

}

function getConquest {

var now = new Date; var timeLeft = (7 * msRealDay) - ((now.getTime - basisDate.getTime) % (7 * msRealDay)); vanaConq = Math.floor(timeLeft / (msGameDay)) + 1;

conqDays = timeLeft / msRealDay; conqHours = (conqDays - Math.floor(conqDays)) * 24; 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); } 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 ' + conqDate + ' (' + formatCountdown(timeLeft) + ')'; document.getElementById("conquest").innerHTML = conq; }

function getRSE { var timenow = new Date; var localtime = timenow.getTime; var RSEtime = RSEdate.getTime; var repeatCal = document.Timer.RSE.value; var race = document.Timer.RSErace.value;

if (race > 7) { RSECal = " '; }  } else {      RSECal = " '; }

}

document.getElementById("rCal").innerHTML = RSECal;

}

function getRSEDetails(varLocation) {

if (varLocation == 0) { output = " ";

} else if (varLocation == 1) { output = " ";

} else if (varLocation == 2) { output = " ";

}

document.getElementById("Details").innerHTML = output; }

function getMoonPhase {

var timenow = new Date; var localTime = timenow.getTime; var moonDays = (Math.floor((localTime - Mndate.getTime) / msGameDay)) % 84;

var mnElapsedTime = (localTime - Mndate.getTime) % msGameDay;

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

} else if (moonpercent >= 90)  { mnPhase = 0; optPhase = 4; toNextPhase = (87 - moonDays) * msGameDay - mnElapsedTime; toOptimalPhase = (38 + 84 - moonDays) * msGameDay - mnElapsedTime;

} else if (moonpercent >= -93 && moonpercent <= -62)  { mnPhase = 1; optPhase = 4; toNextPhase = (17 - moonDays) * msGameDay - mnElapsedTime; toOptimalPhase = (38 - moonDays) * msGameDay - mnElapsedTime;

} else if (moonpercent >= -61 && moonpercent <= -41)  { mnPhase = 2; optPhase = 4; 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 = "" + mnpercent+ ""; } else if (moonpercent >= 90 || moonpercent <= -95) { mnpercent = "" + mnpercent+ ""; }

nextPhase = "Next phase (" + PhaseName[(mnPhase + 1) % 8] + "): " + formatCountdown(toNextPhase); nextOptPhase = "Next " + PhaseName[optPhase] + ": " + formatCountdown(toOptimalPhase);

mnpercent = "" + mnpercent + " "; document.getElementById("mPhase").innerHTML = mnpercent + nextPhase + "" + 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 = document.Timer.Moon.value;

moonCal = " '; }  document.getElementById("mCalendar").innerHTML = moonCal;

}

function getMoonDetails {

out = "Moon Information:"; out = out + "<BR>Each lunar cycle takes exactly 84 game days (3 days, 8 hours, 38 minutes, 24 seconds)"; document.getElementById("Details").innerHTML = out;

}

function getShipSched {

// Boats depart at 00:00, 08:00, 16:00 from both Selbina and Mhuara // Boats arrive at 06:30, 14:30, 22:30 which is 216 seconds before they leave 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 = document.Timer.FerryCount.value;

bSched = " "; } document.getElementById("ferry").innerHTML = out;

}

function getAirSched {

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 var offset2 = ((2 * 60) + 40) * 60 * 1000 / 25; // 2:40 offset used by J->W K-J 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

outAir = ""; outAir += " "; document.getElementById("Airship").innerHTML = outAir; }

function AirHelper(elapsed, offset, day, city) {

var newOffset = offset; var count = 0; while (newOffset < elapsed) { count += 1; newOffset += (msGameDay / 4); }   if (count >= 4) { day = (day + 1) % 8; }  output = "<TR><TD>" + city + "</TD>"; output += "<TD>" + VanaDay[day] + "</FONT></TD>"; arrivalTime = newOffset - elapsed - 144000; if (arrivalTime < 0) { arrivalTime = 0; }  output += "<TD>" + formatCountdown(arrivalTime,1) + "</TD>"; output += "<TD>" + formatCountdown(newOffset - elapsed,1) + "</TD></TR>"; return output; }

function getDaySched {

var now = new Date; var timeDiff = now.getTime - Mndate.getTime; var weekStart = now.getTime - (timeDiff % (8 * msGameDay));

var repeatCal = document.Timer.DayCount.value; var dayOffset = document.Timer.Day.value; var out = " "; } document.getElementById("days").innerHTML = out; }

function getGuildHours { alchemy = guildHelper(8, 23, 6); blacksmith = guildHelper(8, 23, 2); bonework = guildHelper(8, 23, 3); goldsmith = guildHelper(8, 23, 4); cloth = guildHelper(6, 21, 0); wood = guildHelper(6, 21, 0); leather = guildHelper(3, 18, 4); fishing = guildHelper(3, 18, 5); cooking = guildHelper(5, 20, 7);

guildOut = " "; document.getElementById("Guilds").innerHTML = guildOut;

}

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; close = close * convFactor; openTime = open + dayStart; closeTime = close + dayStart; outputTxt = ""; guildCountdown = 0; if (openTime >= localTime) { guildCountdown = openTime - localTime; outputTxt2 = "</TD><TD>Closed.</FONT> Open tomorrow.</TD>"; outputTxt1 = "<TD>Opens in:</TD><TD>"; } else if ((openTime < localTime) && (closeTime > localTime)) { guildCountdown = closeTime - localTime; outputTxt2 = "</TD><TD>Open</FONT> for business</TD>"; outputTxt1 = "<TD>Closes in:</TD><TD>"; } else if (closeTime <= localTime) { guildCountdown = (msGameDay - elapsedTime) + open; outputTxt2 = "</TD><TD>Closed.</FONT> Open tomorrow.</TD>"; outputTxt1 = "<TD>Opens in:</TD><TD>"; }  // adjust for holiday if ((holiday == vDay) && (closeTime > localTime)) { guildCountdown = (msGameDay - elapsedTime) + open; outputTxt2 = "</TD><TD>Closed</FONT> for Holiday</TD>"; outputTxt1 = "<TD>Opens in:</TD><TD>"; } else if (((vDay + 1) == holiday) && (closeTime <= localTime)) { guildCountdown = (msGameDay - elapsedTime) + open + msGameDay; outputTxt2 = "</TD><TD>Closed.</FONT> Holiday tomorrow</TD>"; outputTxt1 = "<TD>Opens in:</TD><TD>"; }

return outputTxt1 + formatCountdown(guildCountdown) + outputTxt2; }

function guildDetail(guild) {

switch(guild) { case 1: out = "Alchemist´s guild <BR>Location: Bastok Mines<BR>Holiday:  Lightsday<BR>Hours:  8:00-23:00"; break case 2: out = "Blacksmith´s guild <BR>Location: Bastok Metalworks, Northern San d´Oria<BR>Holiday:  Watersday<BR>Hours:  8:00-23:00"; break case 3: out = "Boneworker´s guild <BR>Location: Windurst Woods<BR>Holiday:  Windsday<BR>Hours:  8:00-23:00"; break case 4: out = "Goldsmith´s guild <BR>Location: Bastok Market<BR>Holiday:  Iceday<BR>Hours:  8:00-23:00"; break case 5: out = "Weaver´s guild <BR>Location: Windurst Woods<BR>Holiday:  Firesday<BR>Hours:  6:00-21:00"; break case 6: out = "Carpenter´s guild <BR>Location:  Northern San d´Oria<BR>Holiday:  Firesday<BR>Hours:  6:00-21:00"; break case 7: out = "Leatherworker´s guild <BR>Location:  Southern San d´Oria<BR>Holiday:  Iceday<BR>Hours:  3:00-18:00"; break case 8: out = "Fisherman´s guild <BR>Location:  Port Windurst<BR>Holiday:  Lightningday<BR>Hours:  3:00-18:00"; break case 9: out = "Culinary guild <BR>Location:  Windurst Waters<BR>Holiday:  Darksday<BR>Hours:  5:00-20:00"; }  document.getElementById("Details").innerHTML = out; }

function formatCountdown(varTime) {

var dayLeft = varTime / msRealDay; var hourLeft = (dayLeft - Math.floor(dayLeft)) * 24; var minLeft = (hourLeft - Math.floor(hourLeft)) * 60; var secLeft = Math.floor((minLeft - Math.floor(minLeft)) * 60); var formattedTime = '';

dayLeft = Math.floor(dayLeft); hourLeft = Math.floor(hourLeft); minLeft = Math.floor(minLeft);

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 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 = 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 printVanaPage { getVanadielTime; getEarthTime; getMoonPhase; getRSE; getConquest; getShipSched; getDaySched; getGuildHours; getAirSched; setTimeout("printPage", 50); }

printVanaPage;

// Embed Vana'dial Clock //function escapeVanaString(str){ // return str.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"); //} //function GetVanaTime{ // var blip_elements = getElementsByClassName(document.getElementById('bodyContent'),'div','vana_time'); // for(var i = 0; i < blip_elements.length; i++){ //  blip_elements[i].innerHTML = "<iframe src='"+ escapeVanaString(blip_elements[i].firstChild.href) +"' scrolling='no' height='550px' //width='550px' frameBorder='0'> "; // } //} //GetVanaTime;