// Calendar: written by Marc Fluks; version 07/07/2007.
// The results of the calculations are displayed at,
// http://www.me-net.combidom.com/javascript/time.html#icorstime
// DST rule: http://wwp.daylight-saving-time.com/usa/dst-2007.htm
// Define Date.
   var now        = new Date()
// Find day of the week for March 8 and November 1.
   var julianmar  = Math.round((30.6*4)-0.5)+Math.round((365.25*now.getUTCFullYear())-0.5)+8+1720981.5
   var juliannov  = Math.round((30.6*12)-0.5)+Math.round((365.25*now.getUTCFullYear())-0.5)+1+1720981.5
   var daymar     = (julianmar+1.5)/7
   var daynov     = (juliannov+1.5)/7
   var daymar     = Math.round(7*(daymar-Math.round(daymar-.5)))
   var daynov     = Math.round(7*(daynov-Math.round(daynov-.5)))
// Find the second Sunday in March and the first Sunday in November.
   var array      = [8,14,13,12,11,10,9,8]
   var daymar     = array[daymar]
   var array      = [1,7,6,5,4,3,2,1]
   var daynov     = array[daynov]
// Find Julian Day for second Sunday in March and the first Sunday in November at 7:00 UTC.
   var julianmar  = Math.round((30.6*4)-0.5)+Math.round((365.25*now.getUTCFullYear())-0.5)+daymar+1720981.5
   var julianmar  = julianmar+7.00/24
   var juliannov  = Math.round((30.6*12)-0.5)+Math.round((365.25*now.getUTCFullYear())-0.5)+daynov+1720981.5
   var juliannov  = juliannov+7.00/24
// Find IcorsTimezone (values 4 for DST and 5 for standard time).
   var julian     = Math.round(30.6*((now.getUTCMonth()+1)+(((now.getUTCMonth()+1)<3)?13:1))-0.5)+Math.round(365.25*(now.getUTCFullYear()+(((now.getUTCMonth()+1)<3)?-1:0))-0.5)+now.getUTCDate()+1720981.5
   var julian     = julian+(now.getUTCHours()+now.getUTCMinutes()/60+now.getUTCSeconds()/3600)/24
   var IcorsTimezone = (julian-julianmar)*(julian-juliannov)
   var IcorsTimezone = 4.5+.5*(IcorsTimezone/Math.sqrt(IcorsTimezone*IcorsTimezone))
// Find IcorsDay.
   var IcorsDay = (now.getUTCHours()+now.getUTCMinutes()/60+now.getUTCSeconds()/3600-IcorsTimezone)/24
   var IcorsDay = Math.round(IcorsDay-0.5)
   var IcorsDay = 7+now.getUTCDay()+IcorsDay
// Redefine Days from 0 to 6.
   var array        = [0,1,2,3,4,5,6,0,1,2,3,4,5,6,0]
   var IcorsDay = array[IcorsDay]
// Find shiftday: is localday later/earlier than IcorsDay ?
   var shiftday   = 7+(now.getDay()-IcorsDay)
   var array      = [0,1,0,0,0,0,-1,0,1,0,0,0,0,-1]
   var shiftday   = array[shiftday]
// How many days are present in the local month ?
   var array      = [1,0,0,0]
   var shiftyear  = array[Math.round(4*((now.getFullYear()/4)-Math.round((now.getFullYear()/4)-.5)))]
   var array      = [31,28,31,30,31,30,31,31,30,31,30,31]
   var shiftyear  = shiftyear*((30-array[now.getMonth()])*(31-array[now.getMonth()])/6)
   var daysinmonth = array[now.getMonth()]+shiftyear
// Find shiftweek: is localweek later/earlier than IcorsWeek ?
   var month28    = [0,1,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0]
   var month29    = [0,1,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0]
   var month30    = [0,1,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,1,1,1,0]
   var month31    = [0,1,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,1]
   var shiftweek28 = (month28[now.getDate()])*((29-daysinmonth)*(30-daysinmonth)*(31-daysinmonth)/6)
   var shiftweek29 = (month29[now.getDate()])*((daysinmonth-28)*(30-daysinmonth)*(31-daysinmonth)/2)
   var shiftweek30 = (month30[now.getDate()])*((daysinmonth-28)*(daysinmonth-29)*(31-daysinmonth)/2)
   var shiftweek31 = (month31[now.getDate()])*((daysinmonth-28)*(daysinmonth-29)*(daysinmonth-30)/6)
   var shiftweek  = shiftday*(shiftweek28+shiftweek29+shiftweek30+shiftweek31)
// Find IcorsWeek and IcorsYear.
   var array      = [0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5,5]
   var IcorsWeek  = (array[now.getDate()]+5*(now.getMonth()))-shiftweek
   var array      = [60,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,1]
   var shiftyear  = (array[IcorsWeek]-IcorsWeek)/60
   var IcorsWeek  = array[IcorsWeek]
   var firstdate  = IcorsWeek
   var IcorsWeek  = ((IcorsWeek<10)?"0":"")+IcorsWeek
   var IcorsYear  = now.getFullYear()-shiftyear
// Find IcorsMonth (0=january, 11=december).
   var IcorsMonth = Math.round(((IcorsWeek-1)/5)-.5)
   var array      = ['January','February','March','April','May','June','July','August','September','October','November','December']
   var months     = array[IcorsMonth]
// Find IcorsLeapYear: is IcorsYear a leap year ? (0=no, 1=yes)
   var array      = [1,0,0,0]
   var IcorsLeapYear = array[Math.round(4*((now.getFullYear()/4)-Math.round((now.getFullYear()/4)-.5)))]
// Find first date of Icors week.
   var array      = [0,1,8,15,22,29,1,8,15,22,29,1,8,15,22,29,1,8,15,22,29,1,8,15,22,29,1,8,15,22,29,1,8,15,22,29,1,8,15,22,29,1,8,15,22,29,1,8,15,22,29,1,8,15,22,29,1,8,15,22,29]
   var firstdate  = array[firstdate]
// Find first day of Icors week.
   var firstday   = Math.round(30.6*((IcorsMonth+1)+(((IcorsMonth+1)<3)?13:1))-0.5)+Math.round(365.25*(IcorsYear+(((IcorsMonth+1)<3)?-1:0))-0.5)+firstdate+1720981.5
   var firstday   = (firstday+1.5)/7
   var firstday   = Math.round(7*(firstday-Math.round(firstday-.5)))
// Find shiftdate: how many days is IcorsDay later than first day of Icors week ?
   var shiftdate  = 7+IcorsDay-firstday
   var array      = [0,1,2,3,4,5,6,0,1,2,3,4,5,6]    
   var shiftdate  = array[shiftdate]
// Find Icors date.
   var IcorsDate  = firstdate+shiftdate
   var IcorsDate  = ((IcorsDate<10)?"0":"")+IcorsDate
// Find Icors time.
   var array      = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2]
   var IcorsHours = 24+now.getUTCHours()-IcorsTimezone
   var IcorsHours = array[IcorsHours]
   var IcorsMinutes = now.getUTCMinutes()
   var IcorsSeconds = now.getUTCSeconds()
   var IcorsTime  = ((IcorsHours<10)?"0":"")+IcorsHours+((IcorsMinutes<10)?":0":":")+IcorsMinutes+((IcorsSeconds<10)?":0":":")+IcorsSeconds
