function timeModal() { setTimeout("createModal();", 1000*60*39); } function createModal() { var overlay = document.createElement('div'); overlay.id = 'overlay'; overlay.style.position = 'absolute'; overlay.style.left = '0px'; overlay.style.top = '0px'; overlay.style.backgroundImage = 'url(/churchdb/images/transoverlay.gif)'; overlay.style.backgroundRepeat = 'repeat'; overlay.style.width = document.body.scrollWidth + 'px'; overlay.style.height = document.body.scrollHeight + 'px'; var modal = document.createElement('div'); modal.id = 'modal'; modal.style.position = 'absolute'; modal.style.width = '300px'; modal.style.height = '150px'; modal.style.padding = '25px'; modal.style.backgroundColor = '#ffc621'; modal.style.border = '3px ridge'; modal.style.textAlign = 'center'; var modal_warn = document.createElement('span'); modal_warn.style.fontWeight = 'bold'; modal_warn.style.fontSize = '18px'; modal_warn.appendChild(document.createTextNode('WARNING')); modal.appendChild(modal_warn); modal.appendChild(document.createElement('br')); modal.appendChild(document.createTextNode('Your session will timeout in:')); modal.appendChild(document.createElement('br')); modal.appendChild(document.createElement('br')); var modal_clock = document.createElement('span'); modal_clock.id = 'modal_clock'; modal_clock.style.fontFamily = 'monospace'; modal_clock.appendChild(document.createTextNode('5 minutes')); modal.appendChild(modal_clock); modal.appendChild(document.createElement('br')); modal.appendChild(document.createElement('br')); var modal_btn = document.createElement('input'); modal_btn.setAttribute('type', 'button'); modal_btn.setAttribute( 'value', 'Continue Session' ); modal_btn.className = 'SmallButton'; modal_btn.style.backgroundColor = 'green'; modal_btn.style.cursor = 'pointer'; modal_btn.onclick = continueSession; modal.appendChild(modal_btn); overlay.appendChild(modal); document.body.appendChild(overlay); startclock(); positionModal(); document.body.modalIntervalID = setInterval("positionModal();",200) } function positionModal() { var posX = window.innerWidth ? window.innerWidth : document.body.clientWidth; var posY = window.innerHeight ? window.innerHeight : document.body.clientHeight; var scrollX = window.pageXOffset ? window.pageXOffset : document.body.scrollLeft; var scrollY = window.pageYOffset ? window.pageYOffset : document.body.scrollTop; var modal = document.getElementById('modal'); modal.style.left = (posX/2 - 150 + scrollX) + 'px'; modal.style.top = (posY/2 - 75 + scrollY) + 'px'; } function destroyModal() { clearInterval(document.body.modalIntervalID); removeThatNode('overlay', true); } function removeThatNode(id, rc) { var node = document.getElementById( id ); node.removeNode(rc); } if (window.Node) { Node.prototype.removeNode = function(removeChildren) { var self = this; if (Boolean(removeChildren)) { return this.parentNode.removeChild( self ); } else { var range = document.createRange(); range.selectNodeContents(self); return this.parentNode.replaceChild(range.extractContents(), self); } } } function continueSession() { var modal = document.getElementById('modal'); stopclock(); var modal_js = document.createElement('script'); modal_js.setAttribute('language', 'Javascript'); modal_js.setAttribute('src', '/churchdb/INCLUDE/SessionRefresh.asp'); modal.appendChild(modal_js); } var timerID; var timerRunning = false; var today = new Date(); var enday = new Date(); var secPerDay = 0; var minPerDay = 0; var hourPerDay = 0; var secsLeft = 0; var secsRound = 0; var secsRemain = 0; var minLeft = 0; var minRound = 0; var minRemain = 0; var timeRemain = 0; var decremain = 0; var decround = 0; function stopclock () { if(timerRunning) { clearTimeout(timerID); } timerRunning = false; } function startclock () { stopclock(); today = new Date(); enday = new Date(Date.parse(today) + 1000*60*5); showtime(); } function showtime () { today = new Date(); secsPerDay = 1000 ; minPerDay = 60 * 1000 ; hoursPerDay = 60 * 60 * 1000; PerDay = 24 * 60 * 60 * 1000; /*Seconds*/ secsLeft = (enday.getTime() - today.getTime()) / minPerDay; decremain = (enday.getTime() - today.getTime()) / secsPerDay; decround = Math.round(decremain); decremain = decround + " seconds"; secsRound = Math.round(secsLeft); secsRemain = secsLeft - secsRound; secsRemain = (secsRemain < 0) ? secsRemain = 60 - ((secsRound - secsLeft) * 60) : secsRemain = (secsLeft - secsRound) * 60; secsRemain = Math.round(secsRemain); /*Minutes*/ minLeft = ((enday.getTime() - today.getTime()) / hoursPerDay); minRound = Math.round(minLeft); minRemain = minLeft - minRound; minRemain = (minRemain < 0) ? minRemain = 60 - ((minRound - minLeft) * 60) : minRemain = ((minLeft - minRound) * 60); minRemain = Math.round(minRemain - 0.495); /*Hours*/ hoursLeft = ((enday.getTime() - today.getTime()) / PerDay); hoursRound = Math.round(hoursLeft); hoursRemain = hoursLeft - hoursRound; hoursRemain = (hoursRemain < 0) ? hoursRemain = 24 - ((hoursRound - hoursLeft) * 24) : hoursRemain = ((hoursLeft - hoursRound) * 24); hoursRemain = Math.round(hoursRemain - 0.5); /*Days*/ daysLeft = ((enday.getTime() - today.getTime()) / PerDay); daysLeft = (daysLeft - 0.5); daysRound = Math.round(daysLeft); daysRemain = daysRound; /*Time*/ timeRemain = ( (daysRemain > 0 ) ? daysRemain + " day" + ((daysRemain != 1) ? "s" : "") + ", " : "" ) + ( (hoursRemain > 0) ? hoursRemain + " hour" + ((hoursRemain != 1) ? "s" : "") + ", " : "" ) + ( (minRemain > 0) ? minRemain + " minute" + ((minRemain != 1) ? "s" : "") : "" ) + ( ((minRemain > 0) && (secsRemain < 60)) ? ", " : "" ) + ( (secsRemain < 60) ? secsRemain + " second" + ((secsRemain != 1) ? "s" : "") : "" ); var modal_clock = document.getElementById('modal_clock'); modal_clock.removeChild(modal_clock.childNodes.item(0)); modal_clock.appendChild(document.createTextNode(timeRemain)); timerID = setTimeout("showtime()",1000); timerRunning = true; if (Date.parse(new Date()) >= Date.parse(enday)) { clearTimeout(timerID); timerRunning = false; var modal = document.getElementById('modal'); modal.removeChild(modal.childNodes.item(8)); modal_clock.removeChild(modal_clock.childNodes.item(0)); modal_clock.appendChild(document.createTextNode('Session Ended')); window.location.href = '/ChurchDB/SessionEnded.asp?iOrgzKey='; } } if(self.attachEvent) { self.attachEvent( 'onload', timeModal ); } if(self.addEventListener) { self.addEventListener( 'load', timeModal, false ); }