var stopTime1 = false;
var stopTime2 = false;
var stopTime3 = false;
var stopTime4 = false;

var start1=new Date();
var start2=new Date();
var start3=new Date();
var start4=new Date();

var isConferma = false;
var counts=120;

function SetConferma(conferma)
{
	isConferma = conferma;
}

function SetSeconds(seconds)
{
	counts = seconds;
}

function SetStart1()
{
	var ora = new Date();
	start1=Date.parse(ora)/1000;
}

function SetStart2()
{
	var ora = new Date();
	start2=Date.parse(ora)/1000;
}

function SetStart3()
{
	var ora = new Date();
	start3=Date.parse(ora)/1000;
}

function SetStart4()
{
	var ora = new Date();
	start4=Date.parse(ora)/1000;
}

function CountDown(myStart, myClock, myTimer, myStopTimer)
{
	var now = new Date();
	now = Date.parse(now) / 1000;
	var x = parseInt(counts-(now-myStart),10);
	
	if (document.form && myStopTimer == false)
	{
		myClock.value = x;
	}
	
	if (x > 0)
	{
		return true;
	}
	else
	{
	   if (myStopTimer == false)
	   {
		 myTimer.style.display = 'none';		 		
	   }	   	   	  
	   //console.log(document.getElementById('result1').textContent);	   
	   
	   //document.getElementById('result1').textContent = "Corsa Stornata.";
	   	   
	   //console.log(document.getElementById('result1').textContent);
	}
}

function CountDown1()
{
	if (CountDown(start1, document.form.clock1, document.getElementById('timer1'), stopTime1))
	{
		setTimeout("CountDown1()", 100);
	}
	else if (isConferma)
	{
		document.getElementById('result1').textContent = "Corsa Stornata";
	}
}

function CountDown2()
{
	if (CountDown(start2, document.form.clock2, document.getElementById('timer2'), stopTime2))
	{
		setTimeout("CountDown2()", 100);
	}
	else if (isConferma)
	{
		document.getElementById('result2').textContent = "Corsa Stornata";
	}
}

function CountDown3()
{
	if (CountDown(start3, document.form.clock3, document.getElementById('timer3'), stopTime3))
	{
		setTimeout("CountDown3()", 100);
	}
	else if (isConferma)
	{
		document.getElementById('result3').textContent = "Corsa Stornata";
	}	
}

function CountDown4()
{
	if (CountDown(start4, document.form.clock4, document.getElementById('timer4'), stopTime4))
	{
		setTimeout("CountDown4()", 100);
	}
	else if (isConferma)
	{
		document.getElementById('result1').textContent = "Corsa Stornata";
	}	
}
	
function setStopTime1()
{
   stopTime1 = true;
}

function setStopTime2()
{
   stopTime2 = true;
}

function setStopTime3()
{
   stopTime3 = true;
}

function setStopTime4()
{
   stopTime4 = true;
}
