var disabled_timers = {timer_zone1:false,timer_zone2:false,timer_zone3:false}


function getServerTime()
{
	var d=new Date();
	d.setTime(d.getTime()+time_diff);
	return d;
}

function zero(x,size)
{
	if(!size)size=2;
	while(String(x).length < size)
		x='0'+x;
	return x;
}


function ms_to_hms(ms)
{
	var h=Math.floor(ms/(3600*1000));
	ms-=h*3600*1000;
	var m=Math.floor(ms/(60*1000));
	ms-=m*60*1000;
	var s=Math.floor(ms/1000);
	return zero(h)+':'+zero(m)+':'+zero(s);
}

function updateTimer(timer,from_to)
{
	var z1,z2,z3,till_ms,h,m,s,diff,time='00:00:00';
	var from=from_to[0], to=from_to[1], fromm=from_to[2], tom=from_to[3];
	if (!fromm) fromm=0;
	if (!tom) tom=0;
	var curr=getServerTime();
	var curr_h = curr.getHours(); 
	var curr_t = curr.getTime();
	
	if(curr_h >= from && curr_h < to)
	{
		curr.setHours(to);curr.setMinutes(tom);curr.setSeconds(0);
		till_ms = curr.getTime();
		time=ms_to_hms(till_ms-curr_t);
	}
	else if(curr_h > to)
	{
		disabled_timers[timer]=true;
	}
	
	$(timer).innerHTML=time;
}



function UpdateTimers()
{
	//8-15
	if(!disabled_timers.timer_zone1)
		updateTimer('timer_zone1',pickup_intervals.zone1);
	
	//8-12
	if(!disabled_timers.timer_zone2)
		updateTimer('timer_zone2',pickup_intervals.zone2);
		
	//8-10
	if(!disabled_timers.timer_zone3)
		updateTimer('timer_zone3',pickup_intervals.zone3);
	
	setTimeout('UpdateTimers()',1000);
	
	//reload page on new day
	if(getServerTime().getDate()!=curr_day)
		location.href=location.href;
	
}

var curr_day=getServerTime().getDate();

if(!pickup_holiday && !pickup_weekend)
	UpdateTimers();