
function setClock()
 {
  baselvl = new Date()
  basesec = baselvl.getSeconds()
  getDayLightStart(reftime.year)
  getDayLightEnd()
  lastFriApr = getlastfri_apr();
  lastThrSep = getlastthr_sep();
  makeMonthArray()
  makeDayArray()
  makePlaceArrays()
  return true
 }


function getStandardTime(stime)   // 44
 {
   var syear   = stime.year
   var smonth  = stime.month
   var sdate   = stime.date
   var sday    = stime.day
   var shour   = stime.hour
   var smin    = stime.min
   var ssec    = stime.sec 
   var year4   = syear  
   var Mlength = months[smonth].length
   if (smonth == 2)
     { Mlength = getFebMonthDays(year4)}
   if (ssec > 59)
     {
       ssec -= 60
       smin += 1
     } 
   if (smin  > 59)
     {                                // 63
      smin -= 60
      shour += 1 
     }
   if (shour > 23)
    {
    shour = shour - 24
    sdate = sdate + 1
    sday  = sday + 1
    }
   if (sday > 6)
    { sday = 0 }

   if (sdate > Mlength)
    {
     sdate  = 1
     smonth += 1
   
    if (smonth > 12) 
    {
     smonth = 1
     syear += 1
    }
   }
  // when correction is -ve

  if (smin < 0)
   {
    smin += 60
    shour -= 1
   }
  if (shour < 0)
   {
    shour += 24
    sday  -= 1
    sdate -= 1
   }
  if (sday < 0 )
   { sday = 6}
  if (sdate <= 0)
    {                          // 103
    smonth -= 1                 
    if (smonth == 0) 
     { 
     smonth = 12
     syear -= 1
     }                           
    Mlength = months[smonth].length
    if (smonth == 2)
     { Mlength = getFebMonthDays(year4)} 
    sdate = Mlength                 
    }                              // 114
    stime.year  = syear
    stime.month = smonth
    stime.date  = sdate
    stime.day   = sday
    stime.hour  = shour
    stime.min   = smin
    stime.sec   = ssec 
    return stime;    
 }

function showTime()                // 125
{
 var ss
 var cs
 var cd  
 if (revstep == 0) 
 { reftime.sec += 1 }
 else
  { revstep += 1 }    
 reftime=getStandardTime(reftime)    
 computeTime();
 execnum +=1 
 if (execnum == 10)
  { 
   execnum= 0
   cd = new Date()
   cs = cd.getSeconds()
   ss = cs - basesec
   if (ss < 0)
    { ss +=60 }
   syncClock(ss)
   basesec = cs
  }
 setTimeout("showTime()", timeintvl);
}                                         // 145
function syncClock(ss)
 {
   if (ss > 10 )
    { reftime.sec += ss - 10 }
    else
      { revstep = ss - 10 }
   if (timeintvl > 100)
    {

   if (ss > 0)  
    {
      timeintvl *= 10
      timeintvl /= ss
    }
    }
 
 }

function computeTime()
{
 var i = 1;
 
 for (i=1; i <= 56; i++)
  {
    afPlaces[i] = placeTime(afPlaces[i]);     
    document.afForm.afTime[i-1].value= afPlaces[i].curtime;
  }
}

function getDayLightStart(anyyear)
 {
   if (anyyear >= 2000)
    {
      anyyear -= 2000
    }
   var x = anyyear % 28
    
   if (x == 0)
       dayStart = 2
   else if (x == 1)               // 154
       dayStart = 1
   else if (x == 2)
       dayStart = 7
   else if (x == 3)
       dayStart = 6
   else if (x == 4)
       dayStart = 4
   else if (x == 5)
       dayStart = 3
   else if (x == 6)
       dayStart = 2
   else if (x == 7)
       dayStart = 1
   else if (x == 8)
       dayStart = 6
   else if (x == 9)
       dayStart = 5
   else if (x == 10)
       dayStart = 4
   else if (x == 11)
       dayStart = 3
   else if (x == 12)
       dayStart = 1
   else if (x == 13)
       dayStart = 7
   else if (x == 14)
       dayStart = 6
   else if (x == 15)
       dayStart = 5
   else if (x == 16)                 
       dayStart = 3
   else if (x == 17)
       dayStart = 2
   else if (x == 18)
       dayStart = 1
   else if (x == 19)
       dayStart = 7
   else if (x == 20)
       dayStart = 5
   else if (x == 21)
       dayStart = 4
   else if (x == 22)
       dayStart = 3
   else if (x == 23)
       dayStart = 2
   else if (x == 24)               // 200
       dayStart = 7
   else if (x == 25)
       dayStart = 6
   else if (x == 26)
       dayStart = 5
   else if (x == 27)
       dayStart = 4
  return true
 }
function getDayLightEnd()
{
 if (dayStart < 5 )
     dayEnd = dayStart + 27
 else if (dayStart > 4)            
     dayEnd = dayStart + 20       // 215 
}
function getlastfri_apr()
 {
  if (dayStart < 5)
     return (dayStart + 26)
  else return (dayStart + 19)
 } 
function getlastthr_sep()
{
  if (dayStart < 5)
     return (dayStart + 26)
  else return (dayStart + 19)
 } 
function placeTime(splace)
 {
  var  refx= new xtime()
  refx.hour = reftime.hour + splace.hrcorr
  refx.sec  = reftime.sec 
  refx.min  = reftime.min + splace.mincorr 
  refx.day  = reftime.day
  refx.date = reftime.date
  refx.month= reftime.month
  refx.year = reftime.year              
  var apind = "AM"
  refx=getStandardTime(refx);
  // apply day light correction if applicable
  if (splace.dual == 3)           // 230
   {
  
    refx.hour -= correctDLE(refx); 
    refx=getStandardTime(refx);  
      
   }             
  if (refx.hour == 12)
   {
     
    apind = "NN"
   } 
    
  
  if (refx.hour > 12)
   {
    refx.hour -= 12
    apind = "PM"
   } 
    
  splace.curtime = dayText(refx.day)+ " "  
  splace.curtime += monthText(refx.month)+ " "  
  splace.curtime += refx.date
  splace.curtime += ", "
  splace.curtime += refx.hour
  splace.curtime += ((refx.min < 10) ? ":0" : ":") + refx.min;
  splace.curtime += ((refx.sec < 10) ? ":0" : ":") + refx.sec;
  splace.curtime += apind
  return (splace)
 }
function correctDLH(refx)
 {
  if ((refx.month < 4 || (refx.month == 4 && refx.date  < dayStart)  ||
     ( refx.month == 4 && refx.date  == dayStart && refx.hour < 2)) ||
     ( refx.month > 10 || (refx.month == 10 && refx.date > dayEnd)  ||
     ( refx.month == 10 && refx.date == dayEnd && refx.hour > 2) ||
     (refx.month == 10 && refx.date == dayEnd && refx.hour == 2 && refx.min > 0) ||
     (refx.month == 10 && refx.date == dayEnd && refx.hour == 2 && refx.min == 0 && refx.sec > 0)))  
     {      return 0  }
  else     return -1
 }
function correctDLE(refx)
 {
  if ((refx.month < 4 || (refx.month == 4 && refx.date  < lastFriApr)  ||
     ( refx.month == 4 && refx.date  == lastFriApr && refx.hour < 2)) ||
     ( refx.month > 9 || (refx.month == 9 && refx.date > lastThrSep)  ||
     ( refx.month == 9 && refx.date == lastThrSep && refx.hour >= 3)))  
     {      return 0  }
  else     return -1
 }
function dayText(ii)
  {
   return days[ii +1]
  }
function monthText(ii)
  {
   return months[ii].name
  }
function makeDayArray()  
 {
  days = new makeArray(7)
  days[1]  = "Sun"
  days[2]  = "Mon"
  days[3]  = "Tue"                // 285
  days[4]  = "Wed"
  days[5]  = "Thu"
  days[6]  = "Fri"
  days[7]  = "Sat"
 }

function makeMonthArray()  
 {
  months = new makeArray(12)
  months[1]  = new month("Jan",31,0)
  months[2]  = new month("Feb",28,1)
  months[3]  = new month("Mar",31,2)
  months[4]  = new month("Apr",30,3)
  months[5]  = new month("May",31,4)
  months[6]  = new month("Jun",30,5)
  months[7]  = new month("Jul",31,6)
  months[8]  = new month("Aug",31,7)
  months[9]  = new month("Sep",30,8)
  months[10] = new month("Oct",31,9)
  months[11] = new month("Nov",30,10)
  months[12] = new month("Dec",31,11) 
 }                                       //307
function makePlaceArrays()  
 {
  afPlaces = new makeArray(56)
  afPlaces[1]  = new place("Algeria",0,1,0,0,"")
  afPlaces[2]  = new place("Angola",0,1,0,1,"")
  afPlaces[3]  = new place("Benin",0,1,0,2,"")
  afPlaces[4]  = new place("Botswana",0,2,0,3,"")
  afPlaces[5]  = new place("Burkina",0,0,0,4,"")
  afPlaces[6]  = new place("Burundi",0,2,0,5,"")
  afPlaces[7]  = new place("Cameroon",0,1,0,6,"")
  afPlaces[8]  = new place("Cape Verde",0,-1,0,7,"")
  afPlaces[9]  = new place("Cen. African Rep",0,1,0,8,"")
  afPlaces[10]  = new place("Chad",0,1,0,9,"")
  afPlaces[11]  = new place("Comoro Islands",0,3,0,10,"")
  afPlaces[12]  = new place("Congo",0,1,0,11,"")
  afPlaces[13]  = new place("Djibouti",0,3,0,12,"")
  afPlaces[14]  = new place("Egypt",3,2,0,13,"")
  afPlaces[15]  = new place("Eq. Guinea",0,1,0,14,"")
  afPlaces[16]  = new place("Eritrea",0,3,0,15,"")
  afPlaces[17]  = new place("Ethiopia",0,3,0,16,"")
  afPlaces[18]  = new place("Gabon",0,1,0,17,"")
  afPlaces[19]  = new place("Gambia",0,0,0,18,"")
  afPlaces[20]  = new place("Ghana",0,0,0,19,"")
  afPlaces[21]  = new place("Guinea",0,0,0,20,"")
  afPlaces[22]  = new place("Guinea Bissau",0,0,0,21,"")
  afPlaces[23]  = new place("Ivory Coast",0,0,0,22,"")
  afPlaces[24]  = new place("Kenya",0,3,0,23,"")
  afPlaces[25]  = new place("Lesotho",0,2,0,24,"")
  afPlaces[26]  = new place("Liberia",0,0,0,25,"")
  afPlaces[27]  = new place("Libya",0,1,0,26,"")
  afPlaces[28]  = new place("Madagascar",0,3,0,27,"")
  afPlaces[29]  = new place("Malawi",0,2,0,28,"")
  afPlaces[30]  = new place("Mali",0,0,0,29,"")
  afPlaces[31]  = new place("Mauritania",0,0,0,30,"")
  afPlaces[32]  = new place("Mauritius",0,4,0,31,"")
  afPlaces[33]  = new place("Mayotte (France)",0,3,0,32,"")
  afPlaces[34]  = new place("Morocco",0,0,0,33,"")
  afPlaces[35]  = new place("Mozambique",0,2,0,34,"")
  afPlaces[36]  = new place("Namibia",0,2,0,35,"")
  afPlaces[37]  = new place("Niger",0,1,0,36,"")
  afPlaces[38]  = new place("Nigeria",0,1,0,37,"")
  afPlaces[39]  = new place("Reunion (France)",0,4,0,38,"")
  afPlaces[40]  = new place("Rwanda",0,2,0,39,"")
  afPlaces[41]  = new place("Sao Tome",0,0,0,40,"")
  afPlaces[42]  = new place("Senegal",0,0,0,41,"")
  afPlaces[43]  = new place("Seychelles",0,4,0,42,"")
  afPlaces[44]  = new place("Sierra Leone",0,0,0,43,"")
  afPlaces[45]  = new place("Somalia",0,3,0,44,"")
  afPlaces[46]  = new place("South Africa",0,2,0,45,"")
  afPlaces[47]  = new place("Sudan",0,2,0,46,"")
  afPlaces[48]  = new place("Swaziland",0,2,0,47,"")
  afPlaces[49]  = new place("Tanzania",0,3,0,48,"")
  afPlaces[50]  = new place("Togo",0,0,0,49,"")
  afPlaces[51]  = new place("Tunisia",0,1,0,50,"")
  afPlaces[52]  = new place("Uganda",0,3,0,51,"")
  afPlaces[53]  = new place("W. Sahara",0,0,0,52,"")
  afPlaces[54]  = new place("Zaire",1,2,0,53,"")
  afPlaces[55]  = new place("Zambia",0,2,0,54,"")
  afPlaces[56]  = new place("Zimbabwe",0,2,0,55,"") 
}   // 332

function makeArray(arrayLength)  // 333  
 {
  this.length = arrayLength
  for (i=1; i <= arrayLength; i++)
   this[i] = 0
  return this
 }
 
function month(name, length, index)  
 {
 this.name   = name    // property
 this.length = length  // property
 this.index  = index   // property
 }                                  // 355
function place(name, dual, hrcorr, mincorr, index, curtime)  
 {                                         // 357
 this.name     = name      // property
 this.dual     = dual      // property
 this.hrcorr   = hrcorr    // property
 this.mincorr  = mincorr   // property
 this.index    = index     // property
 this.curtime  = curtime  // property  
 } 
 
function getFebMonthDays(pyear) //  
{
 if ((pyear % 4 == 0 && pyear % 100 !=0) ||(pyear % 400 ==0))
  return 29
else
  return 28
} 