//COUNT DOWN FUNCTION
function CounterDown(objToShowIn, objType, nMaxSeconds){
	//objToShowIn 	= obj passed as document.getElementById 
	//objType	= pass 'textbox' or empty
	//nIEndSeconds 	= important for showing DESCENDING display, this is the max number of seonds to start from

	var milisec = 0;
	var seconds = nMaxSeconds; 
	var timer   = "";

	if(objType.toUpperCase() == 'TEXTBOX') objToShowIn.value = ""+seconds;
	else objToShowIn.innerHTML = ""+seconds;
	
	this.displayCounterDown = function(){ 
 		if (milisec<=0){milisec=9; seconds-=1;} 
 		if (seconds<=-1){milisec=0; seconds+=1;} 
 		else milisec-=1;
		if(seconds == 0) timer = "";
		else timer = ""+seconds+"."+milisec+" sec";
		if(objType.toUpperCase() == 'TEXTBOX') objToShowIn.value = timer;
		else objToShowIn.innerHTML = timer;
    		setTimeout("this.displayCounterDown()",100);
	} 
	this.displayCounterDown();
}

//COUNT UP FUNCTION
function CounterUp(objToShowIn, objType){
	//objToShowIn 	= obj passed as document.getElementById 
	//objType	= pass 'textbox' or empty

	var milisec = 0;
  	var seconds = 0;
	var timer   = 0;
	var hr	    = 0;
	var min	    = 0;
	var sec     = 0;

	this.displayCounterUp = function(){
  		if (milisec>=9){milisec=0; seconds+=1;}
  		else milisec+=1;
		
		min = parseInt(seconds/60);
		if(min > 59){hr = parseInt(min/60); min = parseInt(min%60);}			
		sec = parseInt(seconds%60);
		
		if(hr < 10) timer = "0";
		timer += hr;
		timer += ":";
		if(min < 10) timer += "0";
		timer += min;
		timer += ":";
		if(sec < 10) timer += "0";
		timer += sec;
		timer += ":";
		timer += milisec;
		//timer = ""+seconds+"."+milisec+" sec";
		if(objType.toUpperCase() == 'TEXTBOX') objToShowIn.value = timer;
		else objToShowIn.innerHTML = timer;
     		setTimeout("this.displayCounterUp()",100);
  	}
	this.displayCounterUp();
}

//THIS DISPLAYS THE CLOCK IN THE STATUS BAR
function doClock() {
	window.setTimeout( "doClock()", 1000);
   	today = new Date();
   	self.status = today.toLocaleString();//toString();
}

//display current clock time
function CurrentClockTime(objToShowIn, objType, nShowDate){
	//objToShowIn 	= obj passed as document.getElementById 
	//objType	= pass 'textbox' or empty
	//nShowDate	= 0 not show, 1 show, meaning show date also with time

	var clockID 	= 0;
	var toShow	= "";
	this.UpdateClockTime = function() {
   		this.KillClock();
	   	var tDate = new Date();
		toShow = "";
		if(nShowDate == 1) toShow += tDate.toLocaleString();
		else toShow += tDate.getHours() + ":" + tDate.getMinutes() + ":" + tDate.getSeconds();
		if(objType.toUpperCase() == 'TEXTBOX') objToShowIn.value = toShow;
		else objToShowIn.innerHTML = toShow;
   		clockID = setTimeout("this.UpdateClockTime()", 1000);
	}
	this.KillClock = function() {
   		if(clockID) {clearTimeout(clockID);clockID  = 0;}
	}
	this.StartClock = function(){
		clockID = setTimeout("this.UpdateClockTime()", 500);
	}
	//start the clock
	this.StartClock();
}