1 /*/////////////////////////////////////////////////////////
2 // This code is based off of
3 // "Live Clock Lite" script - Version 1.0
4 // By Mark Plachetta (astroboy@zip.com.au)
6 // The original script displayed a clock.
7 // Mark Nielsen modified it to be a countdown timer
8 // for the lesson module in moodle.
10 // Below is the code that is used to call this page.
11 // echo "<script type=\"text/javascript\">\n";
12 // echo "var starttime = ". $timer->starttime . ";\n";
13 // echo "var servertime = ". time() . ";\n";
14 // echo "var testlength = ". $lesson->maxtime * 60 .";\n";
15 // echo "document.write('<script type=\"text/javascript\" src=\"liveclock_lite.js\"><\/script>');\n";
16 // echo "window.onload = function () { show_clock(); }";
17 // echo "</script>\n";
19 //////////////////////////////////////////////////////////*/
21 var myfont_face = "Arial";
22 var myfont_size = "12";
23 var myfont_color = "#000000";
24 var myback_color = "#FFFFFF";
29 var timeleft, hours, minutes, secs;
30 var javatimeDate = new Date();
31 var javatime = javatimeDate.getTime();
32 javatime = Math.floor(javatime/1000);
34 difference = javatime - servertime;
35 starttime = starttime + difference;
40 if (document.all||document.getElementById) {
41 document.write('<span id="LiveClockIE" style="width:'+mywidth+'px;"></span>');
42 } else if (document.layers) {
43 document.write('<ilayer id="ClockPosNS"><layer width="'+mywidth+'" id="LiveClockNS"></layer></ilayer>');
45 old = "true"; show_clock();
48 /*function leave() { // feable attempt to run a script when someone leaves a timed test early, failed so far
49 window.onunload = window.open('http://www.google.com','','toolbar=no,menubar=no,location=no,height=500,width=500');
53 function show_clock() {
57 document.ClockPosNS.visibility="show"
58 if (old == "die") { return; }
60 currentDate = new Date();
61 current = currentDate.getTime();
62 current = Math.floor(current/1000);
64 if (current > starttime + testlength) {
66 myclock += '<font style="color:'+myfont_color+'; font-family:'+myfont_face+'; font-size:'+myfont_size+'pt;">';
67 myclock += "Time is up";
71 timeleft = starttime + testlength - current;
72 hours = Math.floor(timeleft/3600);
73 timeleft = timeleft - (hours * 3600);
74 minutes = Math.floor(timeleft/60);
75 secs = timeleft - (minutes * 60);
81 minutes = "0"+minutes;
84 myclock += '<font style="color:'+myfont_color+'; font-family:'+myfont_face+'; font-size:'+myfont_size+'pt;">';
85 myclock += hours+":"+minutes+":"+secs;
90 document.write(myclock);
94 if (document.layers) {
95 clockpos = document.ClockPosNS;
96 liveclock = clockpos.document.LiveClockNS;
97 liveclock.document.write(myclock);
98 liveclock.document.close();
99 } else if (document.all) {
100 LiveClockIE.innerHTML = myclock;
101 } else if (document.getElementById) {
102 document.getElementById("LiveClockIE").innerHTML = myclock;
105 if (stopclock == 0) {
106 setTimeout("show_clock()",1000);