<html>
<head>
<title>Ajax</title>
<style type="text/css">
.green { color: #00bb00; text-decoration: none; }
.red { color: #ff0000; text-decoration: none; }
#Clock {
height: 45px;
width: 45px;
margin: 0px;
padding: 0px;
margin-left: 100px;
}
.button {
background: #FFFECD;
border: 1px solid #FFE65C;
color: #000000;
padding-left: 5px;
padding-right: 5px;
padding-bottom: 2px;
}
#wrap {
width: 150px;
height: 100px;
background: #FFFFEA;
border: 1px solid #ABAB65;
padding: 0px;
margin: 0px;
}
</style>
<script type="text/javascript" SRC="js/ajax.js"></script>
<script type="text/javascript">
<!--
/* simpleFindObj, by Andrew Shearer
Efficiently finds an object by name/id, using whichever of the IE,
classic Netscape, or Netscape 6/W3C DOM methods is available.
The optional inLayer argument helps Netscape 4 find objects in
the named layer or floating DIV. */
function simpleFindObj(name, inLayer) {
return document[name] || (document.all && document.all[name])
|| (document.getElementById && document.getElementById(name))
|| (document.layers && inLayer && document.layers[inLayer].document[name]);
}
/* Set the Ctime to the desired amount */
var start_cTime;
var clockRun = 1;
var cTime = false;
/* Sets clock to update in one second */
function clockUpdate(stop) {
if (stop) {
cTime = start_cTime;
clockRun = 0;
}
if (clockRun == 1) {
(!cTime)? cTime = start_cTime : cTime;
clockSubtract(cTime)
setTimeout("clockUpdate()",1000);
}
}
/* Subtracts 1000 microseconds from the last time, and translates into how many minutes/seconds */
function clockSubtract(inMicro) {
cTime = inMicro - 1000;
if (cTime >= 0) {
inMinutes = Math.floor(cTime / 60000);
inSeconds = (cTime % 60000) / 1000;
clockColor('Clock', 'green')
}
if (cTime < 0) {
inMinutes = Math.ceil(cTime / 60000);
inSeconds = (cTime % 60000) / -1000;
nTime = 1;
clockColor('Clock', 'red')
}
clockDisplay(inMinutes, inSeconds);
}
/* Set the display of the readout */
function clockReadout(inMinutes, inSeconds) {
if (cTime > 0) { return inMinutes + (inSeconds < 10 ? ":0" : ":") + inSeconds; }
if (cTime == 0) { return "0:00"; }
if (cTime < 0 && inMinutes == 0) { return "-" + inMinutes + (inSeconds < 10 ? ":0" : ":") + inSeconds; }
if (inMinutes < 0) { return inMinutes + (inSeconds < 10 ? ":0" : ":") + inSeconds; }
}
/* Function to be called to update clock */
function clockDisplay(inMinutes, inSeconds) {
clockWrite("Clock", clockReadout(inMinutes, inSeconds));
}
/* Function that actually writes to the clock */
function clockWrite (divName, newValue) {
var divObject = simpleFindObj(divName);
newValue = '<h2>' + newValue + '<' + '/h2>';
if (divObject && divObject.innerHTML) {
divObject.innerHTML = newValue;
}
else if (divObject && divObject.document) {
divObject.document.writeln(newValue);
divObject.document.close();
}
}
/* Function that changes the colour of the timer if its in the negative */
function clockColor(clockId, newClass) {
identity=document.getElementById(clockId);
identity.className=newClass;
}
//-->
</script>
</head>
<body>
<div id="wrap">
<FORM Name="Form1" ACTION="">
<center>
<div class="green" id="Clock" style="">
<h2>0:00</h2>
</div>
<INPUT TYPE="BUTTON" VALUE="Stop" ID="stop" NAME="stop" OnClick="clockUpdate(stop)" class="button">
</center>
</div>
<INPUT TYPE="BUTTON" VALUE="Break" NAME="Timer" OnClick="getMyHTML('timer.php?t=0','popup')" class="button">
<INPUT TYPE="BUTTON" VALUE="Lunch" NAME="Timer2" OnClick="getMyHTML('timer.php?t=1','popup')" class="button">
<INPUT TYPE="BUTTON" VALUE="Vacation" NAME="Timer3" OnClick="getMyHTML('timer.php?t=2','popup')" class="button">
</FORM>
<div id="popup">
</div>
</body>
</html>