/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Neill Broderick :: http://www.bespoke-software-solutions.co.uk/downloads/downjs.php */

var hrs;
var mins;
var secs;
var dhrs;
var dmins;
var dsecs;

function h(obj) {
 	for(var i = 0; i < obj.length; i++) {
  		if(obj.substring(i, i + 1) == ":")
  		break;
 	}
 	return(obj.substring(0, i));
}

function m(obj) {
 	for(var i = 0; i < obj.length; i++) {
  		if(obj.substring(i, i + 1) == ":")
  		break;
 	}
 	return(obj.substring(i + 1, obj.length));
}

function sc(obj) {
 	for(var i = 0; i < obj.length; i++) {
  		if(obj.substring(i, i + 1) == ":")
  		break;
 	}
 	return(obj.substring(i + 1, obj.length));
}

function dis(hrs,mins,secs) {
 	var disp;
 	//if(hrs <= 9) {
  //		disp = " 0";
 	//} else {
  //		disp = " ";
 	//}
 	//disp += hrs + ":";
 	disp = "";
 	if(mins <= 9) {
  		disp += "0";
 	} else {
  		disp += "";
 	}
 	disp += mins + ":";
 	
 	if(secs <= 9) {
  		disp += "0" + secs;
 	} else {
  		disp += secs;
 	}
 	return(disp);
}

function redo() {
 	secs--;
 	if(secs == -1) {
  		secs = 59;
  		mins--;
  		if(mins == -1) {
  		  mins = 59;
  		  hrs--;
  		}
 	}
 	document.getElementById("ecdisp").value = dis(hrs,mins,secs); // setup additional displays here.
 	if((hrs == 0) && (mins == 0) && (secs == 0)) {
  		document.getElementById("ecUpcoming").style.display = "none";
  		document.getElementById("ecInSession").style.display = "block";
  		redois();
  		//window.alert("Time is up. Press OK to continue."); // change timeout message as required
  		// window.location = "yourpage.htm" // redirects to specified page once timer ends and ok button is pressed
 	} else {
 		cd = setTimeout("redo()",1000);
 	}
}

function redois() { //In Session Version
 	dsecs--;
 	if(dsecs == -1) {
  		dsecs = 59;
  		dmins--;
  		if(dmins == -1) {
  		  dmins = 59;
  		  dhrs--;
  		}
 	}
 	//document.getElementById("ecdisp").value = "In Session"; // setup additional displays here.
 	if((dhrs == 0) && (dmins == 0) && (dsecs == 0)) {
 	    document.getElementById("ecOuter").style.display = "none";
  		document.getElementById("ecCS").style.display = "block";
  		//window.alert("Time is up. Press OK to continue."); // change timeout message as required
  		// window.location = "yourpage.htm" // redirects to specified page once timer ends and ok button is pressed
 	} else {
 		cd = setTimeout("redois()",1000);
 	}
}

function init() {
  cd();
}
window.onload = init;