
// All scripts on this page are the work of Timothy Edwards, DBA Can2Can, who asserts all author's rights under Copyright law
// permision granted to use _as is, with copyright stement_ as a callable script file on non-commercial sites
// link to your file with "<script language = "Javascript" type="text/javascript" src="can2can.biz/Sito/ClockFun.js">;"
// linking to this copy on Can2Can.biz website, instead of pulling your own copy, ensures latest bug-fixes and updates

function c2cDaySaveFlag(y,vDate,vMonth){	// 0=sunday/6=saturday,DayOfMonth,MonthOfYear
// use the passed current date value to determine if Daylight savings is in effect (US)
// Original version used months 3=April and 9=October (zero-base)
// Code revised for changes in Daylight Savings period enacted effective 2007 in US
  if(vMonth > 10) return 0	// Change out is in month 9, so past change
  if(vMonth < 2) return 0	// Change in is in month 3, so before change
  if(vMonth > 2 && vMonth <10) return 1 // Between months of change, no doubts
  if(vMonth == 2 && vDate > 14) return 1 // over a week into change-in, set it.
  if(vMonth == 2 && (vDate - 7) > y) return 1 // Sunday or after, set it.
  if(vMonth == 2) return 0
  if(vMonth == 10 && vDate < y) return 1 // not into last week yet, leave it set
  return 0
  }

function c2sub7SegReadout(fvSecs,fvMins,fvHour,ivImagePointOffset,ivNumberOfDiigits){
// use the time numbers and display pointer to write the time
  var c2cjspix = ivImagePointOffset + c2cZClockPoint

c2cLedNumbers(c2cjspix + 2,2,fvMins)
c2cLedNumbers(c2cjspix -1,2,fvHour)
  if (ivNumberOfDiigits == 4) {return 0}
c2cLedNumbers(c2cjspix + 5,2,fvSecs)
  return 1
 }

function c2cLedNumbers(ivFirstImage,ivNumOfPlaces,fvValue){
// generic display of number values using numeral images
 var viLNLoop, fvLNtemp1, fvLNtemp2;
 var fvLNValue = fvValue
	for ( viLNLoop = ivNumOfPlaces; viLNLoop > 0; viLNLoop-- ) {
  var fvLNtemp1 = (fvLNValue % 10)
  document.images[ivFirstImage + viLNLoop].src = c2cjsnums[fvLNtemp1].src
  var fvLNtemp2 = (fvLNValue - fvLNtemp1)
  fvLNValue = (fvLNtemp2 /10)
}
return 1
}

function c2sub2Time(fvBig,ivModulus){
// "mod" is supposed to return integer results, but fails when there are large magnitude differences
  var temp = (fvBig % ivModulus)
// scrub off any non-integer tail from the magnitude mismatch...
  var intr = 0
  for (var i = 0; i <= temp; i++){intr++}
// change it to time format, 1-0 instead of 1-modu (saw what should have been a roll from 23:59 over to 00:00 give 24:60 instead!)
  if (intr == ivModulus) {return 0}
  return intr
  }

function c2subZoneTime(tvZulu,ivZoneNum,ivSaveTime){
// calculate time in a zone from GMT, zone-number, and daylight saving time correction.
  c2cjszhrs = (tvZulu + ivZoneNum + ivSaveTime)
// is ivZoneNum is west, we can be into yesterday, check for roll-under
  if (c2cjszhrs < 0 ) {c2cjszhrs = c2cjszhrs + 24}
// and ivZoneNum east can roll over into tomorrow
  if (c2cjszhrs > 23 ) {c2cjszhrs = c2cjszhrs - 24}
  return c2cjszhrs
  }
function getCookie(Name) {
// Scan our cookie for the value of param "Name"
	var search = Name + "="
	if (document.cookie.length > 0) { // if there are any cookies
	     offset = document.cookie.indexOf(search)
		 if (offset != -1) { // if cookie exists
		 offset += search.length
		 // set index of beginning of value
		 end = document.cookie.indexOf(";", offset)
		 // set index of end of cookie value
		 if (end == -1)
		 	end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
			}
		}
	}

