step = new Array();
step[0] = 300;
step[1] = 10000;
step[2] = 2000;
step[3] = 2000;
spi = new Array();
spi[0] = "";
spi[1] = "3,95&euro;";
spi[2] = "2,95&euro;";
spi[3] = "0,95&euro;";
function alcuni(obj) {
	if (obj.innerHTML == "Alcuni esempi") {
		obj.innerHTML = "Torna al calcolatore";
		document.getElementById("tab2").style.display = getDisplayForObj("TABLE");
		document.getElementById("spiego1").style.display = getDisplayForObj("TABLE");
		document.getElementById("spiego2").style.display = "none";
		document.getElementById("spiego3").style.display = "none";
		document.getElementById("tab1").style.display = "none";
		demo(1);
		for (x=0; x<7; x++) {
			document.getElementById("t"+x).src = "https://images.fineco.it/areapubblica/banking/newCalc/g.gif";
	
		}
	} else {
		obj.innerHTML = "Alcuni esempi";
		document.getElementById("tab1").style.display = getDisplayForObj("TABLE");
		document.getElementById("tab2").style.display = "none";
		document.getElementById("spiego1").style.display = "none";
		document.getElementById("spiego2").style.display = "none";
		document.getElementById("spiego3").style.display = "none";
		fullStip();
		
	}
}
function slide() {
	var stato = document.getElementById("subText").style.display;
	chi = "subText";
	if (stato == "none") {
		Effect.SlideDown(chi);
		//	$(chi).appear();
	} else {
		//$(chi).fade();
		Effect.SlideUp(chi);
	}
}
function vaiTot(caso){
var tasto_tot = 0
tasto_1 = parseFloat(document.getElementById("lab1").innerHTML.replace("€", ""));
	tasto_2 = parseFloat(document.getElementById("lab2").innerHTML.replace("€", ""));
	tasto_3 = parseFloat(document.getElementById("lab3").innerHTML.replace("€", ""));
	tasto_4 = parseFloat(document.getElementById("lab4").innerHTML.replace("€", ""));
	tasto_5 = parseFloat(document.getElementById("lab5").innerHTML.replace("€", ""));
	tasto_tot = tasto_1+tasto_2+tasto_3+tasto_4+tasto_5;

if (caso == 1 && tasto_tot > 5){
tasto_tot = "Gratis"
}



return tasto_tot
}

function modify(direz, indice) {
stop = vaiTot(0)


var myStep = step[indice];
var now = document.getElementById("sub"+indice).innerHTML;
	var lab = indice+2
	now = now.replace(".", "");
	now = parseInt(now);


if (direz == 1 && stop < 5.95){
valoreSub = now + myStep
	scalo = myStep/step[indice];
	scalo = parseFloat (document.getElementById("lab"+lab).innerHTML) + scalo
	if (stop == 5 ){
	
  scalo = scalo  -1  + 0.95

  }
  else {
  scalo = Math.ceil(scalo)

  } 
if (scalo < 6){
document.getElementById("sub"+indice).innerHTML =  ff(valoreSub) +"&euro;"
document.getElementById("lab"+lab).innerHTML  = scalo + "&euro;"
}
}


if (direz == -1 ){



valoreSub = now - myStep
	scalo = myStep/step[indice];
	scalo = parseFloat (document.getElementById("lab"+lab).innerHTML) - scalo
	if (scalo == 6 ){
  scalo = 5.95
  }
  else {
  scalo = Math.ceil(scalo)
  } 

if (scalo >= 0){
if (vaiTot(0) > 5 ){sistema()}

document.getElementById("sub"+indice).innerHTML = ff(valoreSub) +"&euro;"
document.getElementById("lab"+lab).innerHTML  = scalo+"&euro;"
}
}

updateTot()
}

function sistema(){
var  tasto = 0 
for (x=1 ; x < 6 ; x++){
tasto = parseFloat(document.getElementById("lab"+x).innerHTML.replace("€", ""));


document.getElementById("lab"+x).innerHTML = Math.ceil(tasto) +"&euro;"

}
}


function versamento() {
	var versamento = valoreradio("versi");
	risutato = document.getElementById("effettivo").innerHTML;
	if (versamento == 0) {
		valore = "0";
		posiz = "5px 10px";
		colore = "#666666";
		disp = getDisplayForObj("TR");
		costo = "5,95";
	/*	val2 = Math.floor(document.getElementById("lab2").innerHTML.replace("€", ""));
		val3 = Math.floor(document.getElementById("lab3").innerHTML.replace("€", ""));
		val4 = Math.floor(document.getElementById("lab4").innerHTML.replace("€", ""));
		val5 = Math.floor(document.getElementById("lab5").innerHTML.replace("€", ""));
		document.getElementById("lab2").innerHTML = val2+"&euro;";
		document.getElementById("lab3").innerHTML = val3+"&euro;";
		document.getElementById("lab4").innerHTML = val4+"&euro;";
		document.getElementById("lab5").innerHTML = val5+"&euro;";
	*/
		sistema()
	} else {
		disp = "none";
		posiz = "-70px 10px";
		costo = "0";
		colore = "#fff";
		if (risutato == "0,95€") {
			valore = "-0,95";
		} else if (risutato == "Gratis") {
			valore = "0";
			document.azzera.versi[1].checked = true;
			//alert("Attenzione hai gia' raggiunto la soglia richiesta");
			colore = "#666666";
			posiz = "5px 10px";
		} else {
			valore = "1";
			if (vaiTot(1)==5){
      valore = 0.95
      }
		}
	}
	document.getElementById("lab1").innerHTML = valore+"&euro;";
	document.getElementById("TDlab1").style.backgroundPosition = posiz;
	document.getElementById("lab1").style.color = colore;
	updateTot();
}
function updateTot(){
var now = 0
for (x=1; x<6; x++) {
now = parseFloat(document.getElementById("lab"+x).innerHTML)
if (now > 0){
document.getElementById("TDlab"+x).style.backgroundPosition  = "-70px 10px"; 
document.getElementById("lab"+x).style.color   ="#fff"
document.getElementById("prelab"+x).innerHTML = "-"
} else {
document.getElementById("TDlab"+x).style.backgroundPosition  = "5px 10px"; 
document.getElementById("lab"+x).style.color   ="#666666"
document.getElementById("prelab"+x).innerHTML = ""
}




}
var eff = vaiTot(1)
if (eff != "Gratis"){
 eff = 5.95 - eff
 eff = parseInt(eff * 100)/100

 eff = eff + "&euro;"
 disabilitaTasti("fDx.png","dx")
 
 
} else {
disabilitaTasti("fDx-d.png","dx")
}
document.getElementById("effettivo").innerHTML = eff
var barre = vaiTot(0);
if(barre > 6) {
barre = 6;
}
for (x=0; x<6; x++) {
			if (x<barre) {
				document.getElementById("t"+x).src = "https://images.fineco.it/areapubblica/banking/newCalc/tx1.gif";
			} else {
				document.getElementById("t"+x).src = "https://images.fineco.it/areapubblica/banking/newCalc/tx0.gif";
			}
		}

for (w = 0; w < 4 ; w++){
  var numero = document.getElementById("sub"+w).innerHTML
  numero = numero.replace("&euro;" , "")
  numero = numero.replace("€" , "")

  if (numero == "0"){
  ww = w + 1
  document.getElementById("sx"+ww).src = "https://images.fineco.it/areapubblica/banking/newCalc/fSx-d.png"
  //disabilitaTasti("fSx.png","sx")
  } else{
  ww = w + 1
  document.getElementById("sx"+ww).src = "https://images.fineco.it/areapubblica/banking/newCalc/fSx.png"
  
  }
  
}

}


function fullStip() {
	var stipendio = valoreradio("stipendio");
	
document.getElementById("t6").src = "https://images.fineco.it/areapubblica/banking/newCalc/fine.gif";
	if (stipendio == 0) {
		valore = "0&euro;";
		posiz = "5px 10px";
		colore = "#666666";
		disp = getDisplayForObj("TR");
		costo = "5,95";
	} else {
		disp = "none";
		posiz = "-70px 10px";
		costo = "0";
		valore = "-5,95&euro;";
		colore = "#fff";
		for (x=0; x<6; x++) {
			document.getElementById("t"+x).src = "https://images.fineco.it/areapubblica/banking/newCalc/tx1.gif";
		}
			
	}
	for (x=1; x<6; x++) {
		document.getElementById("row"+x).style.display = disp;
	}
	document.getElementById("lab0").innerHTML = valore;
	if (costo == 0) {
		costo = "Gratis";
		
	}
	document.getElementById("effettivo").innerHTML = costo;
	document.getElementById("TDlab0").style.backgroundPosition = posiz;
	document.getElementById("lab0").style.color = colore;
	//
	if (stipendio == 0){
  updateTot();
  }
	if (document.esempio == 0) {
	myLog("SI")
		esempio();
	}
}
function esempio() {

  document.esempio = 1;
}
function init() {
	fullStip();
	//versamento();
	myLog("W")
	document.esempio = 1;
}
function valoreradio(nome) {
	var x = 0;
	do {
		if (document.getElementsByName(nome)[x].checked) {
			var valore = document.getElementsByName(nome)[x].value;
			x = document.getElementsByName(nome).length+1;
		}
		x++;
	} while (x<document.getElementsByName(nome).length);
	return valore;
}
function getDisplayForObj(tag) {
	if (document.all) {
		disp = "";
	} else {
		switch (tag) {
		case "TABLE" :
			var disp = "table";
			break;
		case "TR" :
			var disp = "table-row";
			break;
		case "A" :
			var disp = "inline";
			break;
		default :
			var disp = "block";
			break;
		}
	}
	return disp;
}
function demo(nr) {
	for (x=1; x<4; x++) {
		document.getElementById("spr"+x).style.display = "none";
		document.getElementById("spiego"+x).style.display = "none";
	}
	document.getElementById("spr"+nr).style.display = getDisplayForObj("TR");
	document.getElementById("spiego"+nr).style.display = getDisplayForObj("TABLE");
	document.getElementById("effettivo").innerHTML = spi[nr];
}

function finito(stato,obj){
var dove = obj.getAttribute("id")
dove = dove.substring(2,3)
var vai = document.getElementById("effettivo").innerHTML
vai = vai.toLowerCase()
if (stato == 1 && vai == "gratis"){
document.getElementById("baseEr"+dove).style.visibility = "visible"
}
if (stato == 0 && vai == "gratis"){
document.getElementById("baseEr"+dove).style.visibility = "hidden"
}
}
function finitoRadio(stato){

var vai = document.getElementById("effettivo").innerHTML
vai = vai.toLowerCase()
if (stato == 1 && vai == "gratis"){
document.getElementById("baseEr1").style.visibility = "visible"
}
if (stato == 0 && vai == "gratis"){
document.getElementById("baseEr1").style.visibility = "hidden"
}
}


function disabilitaTasti(stato,direz){

for (y = 1 ; y < 5 ; y ++ ){

document.getElementById(direz+y).src = "https://images.fineco.it/areapubblica/banking/newCalc/" + stato
}
}


function ff(nStr){
nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}

	return x1 + x2;

}

function myLog(str){
document.getElementById("log").innerHTML = str + " | " + document.getElementById("log").innerHTML

}
