//+--------------------------------------------------------------------------+
//| Timer Class                                                              |
//+--------------------------------------------------------------------------+

function Ticker(ID, tID, lID, time, stopped, tTitle, tNote) {
	this.ID = ID;
	this.tID = tID;
	this.localID = lID;
	this.time = 0.0;
	this.timerID = 0;
	this.rowID = 0;
	this.decimalTotal = 0;
	this.timeTotal = { "hours":0,"minutes":0,"seconds":0 };
	this.counter = 0;
	this.title = tTitle;
	this.note = tNote || '';
	this.isDirty = false;

	// set the refID (should be the ID in the timer table or a random number if new);
	this.refID = (this.localID != 0) ? this.localID : Math.floor(Math.random() * (-990000)) - 1000;
	this.setUris();

	if (this.note == '') {
		this.note = this.title;
	}

	// create the HTML
    this.spawn(stopped,tTitle,time);

	this.timer = new Timer(this);
	this.init(time);
}

Ticker.prototype.setUris = function() {

    this.starturi = '/xml/tour.timer.php?f_timer_action=start';
	this.stopuri = '/xml/tour.timer.php?f_timer_action=stop';
	this.clearuri = '/xml/tour.timer.php?f_timer_action=clear';
}

Ticker.prototype.init = function(time) {
	if( isNaN(time) ) {
		return;
	}
	this.time = time;
	this.calculate();
	//prime the seconds from the db
	this.counter = 0;
}

Ticker.prototype.tick = function(d){
	this.calculate();
	this.timerID = this.timer.setTimeout("tick", 1000, d);
	++this.counter;
}

Ticker.prototype.updateTimerList = function() {
    if ( typeof(buildTimerList) == 'function' && this.localID > 0 ) {
        buildTimerList(this.localID);
	}
}

Ticker.prototype.start = function(){
	timerRequest(this.starturi);
	this.updateTimerList();
}

Ticker.prototype.stop = function() {
	this.timer.clearTimeout(this.timerID);
	timerRequest(this.stopuri);
	this.updateTimerList();
}

Ticker.prototype.clear = function() {
	if(this.refID > 0) {
		msg = 'Are you sure you want to clear timer for task #' + this.refID + '?';
	} else {
		msg = 'Are you sure you want to clear this general timer?';
	}
	var result = confirm(msg);
	if(result){
	   this.clearComplete();
	}
	// return whether or not the timer was successfully cleared
	return result;
}
Ticker.prototype.clearComplete = function() {
    if (this.timer.checkRegister(this.timerID) == this.ID) {
        this.timer.clearTimeout(this.timerID);
    }
	timerRequest(this.clearuri);
	this.updateTimerList();
}
Ticker.prototype.destroy = function(g) {

	//document.timers--;

    var oTimerRow = $('tBox'+this.refID);
    var taskAIcon = $('hTaskApplyIcon'+this.refID);
    if (taskAIcon) { taskAIcon.style.display = 'none'; }
    var taskCIcon = $('hTaskClearIcon'+this.refID);
	if (taskCIcon) { taskCIcon.style.display = 'none'; }
	var taskTimeDiv = $('hTaskTimeDiv'+this.refID);
	if (taskTimeDiv) { taskTimeDiv.style.display = 'none'; }

	var newTaskRow = $('tTaskTdRow'+this.refID);
	if (newTaskRow) { newTaskRow.style.visibility = 'hidden'; }

    if(this.refID > 0) {

		var oTimerParent = $('tBoxTimers');
		oTimerParent.removeChild(oTimerRow);

		ekTickerCounter--;
		if( ekTickerCounter <= 0 ) {
			$('tBoxNotimers').style.display = 'block';
		}

	} else {

	    var oTimerParent = $('tBoxGeneralTimers');

    	var aicon = $('hApplyIcon'+this.refID);
    	aicon.style.display = 'none';
    	var cicon = $('hClearIcon'+this.refID);
    	cicon.style.display = 'none';

    	if (ekGeneralTickerCounter > 1) {
    	    ekGeneralTickerCounter--;
    	    oTimerParent.removeChild(oTimerRow);
    	}
	}

	// change the size of the timer blocks
    eval('oTimerParent.style.height=(20*' + ((this.refID > 0) ? 'ekTickerCounter' : 'ekGeneralTickerCounter') + ')+"px"');

}

Ticker.prototype.calculate = function(){
	this.secondsToDecimal(this.time + this.counter);
	this.secondsToTime(this.time + this.counter);
	this.updateDisplay();
}

Ticker.prototype.updateDisplay = function(){
	var sTime	 = $('hTime'+this.refID);
	var sTimeDec = $('hTimeDecimal'+this.refID);
	sTime.innerHTML		= (this.refID < 0 ? '&nbsp;' : '') + '' + Number.lz(this.timeTotal['hours']) + ":" + Number.lz(this.timeTotal['minutes']) + ':' + Number.lz(this.timeTotal['seconds']) + ' hrs';
	sTimeDec.innerHTML  = (this.refID < 0 ? '&nbsp;' : '') + formatNumber(this.decimalTotal,3);

	var sTaskTime	 = $('hTaskTime'+this.refID);
	var sTaskTimeDec = $('hTaskTimeDecimal'+this.refID);
	if (sTaskTime && sTaskTimeDec) {
	   sTaskTime.innerHTML		= '('+Number.lz(this.timeTotal['hours']) + ":" + Number.lz(this.timeTotal['minutes']) + ':' + Number.lz(this.timeTotal['seconds']) + ')';
	   sTaskTimeDec.innerHTML   = formatNumber(this.decimalTotal,3);
	}
}

Ticker.prototype.secondsToDecimal = function(seconds) {
	if(!Number.prototype.toFixed) {
		this.decimalTotal = parseInt(this.timeToDecimal(0, 0,seconds) * 1000 ) / 1000;
	}
	else {
		this.decimalTotal = this.timeToDecimal(0, 0,seconds).toFixed(3);
	}
}

Ticker.prototype.secondsToTime = function(seconds) {
	var result = { "hours":0,"minutes":0,"seconds":0 };
	this.timeTotal['hours'] = parseInt(seconds / 3600);
	this.timeTotal['minutes'] = parseInt(seconds / 60) - (this.timeTotal['hours'] * 60);
	this.timeTotal['seconds'] = parseInt(seconds - (this.timeTotal['hours'] * 3600 + this.timeTotal['minutes'] * 60));
	//return result;
}

Ticker.prototype.timeToDecimal = function(hours, minutes, seconds) {
	return (hours + minutes/60 + seconds/3600);
}

Ticker.prototype.toggleStart = function(v) {
	var icon	 = $('hStartIcon'+this.refID);
	icon.style.display = v;
	var taskIcon = $('hTaskStartIcon'+this.refID);
	if (taskIcon) { taskIcon.style.display = v; }

	var aicon	 = $('hApplyIcon'+this.refID);
	aicon.style.display = v;
	var taskAIcon = $('hTaskApplyIcon'+this.refID);
	if (taskAIcon) { taskAIcon.style.display = v; }

	var cicon	 = $('hClearIcon'+this.refID);
	cicon.style.display = v;
	var taskCIcon = $('hTaskClearIcon'+this.refID);
	if (taskCIcon) { taskCIcon.style.display = v; }

	var taskRow = $('taskRow'+this.refID);
	if (taskRow && v == 'none') {
	    taskRow.className = 'timer';
	}

}

Ticker.prototype.toggleStop = function(v) {
	var icon	 = $('hStopIcon'+this.refID);
	icon.style.display = v;
	var taskIcon = $('hTaskStopIcon'+this.refID);
	if (taskIcon) { taskIcon.style.display = v; }

	var taskRow = $('taskRow'+this.refID);
	if (taskRow && v == 'none') { taskRow.className = (this.rowID % 2 == 0) ? 'odd' : 'even';	}

	var taskTimeDiv = $('hTaskTimeDiv'+this.refID);
	if (taskTimeDiv) { taskTimeDiv.style.display = (this.decimalTotal > 0) ? 'inline' : v; }

}

Ticker.prototype.toggleIcon = function(v) {
	var tIcon	 = $('tIcon'+this.refID);
	var taskTIcon = $('tTaskIcon'+this.refID);

	if ( v == 1 ){
		tIcon.src = t_clock_on.src;
		if (taskTIcon) { taskTIcon.src = t_clock_on.src; }
	}else{
		tIcon.src = t_clock_off.src;
		if (taskTIcon) { taskTIcon.src = t_clock_off.src; }
	}
}

Ticker.prototype.save = function(){
	var lID = this.refID;
	this.note = encodeURIComponent($('tTextNote'+lID).value);
	this.toggleAnimation(true);
	timerRequest('/xml/tour.timer.php?f_timer_action=edit&f_ID='+this.tID+'&f_localID='+this.refID+'&f_name='+this.note);

}

Ticker.prototype.showText = function() {
	if ( ekCurrent != null && ekTicker[ekCurrent] != null && $('tNoteTextDiv'+ekCurrent) != null && ekTimer > 0) {
		if ( ekTicker[ekCurrent].isDirty ) {
			ekTicker[ekCurrent].save();
		} else {
			ekTicker[ekCurrent].toggleText(false);
		}
	}
	clearTimeout(ekTimer);
	ekCurrent = this.refID;
	this.toggleText(true, false, false);
}

Ticker.prototype.hideText = function() {
	ekTicker[this.refID].toggleText(false);
}

Ticker.prototype.toggleText = function(v, clearvalue, setvalue) {
	var lID = this.refID;
	if ( v ) {
		$('tNoteTextDivView'+lID).style.display = 'none';
		$('tNoteTextDiv'+lID).style.display = 'inline';
		$('tTextNote'+lID).focus();
		$('tTextNote'+lID).select();
		//$('tTextNote'+lID).style.background = '#F5F6BE';
		//$('tTextNote'+lID).style.border = '1px solid #ccc';
	} else {
		$('tNoteTextDivView'+lID).style.display = 'block';
		$('tNoteTextDiv'+lID).style.display = 'none';
		//$('tTextNote'+lID).blur();
		//$('tTextNote'+lID).style.background = '#FFFFDD';
		//$('tTextNote'+lID).style.border = '1px solid #fff';
	}

	if ( clearvalue ) {
		this.note = '';
		this.setNote('');
	}

	if ( setvalue ) {
		this.setNote(encodeURIComponent($("tTextNote"+lID).value));
	}
}

Ticker.prototype.setNote = function(val) {
	var lID = this.refID;
	this.note = val;
	$('iconNoteHref'+lID).title = $('ttTaskTitle-'+lID).innerHTML = $('tIcon'+lID).title = 'General Task: ' + (val != '' ? decodeURIComponent(val) : 'No label');
	$('tNoteTextDivView'+lID).innerHTML = decodeURIComponent(val).length > 25 ? decodeURIComponent(val).substring(0,24) + '&hellip;' : decodeURIComponent(val);

	$('tTextNote'+lID).value = decodeURIComponent(val);
	//$('tNoteTextDivView'+lID).innerHTML = decodeURIComponent(val);
}

Ticker.prototype.toggleAnimation = function(v) {
	var lID = this.refID;
	$('tTextNote'+lID).style.background = (v ? '#F5F6BE url(' + parent.location.protocol + '//w0.s.myintervals.com/i/icons/progress.gif) no-repeat right' : '#F5F6BE');
	if ( !v ) {
		this.isDirty = false;
		//$('tTextNote'+lID).style.border = '1px solid #fff';
		//$('tTextNote'+lID).style.background = '#FFFFDD';
		//$('tTextNote'+lID).blur();
	}
}

Ticker.prototype.spawn = function(stopped,title,time) {

	// hold a ptr to this class
	var me = this;

    // this will create the HTML for the timers in the footer
    var lID = this.refID;

	// this is div where the main content will appear
	var block = (lID > 0) ? $('tBoxTimers') : $('tBoxGeneralTimers');
	
	// the div we will put into the block
	var box = document.createElement('div');
	box.setAttribute('id','tBox'+lID);
	box.style.clear='both';
	box.style.height='20px';

    	// timer icon
    	var boxTIcon = document.createElement('div');
    	boxTIcon.style.display = 'inline';
    	boxTIcon.className = 'tIcon';

			var boxTIhref = document.createElement('a');
			boxTIhref.href = "javascript:void(0);";
			boxTIhref.style.cursor = 'default';
			boxTIhref.className = 'sprites iconsClockStopped';
			if (lID > 0) {
				boxTIhref.setAttribute('title', "Task #"+lID);
			} else {
				boxTIhref.setAttribute('title', "General Task: " + (this.note != '' ? decodeURIComponent(this.note) : 'No label'));
			}
			boxTIcon.appendChild(boxTIhref);

            // timer icon img
            var boxTIconImg = document.createElement('img');
            boxTIconImg.setAttribute('id','tIcon'+lID);
            boxTIconImg.src = "/i/" + (!stopped ? 'layout/t' : 'icons/timer_active_ani') + ".gif";
            boxTIconImg.setAttribute('width', '17');
            boxTIconImg.setAttribute('height', '17');
            boxTIconImg.setAttribute('border', "0");
			
            boxTIhref.appendChild(boxTIconImg);

            // tooltip: put it here to keep it from moving around in IE
            var boxTTextTitle = document.createElement('div');
            boxTTextTitle.setAttribute('id','ttTaskTitle-'+lID);
            boxTTextTitle.className = 'tooltipText';
            boxTTextTitle.style.display = 'none';
            boxTTextTitle.style.textAlign = 'left';
			if (lID > 0) {
				boxTTextTitle.innerHTML = 'Task #'+lID+': '+title;
			} else {
				boxTTextTitle.innerHTML = 'General Task: ' + (this.note != '' ? decodeURIComponent(this.note) : 'No label');
			}
            boxTIcon.appendChild(boxTTextTitle);
        box.appendChild(boxTIcon);

        // pause/start/apply/clear
        var boxIcons = document.createElement('div');
        boxIcons.style.display = 'inline';
        boxIcons.style.whiteSpace = 'nowrap';

            // start time icon
            var boxStartIcon = document.createElement('div');
            boxStartIcon.setAttribute('id','hStartIcon'+lID);
            boxStartIcon.className = 'tIcon';
            boxStartIcon.style.display = (stopped) ? 'none' : 'inline';
                // anchor
                var boxStartIconAnchor = document.createElement('a');
                boxStartIconAnchor.setAttribute('title','Start');
                boxStartIconAnchor.onclick = function () { eval("ekTicker[" + lID + "].start();"); }
                boxStartIconAnchor.href='javascript:void(0);';
				boxStartIconAnchor.className = 'sprites iconsTimerStart';
                    // img
                    var boxStartIconAnchorImg = document.createElement('img');
                    boxStartIconAnchorImg.setAttribute('id','iconStart'+lID);
                    boxStartIconAnchorImg.setAttribute('width','17');
                    boxStartIconAnchorImg.setAttribute('height','17');
                    boxStartIconAnchorImg.setAttribute('border','0');
                    boxStartIconAnchorImg.setAttribute('alt','Start the clock');
					boxStartIconAnchorImg.src = '/i/t.gif';;
                    boxStartIconAnchor.appendChild(boxStartIconAnchorImg);
                boxStartIcon.appendChild(boxStartIconAnchor);
            boxIcons.appendChild(boxStartIcon);

            // stop time icon
            var boxStopIcon = document.createElement('div');
            boxStopIcon.setAttribute('id','hStopIcon'+lID);
            boxStopIcon.className = 'tIcon';
            boxStopIcon.style.display = (!stopped) ? 'none' : 'inline';
                // anchor
                var boxStopIconAnchor = document.createElement('a');
                boxStopIconAnchor.setAttribute('title','Stop');
                boxStopIconAnchor.onclick = function () { eval("ekTicker[" + lID + "].stop();"); }
                boxStopIconAnchor.href='javascript:void(0);';
				boxStopIconAnchor.className = 'sprites iconsTimerStop';
                    // img
                    var boxStopIconAnchorImg = document.createElement('img');
                    boxStopIconAnchorImg.setAttribute('id','iconStop'+lID);
                    boxStopIconAnchorImg.setAttribute('width','17');
                    boxStopIconAnchorImg.setAttribute('height','17');
                    boxStopIconAnchorImg.setAttribute('border','0');
                    boxStopIconAnchorImg.setAttribute('alt','Stop the clock');
                    boxStopIconAnchorImg.src = '/i/t.gif';;
                    boxStopIconAnchorImg.style.verticalAlign = 'bottom';
                    boxStopIconAnchor.appendChild(boxStopIconAnchorImg);
                boxStopIcon.appendChild(boxStopIconAnchor);
            boxIcons.appendChild(boxStopIcon);
            // apply time icon
            var boxApplyIcon = document.createElement('div');
            boxApplyIcon.setAttribute('id','hApplyIcon'+lID);
            boxApplyIcon.className = 'tIcon';
            boxApplyIcon.style.display = (stopped || time == 0) ? 'none' : 'inline';
                // anchor
                var boxApplyIconAnchor = document.createElement('a');
                boxApplyIconAnchor.setAttribute('title','Apply');
                if (lID > 0) {
                    boxApplyIconAnchor.onclick = function () {
						addtimeTaskTime(lID,1,decodeURIComponent(me.note));
					}
                } else {
                    boxApplyIconAnchor.onclick = function () {
						addtimeRegularTime(timerpersonID,null,null,ekTicker[lID].tID,lID,decodeURIComponent(me.note));
					}
                }
                boxApplyIconAnchor.href='javascript:void(0);';
				boxApplyIconAnchor.className = 'sprites iconsTimerApply';
                    // img
                    var boxApplyIconAnchorImg = document.createElement('img');
                    boxApplyIconAnchorImg.setAttribute('id','iconApply'+lID);
                    boxApplyIconAnchorImg.setAttribute('width','34');
                    boxApplyIconAnchorImg.setAttribute('height','17');
                    boxApplyIconAnchorImg.setAttribute('border','0');
                    boxApplyIconAnchorImg.setAttribute('alt','Apply');
                    boxApplyIconAnchorImg.src = '/i/t.gif';;
                    boxApplyIconAnchor.appendChild(boxApplyIconAnchorImg);
                boxApplyIcon.appendChild(boxApplyIconAnchor);
            boxIcons.appendChild(boxApplyIcon);
            // clear time icon
            var boxClearIcon = document.createElement('div');
            boxClearIcon.setAttribute('id','hClearIcon'+lID);
            boxClearIcon.className = 'tIcon';
            boxClearIcon.style.display = (stopped || time == 0) ? 'none' : 'inline';
                // anchor
                var boxClearIconAnchor = document.createElement('a');
                boxClearIconAnchor.setAttribute('title','Clear');
                boxClearIconAnchor.onclick = function () { eval("ekTicker[" + lID + "].clear();"); }
                boxClearIconAnchor.href='javascript:void(0);';
				boxClearIconAnchor.className = 'sprites iconsTimerClear';
                    // img
                    var boxClearIconAnchorImg = document.createElement('img');
                    boxClearIconAnchorImg.setAttribute('id','iconClear'+lID);
                    boxClearIconAnchorImg.setAttribute('width','34');
                    boxClearIconAnchorImg.setAttribute('height','17');
                    boxClearIconAnchorImg.setAttribute('border','0');
                    boxClearIconAnchorImg.setAttribute('alt','Clear');
                    boxClearIconAnchorImg.src = '/i/t.gif';;
                    boxClearIconAnchor.appendChild(boxClearIconAnchorImg);
                boxClearIcon.appendChild(boxClearIconAnchor);
            boxIcons.appendChild(boxClearIcon);
        box.appendChild(boxIcons);

        // task# / decimal hours / clock hours
        var boxTText = document.createElement('div');
		boxTText.id = 'ttTaskTitle' + lID;
        boxTText.className = 'tText tTextDec';
            if (lID > 0) {
                // # sign
                var boxTaskPound = document.createTextNode('#');
                boxTText.appendChild(boxTaskPound);
                // task #
                var boxTaskNo = document.createElement('a');
				boxTaskNo.setAttribute('id','hTaskNo'+lID);
                boxTaskNo.className = 'tooltip';
                boxTaskNo.setAttribute('rel','ttTaskTitle-'+lID);
                boxTaskNo.style.fontWeight='bold';
                boxTaskNo.href="/tasks/view/"+lID;
                boxTaskNo.title=title.replace(/&quot;/g,'"');
                boxTaskNo.innerHTML=lID+': ';
                boxTText.appendChild(boxTaskNo);
            }
            // decimal hours
            var boxDecHours = document.createElement('span');
            boxDecHours.setAttribute('id','hTimeDecimal'+lID);
			boxDecHours.style.display = 'none';
            boxTText.appendChild(boxDecHours);

			/*
            var boxDecHoursText = document.createTextNode(' hrs');
			boxTText.appendChild(boxDecHoursText);
			*/

            // clock hours
            var boxTimeHours = document.createElement('span');
            boxTimeHours.setAttribute('id','hTime'+lID);
			boxTimeHours.style.display = 'inline';

			var boxTimeHoursText = document.createTextNode(' hrs');
			boxTimeHours.appendChild(boxTimeHoursText);
			boxTimeHours.style.display = 'block';
			//boxTimeHours.style.color = 'blue';
			boxTimeHours.style.float = 'left';
			boxTimeHours.style.marginTop = '-2px';

            boxTText.appendChild(boxTimeHours);
        box.appendChild(boxTText);

//if ( lID < 0 ) {
			// div containing label and note icon
            var boxNoteIcon = document.createElement('div');
            boxNoteIcon.setAttribute('id','nNoteIcon'+lID);
            boxNoteIcon.className = 'tIcon';
            boxNoteIcon.style.display = 'inline';

                // anchor
                var boxNoteIconAnchor = document.createElement('a');
				boxNoteIconAnchor.setAttribute('id','iconNoteHref'+lID);
				boxNoteIconAnchor.setAttribute('title', "General Task: " + (this.note != '' ? decodeURIComponent(this.note) : 'No label'));
                boxNoteIconAnchor.href='javascript:void(0);';
				boxNoteIconAnchor.className = "sprites iconsTimerNote";
				boxNoteIconAnchor.onclick = function() {
					if ( ekCurrent == me.refID ) {
						$('tTextNote'+lID).focus();
						$('tTextNote'+lID).select();
					} else {
						me.showText();
					}
				}

				// img
				var boxNoteIconImg = document.createElement('img');
				boxNoteIconImg.setAttribute('id','iconNoteImg'+lID);
				boxNoteIconImg.setAttribute('width','16');
				boxNoteIconImg.setAttribute('height','17');
				boxNoteIconImg.setAttribute('border','0');
				boxNoteIconImg.setAttribute('alt','Edit Note');
				boxNoteIconImg.src = '/i/t.gif';;
				boxNoteIconAnchor.appendChild(boxNoteIconImg);
				boxNoteIcon.appendChild(boxNoteIconAnchor);
			box.appendChild(boxNoteIcon);

			// span note preview
			var noteTextDivView = document.createElement('div');
			noteTextDivView.setAttribute('id','tNoteTextDivView'+lID);
			noteTextDivView.style.display = 'block';
			noteTextDivView.className = 'tIcon';
			noteTextDivView.innerHTML = this.note.length > 25 ? this.note.substring(0,24) + '&hellip;' : this.note;
			
			noteTextDivView.style.width = '120px';
			noteTextDivView.style.height = '1.3em';
			noteTextDivView.style.overflow = 'hidden';
			noteTextDivView.style.textAlign = 'left';
			noteTextDivView.style.whiteSpace = 'nowrap';
			noteTextDivView.style.fontFamily = 'arial';
			noteTextDivView.style.border = '1px solid #DDEEFF';
			noteTextDivView.style.fontSize = '10px';
			noteTextDivView.style.marginTop = /msie/gi.test(navigator.userAgent) ? '0' : '-1px';
			noteTextDivView.style.padding = /msie/gi.test(navigator.userAgent) ? '0 0 2px 0' : '0 0 2px 0';
			noteTextDivView.style.cursor = 'default';
			noteTextDivView.onmouseover = function() {
				this.style.border = '1px solid #ccc';
			}
			noteTextDivView.onmouseout = function() {
				this.style.border = '1px solid #DDEEFF';
			}
			noteTextDivView.onclick= function() {
				me.showText();
			}
			box.appendChild(noteTextDivView);


			var noteTextDiv = document.createElement('div');
			noteTextDiv.id = 'tNoteTextDiv' + lID;
			noteTextDiv.style.display = 'none';
			noteTextDiv.style.width ='120px';
			noteTextDiv.style.marginTop = '-2px';
			noteTextDiv.style.paddingTop = '0';

			box.appendChild(noteTextDiv);

				// input text
				var noteText = document.createElement('input');
				noteText.id = "tTextNote"+lID;
				noteText.type = "text";
				noteText.maxLength = 255;
				noteText.style.height = '1.3em';
				noteText.style.background = '#FFFFDD';
				noteText.style.width = '120px';
				noteText.style.backgroundImage = '';
				noteText.style.padding = /msie/gi.test(navigator.userAgent) ? '1px 0 1px 1px' : '1px 0 1px 1px';
				noteText.style.fontFamily = 'arial';
				noteText.style.fontSize = '10px';
				noteText.style.border = '1px solid #ccc';
				noteText.value = this.note;

				noteText.onkeydown = function (ev) {
					me.isDirty = true;
					ev || (ev = window.event);
					var charCode = (ev.charCode) ? ev.charCode : ((ev.which) ? ev.which : ev.keyCode);
					if (charCode == 13) {
						if (this.value.length > 0) {
							me.save();
						}
					}
					return true;
				}

				noteText.onblur = function() {
					if ( me.isDirty ) {
						d('blur saving: ' + noteText.value);
						me.save();
					} else {
						d('blur hiding: ' + noteText.value);
						me.hideText();
					}
				}

				noteTextDiv.appendChild(noteText);
//}

    // add it all
    block.appendChild(box);
    eval('block.style.height=(20*' + ((lID > 0) ? 'ekTickerCounter' : 'ekGeneralTickerCounter') + ')+"px"');

}

//+--------------------------------------------------------------------------+
//| Timer Class                                                              |
//+--------------------------------------------------------------------------+
function Timer(){
	this.obj = (arguments.length)?arguments[0]:window;
	return this;
}

Timer.prototype.setInterval = function(func, msec){
	var i = Timer.getNew(this.obj.ID);
	var t = Timer.buildCall(this.obj, i, arguments);
	Timer.set[i].timer = window.setInterval(t,msec);
	return i;
}

Timer.prototype.setTimeout = function(func, msec){
	var i = Timer.getNew(this.obj.ID);
	Timer.buildCall(this.obj, i, arguments);
	Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec);
	return i;
}

Timer.prototype.clearInterval = function(i){
	if(!Timer.set[i]) { return; }
	window.clearInterval(Timer.set[i].timer);
	Timer.set[i] = null;
}

Timer.prototype.clearTimeout = function(i){
	if(!Timer.set[i]) { return; }
	window.clearTimeout(Timer.set[i].timer);
	Timer.set[i] = null;
}
Timer.prototype.checkRegister = function(i){
    return Timer.register[i];
}

Timer.set = new Array();
Timer.register = new Array();

Timer.buildCall = function(obj, i, args){
	var t = "";
	Timer.set[i] = new Array();
	if(obj != window){
		Timer.set[i].obj = obj;
		t = "Timer.set["+i+"].obj.";
	}
	t += args[0]+"(";
	if(args.length > 2){
		Timer.set[i][0] = args[2];
		t += "Timer.set["+i+"][0]";
		for(var j=1; (j+2)<args.length; j++){
			Timer.set[i][j] = args[j+2];
			t += ", Timer.set["+i+"]["+j+"]";
		}
	}
	t += ");";
	Timer.set[i].call = t;
	return t;
}

Timer.callOnce = function(i){
	if(!Timer.set[i]) { return; }
	eval(Timer.set[i].call);
	Timer.set[i] = null;
	Timer.register[i] = null;
}

Timer.getNew = function(){
	var i = 0;
	while(Timer.set[i]) { i++; }
	if (arguments.length) { Timer.register[i] = arguments[0]; }
	return i;
}

//+--------------------------------------------------------------------------+
//| Other functions                                                          |
//+--------------------------------------------------------------------------+

// leading zero
Number.lz = function(n){
	return (n > 9) ? ''+n : '0'+n;
}

function d(s){
	//$('t').innerHTML += '<br>' + s.toString();
}

