/* FILE ARCHIVED ON 11:31:04 Jan 16, 2014 AND RETRIEVED FROM THE INTERNET ARCHIVE ON 5:57:44 Nov 3, 2016. JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE. ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C. SECTION 108(a)(3)). */ /* ADDS_2007 Author : Alex Dredge Date : 04/03/2007 Usage : StartCountDown(string, int, string); Notes : Count down value passed in must be in seconds Count Down timer to calculate how many days, hours, minutes and seconds left till a specific date */ var _arrCountDownContainers = new Array(); var _arrCountDownSeconds = new Array(); var _arrCountDownCallbacks = new Array(); var _countDownTimer = 0; function _cdt_CountDownTick() { var activeCount = 0; for (var key in _arrCountDownSeconds) { var curSeconds = _arrCountDownSeconds[key]; if (curSeconds < 0) continue; if (curSeconds == 0) { _cdt_TimeOver(key); continue; } _cdt_ApplyCountdownText(key); activeCount++; } if (activeCount > 0) _countDownTimer = window.setTimeout("_cdt_CountDownTick()", 100); } function _cdt_TimeOver(key) { _arrCountDownSeconds[key] = -1; var strCallback = _arrCountDownCallbacks[key]; if (strCallback && strCallback.length > 0) { eval(strCallback + "();"); } } function StartCountDown(strContainerID, initialValue, strCallback) { if (typeof initialValue == "undefined") { if (_arrCountDownSeconds[strContainerID] && _arrCountDownSeconds[strContainerID] < 0) { _arrCountDownSeconds[strContainerID] = _arrCountDownSeconds[strContainerID] * -1; _arrCountDownContainers[strContainerID].setAttribute("initial_timer_value", _arrCountDownSeconds[strContainerID] + ""); _arrCountDownContainers[strContainerID].setAttribute("activation_time", _cdt_GetCurrentTime() + ""); RestartCountdownTimer(1); } return; } var objContainer = document.getElementById(strContainerID); if (!objContainer) { alert("count down error: container does not exist: " + strContainerID + "\nmake sure html element with this ID exists"); return; } if (is_array(initialValue)) { var dtNow = new Date(); var dtFuture = _cdt_ArrayToDate(initialValue); if (dtFuture < dtNow) { alert("count down error: can't use past date as initializer"); return; } initialValue = parseInt(((dtFuture.getTime() - dtNow.getTime()) / 1000)); } objContainer.setAttribute("activation_time", _cdt_GetCurrentTime() + ""); objContainer.setAttribute("initial_timer_value", initialValue + ""); _arrCountDownContainers[strContainerID] = objContainer; _arrCountDownCallbacks[strContainerID] = strCallback; _cdt_ApplyCountdownText(strContainerID); RestartCountdownTimer(1000); } function DateDifferenceSecs(startdate, enddate) { Math.ceil((enddate.getTime() - startdate.getTime()) / 1000); } function RestartCountdownTimer(value) { if (_countDownTimer) window.clearTimeout(_countDownTimer); _countDownTimer = window.setTimeout("_cdt_CountDownTick()", value); } function StopCountDown(strContainerID) { if (_arrCountDownSeconds[strContainerID] && _arrCountDownSeconds[strContainerID] > 0) { _arrCountDownSeconds[strContainerID] = _arrCountDownSeconds[strContainerID] * -1; } } function DeactivateAllCountdowns() { for (var key in _arrCountDownSeconds) { StopCountDown(key); } } function ActivateAllCountdowns() { for (var key in _arrCountDownSeconds) { StartCountDown(key); } } function SetInitialTime(strContainerID, initialValue) { var nValue = parseInt(initialValue); if (isNaN(nValue)) { alert("invalid number: " + initialValue); return; } if (nValue < 0) nValue = 0; var objContainer = _arrCountDownContainers[strContainerID]; if (objContainer) { objContainer.setAttribute("activation_time", _cdt_GetCurrentTime() + ""); objContainer.setAttribute("initial_timer_value", nValue + ""); } } function GetCurrentTime(strContainerID) { var objContainer = _arrCountDownContainers[strContainerID]; if (objContainer) { return _cdt_GetRealSeconds(objContainer); } return 0; } function is_array(input) { return (typeof(input) == 'object' && (input instanceof Array)); } function _cdt_ApplyCountdownText(strContainerID) { //get container: var objContainer = _arrCountDownContainers[strContainerID]; //get format: var strFormat = objContainer.getAttribute("time_format"); var blnCustomFormat = true; if (!strFormat || strFormat.length == 0) { strFormat = "%h:%m:%s"; blnCustomFormat = false; } //get real seconds var seconds = _cdt_GetRealSeconds(objContainer); //store: _arrCountDownSeconds[strContainerID] = seconds; //build text: var strText = ""; //time over? var strFinishTime = objContainer.getAttribute("finish_value"); if (strFinishTime && strFinishTime.length > 0) { var nFinishTime = parseFloat(strFinishTime); if (!isNaN(nFinishTime) && seconds < nFinishTime) { _cdt_TimeOver(strContainerID); return; } } //raw? if (strFormat == "RAW") { strText = parseFloat(seconds.toFixed(2)); } else { //get minutes: var minutes = parseInt(seconds / 60); //shrink: seconds = (seconds % 60); //get hours: var hours = parseInt(minutes / 60); //shrink: minutes = (minutes % 60); //get days: var days = parseInt(hours / 24); //shrink: hours = (hours % 24); //need to add zero? if (!blnCustomFormat) { hours = AddZero(hours); minutes = AddZero(minutes); seconds = AddZero(seconds); } strText = strFormat.replace("%d", days + "").replace("%h", hours + "").replace("%m", minutes + "").replace("%s", seconds + ""); } //apply: objContainer.innerHTML = strText; } function AddZero(num) { return ((num >= 0)&&(num < 10))?"0"+num:num+""; } function _cdt_GetCurrentTime() { var objDate = new Date(); return objDate.getTime(); } function _cdt_GetRealSeconds(objContainer) { var nCurrentTime = _cdt_GetCurrentTime(); var nActivationTime = parseInt(objContainer.getAttribute("activation_time")); var nInitialValue = parseFloat(objContainer.getAttribute("initial_timer_value")); var nMiliSecondsDiff = (nCurrentTime - nActivationTime); var nTotalDifference = parseInt(nMiliSecondsDiff / 1000); var strSecondValue = objContainer.getAttribute("second_value"); if (strSecondValue && strSecondValue.length > 0) { var nSecondValue = parseFloat(strSecondValue); if (!isNaN(nSecondValue)) nTotalDifference = parseFloat(nTotalDifference) * nSecondValue; } return (nInitialValue - nTotalDifference); } function _cdt_ArrayToDate(arrDateTimeParts) { var dtFuture = new Date(); var day = _cdt_ParseArrayItemToNumber(arrDateTimeParts, 0, 1, 31, "day", 0, dtFuture.getDate()); var month = _cdt_ParseArrayItemToNumber(arrDateTimeParts, 1, 1, 12, "month", -1, dtFuture.getMonth()); var year = _cdt_ParseArrayItemToNumber(arrDateTimeParts, 2, 200, 3200, "year", 0, dtFuture.getFullYear()); var hours = _cdt_ParseArrayItemToNumber(arrDateTimeParts, 3, 0, 23, "hour", 0, dtFuture.getHours()); var minutes = _cdt_ParseArrayItemToNumber(arrDateTimeParts, 4, 0, 59, "minute", 0, dtFuture.getMinutes()); var seconds = _cdt_ParseArrayItemToNumber(arrDateTimeParts, 5, 0, 59, "second", 0, dtFuture.getSeconds()); dtFuture.setDate(day); dtFuture.setMonth(month); dtFuture.setFullYear(year); dtFuture.setHours(hours); dtFuture.setMinutes(minutes); dtFuture.setSeconds(seconds); return dtFuture; } function _cdt_ParseArrayItemToNumber(arrValues, index, minValue, maxValue, strCaption, offset, defaultValue) { if (index >= 0 && index < arrValues.length) { var nValue = parseInt(arrValues[index]) + offset; if (isNaN(nValue) || nValue < minValue || nValue > maxValue) { alert(arrValues[index] + " is invalid " + strCaption + ", using current " + strCaption); } else { return nValue; } } return defaultValue; }