﻿<!--
// copyright non specificato
function Calcola()
{	
	if(!CheckData())
		return;
	
	var Valore, Icilorda, Ici, DetrazioneEffettiva, Aliquota, RenditaCatastale
	
	RenditaCatastale = GetValue("renditacatastale").replace(",",".");
	Valore = (RenditaCatastale * 1.05) * GetValue("categoriacatastale");
	Aliquota = GetValue("Aliquota").replace(",",".");
	Icilorda = (Valore * Aliquota)/1000;
	DetrazioneEffettiva = GetValue("detrazioneabitazprincipale")/GetValue("proprietaridetrazione");
	
	Ici = (Icilorda/100) * GetValue("quotapossesso");
	Ici -= DetrazioneEffettiva;
	Ici = (Ici/12) * GetValue("mesipossesso"); 
	
	var obj=document.getElementById("totale");
	if(obj)
	obj.innerHTML = "<span class=pi>Totale ici annuale netta:</span> <span class=r>" + Math.round(Ici) + "&nbsp;&euro;</span>";
	
	obj=document.getElementById("acconto");
	if(obj)
	obj.innerHTML = "<span class=pi>Acconto del 50% da pagare a giugno:</span> <span class=r>" + Math.round(Ici/2) + "&nbsp;&euro;</span>";

             obj=document.getElementById("saldo");
	if(obj)
	obj.innerHTML = "<span class=pi>Saldo dell'altro 50% da versare a dicembre:</span> <span class=r>" + Math.round(Ici/2) + "&nbsp;&euro;</span>";	
	
	//alert(Ici);
	//alert(Math.round(Ici));
	
	ShowRisultato(true);
}

function Azzera()
{
	SetValue("Aliquota","");
	SetValue("renditacatastale","");
	SetValue("quotapossesso","100");
	SetValue("detrazioneabitazprincipale","0");
	SetValue("proprietaridetrazione","1");
	ShowRisultato(false);
}

function GetValue(id)
{
	var obj=document.getElementById(id);
	if(obj)
		return obj.value;
}

function SetValue(id,newvalue)
{
	var obj=document.getElementById(id);
	if(obj)
		obj.value=newvalue;
}

function ShowRisultato(bVisibility)
{
	var obj=document.getElementById("calcoloicionliney");
	if(obj)
	{
		if(bVisibility)
			obj.style.visibility = "visible";
		else	
			obj.style.visibility = "hidden";
	}
}

function CheckData()
{
	var TestValue;

             TestValue=GetValue("renditacatastale").replace(",",".");
	if (isNaN(TestValue)||(TestValue<=0))
	{
		alert("Inserisci la rendita catastale in modo corretto ! ");
		return false;
	}	

             TestValue=GetValue("Aliquota").replace(",",".");
	if (isNaN(TestValue)||(TestValue<=0))
	{
		alert("Inserisci una aliquota valida !");
		return false;
	}
	

             TestValue=GetValue("detrazioneabitazprincipale");
	if (isNaN(TestValue)||(TestValue<0))
	{
		alert("Detrazione prima casa non applicabile !");
		return false;
	}

	TestValue=GetValue("quotapossesso");
	if (isNaN(TestValue)||(TestValue<=0)||(TestValue>100))
	{
		alert("La percentuale di possesso non è valida !");
		return false;
	}	
	
			
	
	TestValue=GetValue("proprietaridetrazione");
	if (isNaN(TestValue)||(TestValue<=0))
	{
		alert("Il numero dei proprietari non è valido !");
		return false;
	}	

	if ((TestValue>1)&&(GetValue("quotapossesso")==100))
	{
		alert("Nel possesso al 100% il proprietario deve essere necessariamente uno solo !");
		return false;
	}	
	
	return true;
}
//-->
