//
// Created on: <20-Jul-2004 10:54:01 fh>
//
// SOFTWARE NAME: eZ Publish
// SOFTWARE RELEASE: 4.0.1
// BUILD VERSION: 22260
// COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
// SOFTWARE LICENSE: GNU General Public License v2.0
// NOTICE: >
//   This program is free software; you can redistribute it and/or
//   modify it under the terms of version 2.0  of the GNU General
//   Public License as published by the Free Software Foundation.
//
//
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of version 2.0 of the GNU General
//   Public License along with this program; if not, write to the Free
//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//   MA 02110-1301, USA.
//
//
            
/*! \file ezjsselection.js
*/


/*! 
    Invert the status of checkboxes named 'checkboxname' in form 'formname'.
    If you have a list of checkboxes name them with 'someName[]' in order to toggle them all.
*/
function ezjs_toggleCheckboxes( formname, checkboxname )
{
    with( formname )
	{
        for( var i=0; i<elements.length; i++ )
        {
            if( elements[i].type == 'checkbox' && elements[i].name == checkboxname && elements[i].disabled == "" )
            {
                if( elements[i].checked == true )
                {
                    elements[i].checked = false;
                }
                else
                {
                    elements[i].checked = true;
                }
            }
        }
    }
}


function calcola_mutuo_inpdap() {

var sconto = 1;
var errori = "";
var valore = document.getElementById('valore_inpdap').value;
var anni = document.getElementById('anni_inpdap').value;
var errore = 0;
document.getElementById('premio_inpdap').innerHTML = "";
document.getElementById('valore_inpdap').style.background = "#ffffff";
document.getElementById('anni_inpdap').style.background = "#ffffff";
document.getElementById('errori_mutuo_inpdap').style.display = "none";

valore = valore.replace(".", "");
valore = valore.replace(",", "");

if(!valore.match(/^\d+$/)) {
errore = 1;
errori = "il campo 'valore dell'immobile' non ha un formato corretto";
document.getElementById('valore_inpdap').style.background = "#FFB0B0";
}

if(errore == 0) {
if(parseFloat(valore) < 10000 || parseFloat(valore) > 2000000) {
errore = 1;
errori = "la somma da assicurare deve essere compresa tra 10.000&euro; e 200.000&euro;";
document.getElementById('valore_inpdap').style.background = "#FFB0B0";
}
}

if(errore == 0) {
if(!anni.match(/^\d+$/)) {
errore = 1;
errori = "il campo 'anni' non ha un formato corretto";
document.getElementById('anni_inpdap').style.background = "#FFB0B0";
}
}

if(errore == 0) {
if(parseFloat(anni) < 1 || parseFloat(anni) > 40) {
errore = 1;
errori = "la durata del mutuo deve essere compresa tra 1 e 30 anni";
document.getElementById('anni_inpdap').style.background = "#FFB0B0";
}
}

if(errore == 0) {
var totale = 0;
totale = ((valore * anni * 0.19)/1000)*sconto;
var premio_finale = parseFloat(totale);
if(premio_finale > 10) {
premio_finale = Math.ceil(premio_finale*100)/100;
premio_finale = Math.round(premio_finale);
premio_finale = premio_finale.toString();
premio_finale = premio_finale+ "";


document.getElementById('premio_inpdap').innerHTML = 'Il premio &egrave;<br/><span id="testo_premio">'+premio_finale+'&euro;<sup style="font-size: 13px; vertical-align: top;">*</sup></span><p>*premio unico per tutta<br/>la durata del mutuo</p><a style="margin: 8px auto;" href="/index.php/ita/Assicurazione-casa-mutuo/Mutuo-INPDAP" class="btt_entra">ACQUISTA ORA</a>';


} else {
errori = "il premio minimo &egrave; di 100&euro;: modifica la somma assicurata o la durata";
document.getElementById('anni_inpdap').style.background = "#FFB0B0";
document.getElementById('valore_inpdap').style.background = "#FFB0B0";
document.getElementById('errori_mutuo_inpdap').innerHTML = errori;
document.getElementById('errori_mutuo_inpdap').style.display = "block";
}
} else {
document.getElementById('errori_mutuo_inpdap').style.display = "block";
document.getElementById('errori_mutuo_inpdap').innerHTML = errori;
}

}


function calcola_mutuo_banca() {

var sconto = 1;
var errori = "";
var valore = document.getElementById('valore_banca').value;
var anni = document.getElementById('anni_banca').value;
var errore = 0;
document.getElementById('premio_banca').innerHTML = "";
document.getElementById('valore_banca').style.background = "#ffffff";
document.getElementById('anni_banca').style.background = "#ffffff";
document.getElementById('errori_mutuo_banca').style.display = "none";

valore = valore.replace(".", "");
valore = valore.replace(",", "");

if(!valore.match(/^\d+$/)) {
errore = 1;
errori = "il campo 'valore dell'immobile' non ha un formato corretto";
document.getElementById('valore_banca').style.background = "#FFB0B0";
}

if(errore == 0) {
if(parseFloat(valore) < 10000 || parseFloat(valore) > 2000000) {
errore = 1;
errori = "la somma da assicurare deve essere compresa tra 10.000&euro; e 200.000&euro;";
document.getElementById('valore_banca').style.background = "#FFB0B0";
}
}

if(errore == 0) {
if(!anni.match(/^\d+$/)) {
errore = 1;
errori = "il campo 'anni' non ha un formato corretto";
document.getElementById('anni_banca').style.background = "#FFB0B0";
}
}

if(errore == 0) {
if(parseFloat(anni) < 1 || parseFloat(anni) > 40) {
errore = 1; 
errori = "la durata del mutuo deve essere compresa tra 1 e 30 anni";
document.getElementById('anni_banca').style.background = "#FFB0B0";
}
}

if(errore == 0) { 
var totale = 0;
totale = ((valore * anni * 0.07)/1000)*sconto;
if (totale < 200) {
	totale = 200;
}	
var premio_finale = parseFloat(totale);
if(premio_finale > 10) {
premio_finale = Math.ceil(premio_finale*100)/100;
premio_finale = Math.round(premio_finale);
premio_finale = premio_finale.toString();
premio_finale = premio_finale+ "";


document.getElementById('premio_banca').innerHTML = 'Il premio &egrave;<br/><span id="testo_premio">'+premio_finale+'&euro;<sup style="font-size: 13px; vertical-align: top;">*</sup></span><p>*premio unico per tutta<br/>la durata del mutuo</p><a style="margin: 8px auto;" href="/index.php/ita/Assicurazione-casa-mutuo/Mutuo-Banca" class="btt_entra">ACQUISTA ORA</a>';


} else {
errori = "il premio minimo &egrave; di 100&euro;: modifica la somma assicurata o la durata";
document.getElementById('anni_banca').style.background = "#FFB0B0";
document.getElementById('valore_banca').style.background = "#FFB0B0";
document.getElementById('errori_mutuo_banca').innerHTML = errori;
document.getElementById('errori_mutuo_banca').style.display = "block";
}
} else {
document.getElementById('errori_mutuo_banca').style.display = "block";
document.getElementById('errori_mutuo_banca').innerHTML = errori;
}

}


function ripristina (campo) {
campo.style.background = "#FFFFFF";
}



