var ids=new Array('uzsakymas');

function switchid(id){	
	hideallids();
	showdiv(id);
}

function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		hidediv(ids[i]);
	}		  
}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function show(id){
	   document.getElementById(id).style.visibility="visible";
	}

function hide(id){
	   document.getElementById(id).style.visibility="hidden";
	}



function startCalc(){
	interval = setInterval("calc()",1);
}
function calc(){
	
	var nuo = document.uzsakymoforma.nuo.value;
	var iki = document.uzsakymoforma.iki.value; 
	var motkaina = document.uzsakymoforma.motkaina.value; 
	
	var nuo = nuo.split("/");
	var iki = iki.split("/");
	
	var nuohh = document.uzsakymoforma.nuohh.value;
	var ikihh = document.uzsakymoforma.ikihh.value;
	
	var nuohh = nuohh.replace(":00", "");
	var ikihh = ikihh.replace(":00", "");
	
	//var skirtumas = (parseInt(ikihh[0]) - parseInt(nuohh[0])) * 3600000;
	
	var skirtumas = (ikihh - nuohh) * 3600000;
	
	var datanuo = new Date(nuo[2]+"/"+nuo[1]+"/"+nuo[0]);
	var dataiki = new Date(iki[2]+"/"+iki[1]+"/"+iki[0]);
	
	var dienos = ((dataiki - datanuo) + skirtumas) / (1000*60*60*24);
	skirtumas = Math.round(dienos);
	
	if (dienos > Math.round(dienos))
	{
		skirtumas = Math.round(dienos + 1);
	}

	mokesciai = document.uzsakymoforma.mokesciai.value; 
	
	suma = (skirtumas * motkaina) * mokesciai;
	
	if (suma < motkaina)
	{
		document.uzsakymoforma.bendrasuma.value = motkaina;
	}
	else
	{
		document.uzsakymoforma.bendrasuma.value = suma;
	}
}
function stopCalc(){
  clearInterval(interval);
}
