// Object is deprecated, used only for compatibility
function cbCounter(container, object, servertimestring, targetdate, mode, auctionended, days, hours, minutes, seconds) {
	if (!document.getElementById || !document.getElementById(container)) return

	if (!document.getElementById(container)) return
	this.container = document.getElementById(container)

	this.localtime = this.serverdate = new Date(servertimestring)

	this.targetdate = new Date(targetdate)
	this.mode = mode
	this.auctionended = auctionended
	this.days = days
	this.hours = hours
	this.minutes = minutes
	this.seconds = seconds
	this.timesup = false
	this.autoUpdateTime()
}

cbCounter.prototype.autoUpdateTime=function() {
	var thisobj = this
	this.localtime.setSeconds(this.localtime.getSeconds() + 1)
	setTimeout(function(){thisobj.autoUpdateTime()}, 1000)
}

cbCounter.prototype.updateTime=function(functionref) {
	this.formatresults = functionref ? functionref : formatresults
	this.showresults()
}

cbCounter.prototype.showresults=function() {
	var thisobj = this

	var timediff = (this.targetdate-this.localtime)/1000 //difference btw target date and current date, in seconds
	if (timediff<0){ //if time is up
		this.timesup = true
		this.container.innerHTML = this.formatresults()
		return
	}
	var oneMinute = 60 			//minute unit in seconds
	var oneHour = 60 * 60 		//hour unit in seconds
	var oneDay = 60 * 60 * 24 	//day unit in seconds
	var dayfield = Math.floor(timediff/oneDay)
	var hourfield = Math.floor((timediff-dayfield*oneDay)/oneHour)
	var minutefield = Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
	var secondfield = Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))

	this.container.innerHTML = this.formatresults(dayfield, hourfield, minutefield, secondfield)
	setTimeout(function(){thisobj.showresults()}, 1000)
}

function formatresults(){
		if (this.timesup == false) { //if target date/time not yet met
			var displaystring = "<span>";
			if ((arguments[0] == 0) && (arguments[1] == 0)) {
				displaystring += "<font>"
			}
			if (arguments[0] > 0 || this.mode != "hideempty") {
				displaystring += arguments[0] + this.days + " "
			}
			if (((arguments[0] > 0) || (arguments[1] > 0)) || this.mode != "hideempty") {
				displaystring += arguments[1] + this.hours + " "
			}
			displaystring += arguments[2] + this.minutes + " " + arguments[3] + this.seconds
			if ((arguments[0] == 0) && (arguments[1] == 0)) {
				displaystring += "</font>"
			}
			displaystring += "</span>"
		}
		else { //else if target date/time met
			var displaystring = "<font>" + this.auctionended + "</font>"
		}
		return displaystring
}

