﻿// JScript File for World Time
var clockID = 0;
var timezone = 0;
var offset = "";
var tzoffset = "";
var entries = 65;
var criteria = "";
var zone = new MakeArray(entries);

function MakeArray(n) {
   for (var i = 1; i <= n; i++) { this[i] = 0; }
   this.maxlen = n; this.len = 0; return this;
}

function addZone(zonename, timediff) {
  this.name = zonename; this.time = timediff;
}

function Add(name, time) {
  zone.len++; zone[zone.len] = new addZone(name, time);
}

/////////////////////////////////////////////////////////////////////////////
// Add Details for each timezone.
// ie. Add("Timezone Name", "Time Difference");

Add("Alaska", "-9.00");
Add("Arizona - US Mountain", "-7.00");
Add("Azores", "-1.00");
Add("Amsterdam - Romance", "+1.00");
Add("Athens - GFT ", "+2.00");
Add("Abu Dhabi - Arabian", "+4.00");
Add("Afghanistan - Kabul", "+4.50");
Add("Almaty - Central Asia", "+6.00");
Add("Adelaide - Cen. Australia", "+9.50");
Add("Auckland", "+12.00");
Add("Bogota - SA Pacific", "-5.00");
Add("Brasilia - E. South America", "-3.00");
Add("Buenos Aires - SA Eastern", "-3.00");
Add("Belgrade - Central European", "+1.00");
Add("Bratislava - Central Europe", "+1.00");
Add("Budapest - Central Europe", "+1.00");
Add("Brussels - W. Europe", "+1.00");
Add("Berlin - W. Europe", "+1.00");
Add("Bern - W. Europe", "+1.00");
Add("Bucharest - E. Europe", "+2.00");
Add("Baghdad - Saudi Arabia", "+3.00");
Add("Baku - Caucasus", "+4.00");
Add("Bombay - India", "+5.50");
Add("Bangkok", "+7.00");
Add("Brisbane - E. Australia", "+10.00");
Add("Beijing - China", "+8.00");
Add("Canada - Pacific Time", "-8.00");
Add("Canada - Mountain Time", "-7.00");
Add("Canada - Central Time", "-6.00");
Add("Canada - Eastern Time", "-5.00");
Add("Canada - Atlantic Time", "-4.00");
Add("Caracas - SA Western", "-4.00");
Add("Cape Verde Is.", "-1.00");
Add("Casablanca", "+0.00");
Add("Copenhagen - Romance", "+1.00");
Add("Cairo", "+2.00");
Add("Calcutta - India", "+5.50");
Add("Chongqing - China", "+8.00");
Add("Canberra", "+10.00");
Add("Dublin", "+0.00");
Add("Dhaka - Central Asia", "+6.00");
Add("Darwin - AUS Central", "+9.50");
Add("Eniwetok - Dateline", "-12.00");
Add("Edinburgh", "+0.00");
Add("Egypt", "+2.00");
Add("Ekaterinburg", "+5.00");
Add("Fiji", "+12.00");
Add("Georgetown - SA Eastern", "-3.00");
Add("Guam - West Pacific", "+10.00");
Add("Hanoi", "+7.00");
Add("Hong Kong - China", "+8.00");
Add("Hawaii", "-10.00");
Add("Harare - South Africa", "+2.00");
Add("Helsinki - FLE", "+2.00");
Add("Israel", "+2.00");
Add("Islamabad - West Asia", "+5.00");
Add("Iran", "+3.50");
Add("Istanbul - GFT ", "+2.00");
Add("Indiana (East) - US Eastern", "-5.00");
Add("Jakarta", "+7.00");
Add("Kwajalein - Dateline", "-12.00");
Add("Karachi - West Asia", "+5.00");
Add("Korea - Seoul", "+9.00");
Add("Kamchatka", "+12.00");
Add("Kuwait - Saudi Arabia", "+3.00");
Add("Lima - SA Pacific", "-5.00");
Add("La Paz - SA Western", "-4.00");
Add("Lisbon", "+0.00");
Add("London", "+0.00");
Add("Ljubljana - Central Europe", "+1.00");
Add("Mexico City", "-6.00");
Add("Mid-Atlantic", "-2.00");
Add("Marshall Is.", "+12.00");
Add("Melbourne", "+10.00");
Add("Magadan - Central Pacific", "+11.00");
Add("Monrovia", "+0.00");
Add("Madrid - Romance", "+1.00");
Add("Minsk - GFT ", "+2.00");
Add("Moscow - Russian", "+3.00");
Add("Muscat - Arabian", "+4.00");
Add("Madras - India", "+5.50");
Add("Newfoundland", "-3.50");
Add("Nairobi - E. Africa", "+3.00");
Add("New Delhi - India", "+5.50");
Add("New Caledonia - Central Pacific", "+11.00");
Add("New Zealand ", "+12.00");
Add("Paris - Romance", "+1.00");
Add("Prague - Central Europe", "+1.00");
Add("Pretoria - South Africa", "+2.00");
Add("Perth - W. Australia", "+8.00");
Add("Port Moresby - West Pacific", "+10.00");
Add("Quito - SA Pacific", "-5.00");
Add("Rome - W. Europe", "+1.00");
Add("Riga - FLE", "+2.00");
Add("Riyadh - Saudi Arabia", "+3.00");
Add("Samoa - Midway Island", "-11.00");
Add("Saskatchewan - Canada Central ", "-6.00");
Add("Sarajevo - Central European", "+1.00");
Add("Skopje - Central European", "+1.00");
Add("Sofija - Central European", "+1.00");
Add("Stockholm - W. Europe", "+1.00");
Add("St. Petersburg - Russian", "+3.00");
Add("Sri Lanka - Colombo", "+6.00");
Add("Singapore", "+8.00");
Add("Sydney", "+10.00");
Add("Solomon Is. - Central Pacific", "+11.00");
Add("Tallinn - FLE", "+2.00");
Add("Tehran", "+3.50");
Add("Tbilisi - Caucasus", "+4.00");
Add("Tashkent - West Asia", "+5.00");
Add("Taipei", "+8.00");
Add("Tokyo - Osaka, Sapporo", "+9.00");
Add("Tasmania - Hobart", "+10.00");
Add("Tijuana", "-8.00");
Add("Tegucigalpa", "-6.00");
Add("US - Pacific Time", "-8.00");
Add("US - Mountain Time", "-7.00");
Add("US - Central Time", "-6.00");
Add("US - Eastern Time", "-5.00");
Add("Urumqi - China", "+8.00");
Add("Vladivostok", "+10.00");
Add("Volgograd - Russian", "+3.00");
Add("Vienna - W. Europe", "+1.00");
Add("Vilnius - Romance", "+1.00");
Add("Wellington", "+12.00");
Add("Warsaw - Central Europe", "+1.00"); 
Add("Yakutsk", "+9.00");
Add("Zagreb - Central European", "+1.00");

// End of timezone entries.
/////////////////////////////////////////////////////////////////////////////

function searchTimeZone() {
   var doc = document.forms['clock'];
   document.getElementById('timezone').selectedIndex = 0;
   document.getElementById('date').value = "";
   document.getElementById('time').value = "";
   KillClock();
   criteria = prompt("Enter the time zone you are looking for?", criteria);
   if (criteria) criteria = criteria.toLowerCase();
   zonefound = 0;
   for (i=1; i<=zone.len; i++) {
      zonefind = zone[i].name.toLowerCase();
      if (zonefind.indexOf(criteria) >= 0 && (!zonefound) && (criteria)) {
         document.getElementById('timezone').selectedIndex = i;
         timezone = parseFloat(zone[i].time);
         StartClock();
         zonefound++;
      }
   }
   if (!zonefound && (criteria)) {
      alert("Unable to find the specified time zone.");
      setTimeout("searchTimeZone()", 200);
   }
}

function changeTimeZone(tz) {
   
   var doc = document.forms['clock'];    
   var newzone = document.getElementById('timezone').options[document.getElementById('timezone').selectedIndex].text   
   KillClock();    
   if (!document.getElementById('timezone').selectedIndex) {
       KillClock();
       document.getElementById('date').value = "";
       document.getElementById('time').value = "";
   }else{
       newzone = zone[document.getElementById('timezone').selectedIndex].name;
       timezone = parseFloat(tz);
       StartClock();
   }
}

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
   var tDate = new Date();
   tDate.setTime(tDate.getTime() + (timezone * 3600000)); tDate.toGMTString();
   newtime = tDate.toGMTString(); newtime = newtime.substring(0,25);
   ndate = newtime.substring(0,16); ntime = newtime.substring(17,19);
   otime = newtime.substring(19); ohour = parseInt(ntime.substring(0,2));
   ampm = (parseInt(ohour) < 12) ? " AM" : " PM";
   nhour = (parseInt(ntime) >= 13) ? "" + (parseInt(ntime) - 12) + "" : ntime;
   if(ntime == "00" || ntime == "0") { nhour = "12"; }
   if (nhour.substring(0,1) == "0") nhour = nhour.substring(1,2);
   if (nhour.length == 1) nhour = " " + nhour;
   ntime = nhour + otime + ampm;
   document.getElementById('date').value = ndate;
   document.getElementById('time').value = ntime;
   clockID = setTimeout("UpdateClock()", 1000);
}

function StartClock() {
   clockID = setTimeout("UpdateClock()", 200);
}

function KillClock() {
   if(clockID) {
      document.getElementById('date').value = "";
      document.getElementById('time').value = "";
      clearTimeout(clockID);
      clockID  = 0;
   }
}

function js_ShowWorldTime()
{
    document.write('<table WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" BORDERCOLOR="#ACD6E6" STYLE="border-collapse:collapse;">');
    document.write('<TR>');
    document.write('<TD colspan="2" ALIGN="CENTER" HEIGHT="25" BGCOLOR="#F0F6FB" CLASS="calculate" ');
    document.write(' ><B>World Time Calculator</B></TD>');
    document.write('</TR>');
    document.write('<tr><td colspan="2" align="center" BGCOLOR="#Fafafa">');
    document.write('<select name="timezone" id="timezone" onChange="changeTimeZone(this.options[this.selectedIndex].value)" class="searchdrop">');
    document.write('<option value=0>Select a Timezone to Display the Current Time</option>');
    for (i=1; i<=zone.len; i++) {
        offset = zone[i].time.split(".");
        hoffset = offset[0];
        moffset = (parseInt(offset[1])) ? "30" : "00";
        tzoffset = hoffset + ":" + moffset 
     
        document.write('<option value="' + zone[i].time + '">' + zone[i].name);
        if (parseInt(zone[i].time)) document.write(" GMT(" + tzoffset + ")");
        document.write('</option>\n');
    }
    document.write('</select></td></tr>');
    document.write('<tr><td  align="right" BGCOLOR="#Fafafa" style="padding-top:6px;"><div class="calculate"><b>Current Time: &nbsp;</b></div></td>');
    document.write('<td  align="left" BGCOLOR="#Fafafa" style="padding-top:6px;">&nbsp;<input type=text name="time" id="time" size=11 onFocus="this.blur()">&nbsp;&nbsp;</td></tr>\n');
    document.write('<tr><td  align="right" BGCOLOR="#Fafafa" style="padding-top:6px;"><div class="calculate"><b>Current Date: &nbsp;</b></div></td>');
    document.write('<td  align="left" BGCOLOR="#Fafafa" style="padding-top:6px;">&nbsp;<input type=text name="date" id="date" size=16 onFocus="this.blur()"> &nbsp;</td></tr>');
    document.write('<tr><td  align="right" BGCOLOR="#F0F6FB" style="padding-top:6px;" colspan="2">');
    document.write('<div align="center" class="text">Please make sure the time displayed on your desktop maintains accuracy with the local time of your Time Zone.</div>'); 
    document.write('</td></tr>');    
    document.write('</table>');
    //document.write('</form>');
}