function getCookie(NameOfCookie){
	if (document.cookie.length > 0) {
		begin = document.cookie.indexOf(NameOfCookie+"=");
	if (begin != -1){
		begin += NameOfCookie.length+1;
		end = document.cookie.indexOf(";", begin);
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(begin, end)); }
	}
	return null;
}

function returnSelection(radioButton) {
	var selection=null;
	for(var i=0; i<radioButton.length; i++) {
		 if(radioButton[i].checked) {
		   selection=radioButton[i].value;
		   return selection;
		 }
	}
	return selection;
}

// preload images
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// switch images
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features){
  window.open(theURL,winName,features);
}

// openWindow('urlPage', 'namePopup', 'width', 'height', 'yes/no', 'yes/no');
function openWindow(mypage,myname,w,h,resizable,scrollbars){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'scrollbars='+scrollbars+',resizable='+resizable+',height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition;
	win = window.open(mypage,myname,settings);
}

/* clock script */
var timerID = null
var timerRunning = false

function stopclock(){
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function startclock(){
    stopclock()
    showtime()
}

function showtime(){
    var now = new Date();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds();
    var timeValue = "" + hours;
    timeValue  += ((minutes < 10) ? ":0" : ":") + minutes;
    timeValue  += ((seconds < 10) ? ":0" : ":") + seconds;
    document.clock.face.value = timeValue;
    timerID = setTimeout("showtime()",1000);
    timerRunning = true;
}
/* clock script */

/* function correct date */
function areCharsInList(s,list) {
	var i,c;
	for (i=0;i<s.length; i++) {
		c = s.charAt(i);
	if (list.indexOf(c) == -1)
		return false;
	}
return true;
}

function isDate(str){
	if(str.length!=10){
		return false;
	}
	if(str.charAt(2)!='/' || str.charAt(5)!='/'){
		return false;
	}
	if( !areCharsInList(str.substring(0,2)+str.substring(3,5)+str.substring(6,10), '1234567890') ){
		return false;
	}
	if(str.substring(3,5)>12){
		return false;
	}
	if(str.substring(0,2)>31){
		return false;
	}
return true;
}
/* function correct date */




function trunc(s, npos)
{
	var t = "0.0";
	var tail = "";
	var strs = ("" + s).split(".");

	if (strs.length > 1) {
		if (strs[1].length >= npos)
			t = strs[0] + "." + strs[1].substring(0, npos);
		else {
			for (var i = 0; i < npos - strs[1].length; i++)
				tail += "0";
			t = strs[0] + "." + strs[1] + tail;
		}
	}
	else {
		for (var i = 0; i < npos; i++)
			tail += "0";
		t = strs[0] + "." + tail;
	}

	return Number(t);
}

function calcolo_lunga_perm_p4( text, form )
{
	//Controlla che siano inseriti soltanto numeri o '.'
	var ultima = text.value.charAt(text.value.length-1);
	if ( ultima != '0' && ultima != '1' && ultima != '2' && ultima != '3' && ultima != '4' && ultima != '5' && ultima != '6' && ultima != '7' && ultima != '8' && ultima != '9' && ultima != '.' ) {
		var aux = text.value;
		text.value = '';

		var i;
		for ( i=0; i<aux.length-1; i++ )
			text.value += aux.charAt(i);
	}

		var time = 0; //tempo totale in minuti
		if ( form.giorni_lunga.value != '' )
			time = (parseFloat(form.giorni_lunga.value) * 24 * 60);
			
		if ( form.ore_lunga.value != '' )
			time += (Math.ceil(parseFloat(form.ore_lunga.value)) * 60);
			
		if ( form.minuti_lunga.value != '' )
			time += Math.ceil(parseFloat(form.minuti_lunga.value));

		if (time == 0) {
			form.importo_lunga.value = "—";
			return 0;
		}

		//da 0 a 10 minuti
		if (time <= 10) {
			form.importo_lunga.value = "Gratis";
			return 0;
		}

		//da 10 minuti a 1 ora
		if (time <= 60) {
			form.importo_lunga.value = "2,00";
			return 0;
		}

		//da 1 ora e 2 ore
		if (time <= 120) {
			form.importo_lunga.value = "3,00 €";
			return 0;
		}

		//da 2 ora e 3 ore
		if (time <= 180) {
			form.importo_lunga.value = "4,00 €";
			return 0;
		}

		//da 3 ora e 4 ore
		if (time <= 240) {
			form.importo_lunga.value = "5,00 €";
			return 0;
		}

		//da 4 ora e 5 ore
		if (time <= 300) {
			form.importo_lunga.value = "6,00 €";
			return 0;
		}

		//da 5 ora e 6 ore
		if (time <= 360) {
			form.importo_lunga.value = "7,00 €";
			return 0;
		}

		//da 6 ora e 7 ore
		if (time <= 420) {
			form.importo_lunga.value = "8,00 €";
			return 0;
		}

		//da 7 ora e 8 ore
		if (time <= 480) {
			form.importo_lunga.value = "9,00 €";
			return 0;
		}

		//da 8 ora e 9 ore
		if (time <= 540) {
			form.importo_lunga.value = "10,00 €";
			return 0;
		}

		//da 9 ora e 10 ore
		if (time <= 600) {
			form.importo_lunga.value = "11,00 €";
			return 0;
		}

		//da 10 ora e 11 ore
		if (time <= 660) {
			form.importo_lunga.value = "12,00 €";
			return 0;
		}

		//da 11 ora e 12 ore
		if (time <= 720) {
			form.importo_lunga.value = "13,00 €";
			return 0;
		}
		
		// dalla 12 ore
		if (time > 720) {
			var altro = (Math.ceil(((time-720) / 60) / 1) * 0.5)+13;
			
			var imp = altro+",00 €";
			
			form.importo_lunga.value = imp.replace(".5,00", ",50");
			return 0;
		}

/*
		//Inizio secondo giorno
		total = 9;
		time -= 24;
		if (time >= 24) {
			time -= 24;
			total += 8;
		}else {
			total += trunc(Math.ceil(time / 6) * 2, 2);
			time = 0;
		}

		//terzo giorno
		if (time >= 48) {
			time -= 48;
			total += 12;
		}else {
			total += trunc(Math.ceil(time / 24) * 7, 2);
			time = 0;
		}

		//quarto giorno
		if (time >= 72) {
			time -= 72;
			total += 12;
		}else {
			total += trunc(Math.ceil(time / 24) * 6, 2);
			time = 0;
		}

		//dal quinto giorno
		if (time > 0) {
			total += trunc(Math.ceil(time / 24) * 4, 2);
		}
		form.importo_lunga.value = total + " €";
		*/
}


function calcolo_breve_perm_p2( text, form )
{
	//Controlla che siano inseriti soltanto numeri o '.'
	var ultima = text.value.charAt(text.value.length-1);
	if ( ultima != '0' && ultima != '1' && ultima != '2' && ultima != '3' && ultima != '4' && ultima != '5' && ultima != '6' && ultima != '7' && ultima != '8' && ultima != '9' && ultima != '.' ) {
		var aux = text.value;
		text.value = '';

		var i;
		for ( i=0; i<aux.length-1; i++ )
			text.value += aux.charAt(i);
	}

		var time = 0; //tempo totale in minuti
		if ( form.giorni_lunga.value != '' )
			time = (parseFloat(form.giorni_lunga.value) * 24 * 60);
			
		if ( form.ore_lunga.value != '' )
			time += (Math.ceil(parseFloat(form.ore_lunga.value)) * 60);
			
		if ( form.minuti_lunga.value != '' )
			time += Math.ceil(parseFloat(form.minuti_lunga.value));

		if (time == 0) {
			form.importo_lunga.value = "—";
			return 0;
		}

		//primi 15 minuti
		if (time <= 15) {
			form.importo_lunga.value = "Gratis";
			return 0;
		}

		//da 16 minuti a 30 min
		if (time <= 30) {
			form.importo_lunga.value = "1,00 €";
			return 0;
		}

		//da 31 minuti a 1 ora
		if (time <= 60) {
			form.importo_lunga.value = "3,00 €";
			return 0;
		}

		//da 1 ora e 2 ore
		if (time <= 120) {
			form.importo_lunga.value = "5,00 €";
			return 0;
		}

		//da 2 ora e 3 ore
		if (time <= 180) {
			form.importo_lunga.value = "7,00 €";
			return 0;
		}

		//da 3 ora e 4 ore
		if (time <= 240) {
			form.importo_lunga.value = "9,00 €";
			return 0;
		}

		//da 4 ora e 5 ore
		if (time <= 300) {
			form.importo_lunga.value = "10,00 €";
			return 0;
		}

		//da 5 ora e 6 ore
		if (time <= 360) {
			form.importo_lunga.value = "11,00 €";
			return 0;
		}

		//da 6 ora e 7 ore
		if (time <= 420) {
			form.importo_lunga.value = "12,00 €";
			return 0;
		}

		//da 7 ora e 8 ore
		if (time <= 480) {
			form.importo_lunga.value = "13,00 €";
			return 0;
		}

		//da 8 ora e 24 ore
		if (time <= 1440) {
			form.importo_lunga.value = "14,00 €";
			return 0;
		}

		// 2 girono
		if (time <= 2880) {
			form.importo_lunga.value = "26,00 €";
			return 0;
		}
		
		// 3 girono
		if (time <= 4320) {
			form.importo_lunga.value = "36,00 €";
			return 0;
		}
		
		// 4 girono
		if (time <= 5760) {
			form.importo_lunga.value = "44,00 €";
			return 0;
		}
		
		// 5 girono
		if (time <= 7200) {
			form.importo_lunga.value = "50,00 €";
			return 0;
		}
		
		// dal 6 girono
		if (time > 7200) {
			var altro = (Math.ceil((time-7200) / 60 / 24) * 6)+50;
			
			var imp = altro+",00 €";
			
			form.importo_lunga.value = imp;
			return 0;
		}

/*
		//Inizio secondo giorno
		total = 9;
		time -= 24;
		if (time >= 24) {
			time -= 24;
			total += 8;
		}else {
			total += trunc(Math.ceil(time / 6) * 2, 2);
			time = 0;
		}

		//terzo giorno
		if (time >= 48) {
			time -= 48;
			total += 12;
		}else {
			total += trunc(Math.ceil(time / 24) * 7, 2);
			time = 0;
		}

		//quarto giorno
		if (time >= 72) {
			time -= 72;
			total += 12;
		}else {
			total += trunc(Math.ceil(time / 24) * 6, 2);
			time = 0;
		}

		//dal quinto giorno
		if (time > 0) {
			total += trunc(Math.ceil(time / 24) * 4, 2);
		}
		form.importo_lunga.value = total + " €";
		*/
}



function calcolo_breve_perm( text, form )
{
	//Controlla che siano inseriti soltanto numeri o '.'
	var ultima = text.value.charAt(text.value.length-1);

	if ( ultima != '0' && ultima != '1' && ultima != '2' && ultima != '3' && ultima != '4' && ultima != '5' && ultima != '6' && ultima != '7' && ultima != '8' && ultima != '9' && ultima != '.' ) {
		var aux = text.value;
		text.value = '';

		var i;
		for ( i=0; i<aux.length-1; i++ )
			text.value += aux.charAt(i);
			
	}

		var time = 0; //tempo totale in minuti
		if ( form.giorni_breve && form.giorni_breve.value != '' )
			time = (parseFloat(form.giorni_breve.value) * 24 * 60);
			
		if ( form.ore_breve.value != '' )
			time += (Math.ceil(parseFloat(form.ore_breve.value)) * 60);
			
		if ( form.minuti_breve.value != '' )
			time += Math.ceil(parseFloat(form.minuti_breve.value));

		//primi 16 minuti
		if (time <= 15) {
			form.importo_breve.value = "Gratis";
			return 0;
		}

		//primi 30 minuti
		if (time <= 30) {
			form.importo_breve.value = "1,00 €";
			return 0;
		}

		//1 ora
		if (time <= 60) {
			form.importo_breve.value = "3,00 €";
			return 0;
		}

		//2 ora
		if (time <= 120) {
			form.importo_breve.value = "5,00 €";
			return 0;
		}

		//3 ora
		if (time <= 180) {
			form.importo_breve.value = "7,00 €";
			return 0;
		}

		//4 ora
		if (time <= 240) {
			form.importo_breve.value = "9,00 €";
			return 0;
		}

		//da 5
		if (time <= 300) {
			form.importo_breve.value = "10,00 €";
			return 0;
		}

		//dalla 12 ora in poi
		if (time > 300) {
			var altro = (Math.ceil(((time-300) / 60) / 1) * 1)+10;
			
			var imp = altro+",00 €";
			
			form.importo_breve.value = imp.replace(".5,00", ",50");
			return 0;
		}
}

function calcolo_breve_perm_blu( text, form )
{
	//Controlla che siano inseriti soltanto numeri o '.'
	var ultima = text.value.charAt(text.value.length-1);

	if ( ultima != '0' && ultima != '1' && ultima != '2' && ultima != '3' && ultima != '4' && ultima != '5' && ultima != '6' && ultima != '7' && ultima != '8' && ultima != '9' && ultima != '.' ) {
		var aux = text.value;
		text.value = '';

		var i;
		for ( i=0; i<aux.length-1; i++ )
			text.value += aux.charAt(i);
			
	}

		var time = 0; //tempo totale in minuti
		if ( form.giorni_breve && form.giorni_breve.value != '' )
			time = (parseFloat(form.giorni_breve.value) * 24 * 60);
			
		if ( form.ore_breve.value != '' )
			time += (Math.ceil(parseFloat(form.ore_breve.value)) * 60);
			
		if ( form.minuti_breve.value != '' )
			time += Math.ceil(parseFloat(form.minuti_breve.value));

		//primi 16 minuti
		if (time == 0) {
			form.importo_breve.value = "—";
			return 0;
		}
		if (time <= 10) {
			form.importo_breve.value = "0,50";
			return 0;
		}

		//1 ora
		if (time <= 60) {
			form.importo_breve.value = "3,00 €";
			return 0;
		}

		//2 ora
		if (time <= 120) {
			form.importo_breve.value = "5,00 €";
			return 0;
		}

		//3 ora
		if (time <= 180) {
			form.importo_breve.value = "7,00 €";
			return 0;
		}

		//4 ora
		if (time <= 240) {
			form.importo_breve.value = "10,00 €";
			return 0;
		}

		//da 6
		if (time <= 360) {
			form.importo_breve.value = "15,00 €";
			return 0;
		}

		//da 12
		if (time <= 720) {
			form.importo_breve.value = "20,00 €";
			return 0;
		}

		//da 24
		if (time <= 1440) {
			form.importo_breve.value = "35,00 €";
			return 0;
		}
}
