// copyright Alessandro Reggiani 2001 
// biologico versione 1.1

function ce () {

var giorni1 = parseFloat(document.modulo.D1.options.value)
var mesi1 = parseFloat(document.modulo.D2.options.value)*30.0
var anni1 = parseFloat(document.modulo.T4.value)*365.0
data1 = giorni1+mesi1+anni1

var giorni2 = parseFloat(document.modulo.D7.options.value)
var mesi2 = parseFloat(document.modulo.D8.options.value)*30.0
var anni2 = parseFloat(document.modulo.T5.value)*365.0
data2 = giorni2+mesi2+anni2

contofinale = (data2-data1)/365

document.modulo.eta.value=Math.round(100.0*contofinale)/100.0
}


function biologico () {

var a = document.modulo.eta.value.replace(",",".")
if (a <= 10){document.modulo.coeff2.value = 1}
else if (a > 10){document.modulo.coeff2.value = (a-10)*0.005}

var b = (document.modulo.punti.value).replace(",",".")
if (b == 1) {document.modulo.coeff1.value = 1}
else if (b == 2) {document.modulo.coeff1.value = 1.1}
else if (b == 3) {document.modulo.coeff1.value = 1.2}
else if (b == 4) {document.modulo.coeff1.value = 1.3}
else if (b == 5) {document.modulo.coeff1.value = 1.5}
else if (b == 6) {document.modulo.coeff1.value = 1.7}
else if (b == 7) {document.modulo.coeff1.value = 1.9}
else if (b == 8) {document.modulo.coeff1.value = 2.1}
else if (b == 9) {document.modulo.coeff1.value = 2.3}


var i = parseFloat(document.modulo.coeff1.value)
var l = parseFloat(document.modulo.coeff2.value)
var z = (Math.round(100*(parseFloat(688.28)))/100) * i
if (a <= 10){document.modulo.bp.value =  Math.round(100*(parseFloat(688.28) *  l * i * b))/100}
else if (a > 10){document.modulo.bp.value = Math.round(100*((z - (z*l))*b))/100}


var c = document.modulo.ggitt.value
document.modulo.itt.value = Math.round(100*((parseFloat(c) * parseFloat(40.16))))/100

var d = document.modulo.ggitp.value
var dd = document.modulo.ggitp1.value
var ddd = parseFloat(dd) * parseFloat(10.04)
var dddd = Math.round(100*((parseFloat(d) * parseFloat(20.08))))/100.0+ddd
document.modulo.itp.value = Math.round(100*dddd)/100.0

var e = document.modulo.itt.value
var f = document.modulo.itp.value
var xxx = document.modulo.mmm.options.value
document.modulo.morale.value = Math.round(100*(((parseFloat(document.modulo.bp.value) +parseFloat(e) + parseFloat(f)) / 100 * xxx)))/100
document.modulo.totale.value = Math.round(100*((parseFloat(document.modulo.bp.value) +parseFloat(e) + parseFloat(f) + parseFloat(document.modulo.morale.value))))/100

var ITT = (document.modulo.itt.value).toString().replace(".",",")
var IPT = (document.modulo.itp.value).toString().replace(".",",")
var PERMANENTE = (document.modulo.bp.value).toString().replace(".",",")
var MORALE = (document.modulo.morale.value).toString().replace(".",",")
var TOTALE = (document.modulo.totale.value).toString().replace(".",",")

document.modulo.itt.value = ITT
document.modulo.itp.value = IPT
document.modulo.bp.value = PERMANENTE
document.modulo.morale.value = MORALE
document.modulo.totale.value = TOTALE

var y1 = ITT
var y2 = document.modulo.itt.value
//if(y1.length == 4){y2= y1.charAt(0)+"."+y1.substring(1,7)}
//if(y1.length == 5){y2= y1.charAt(0)+"."+y1.substring(2,8)}
if(y1.length == 6 && y1.indexOf(",") == 4){y2= y1.substring(0,1)+"."+y1.substring(1,9)}
if(y1.length == 7 && y1.indexOf(",") == 4){y2= y1.substring(0,1)+"."+y1.substring(1,4)+y1.substring(4,10)}
if(y1.length == 8){y2= y1.substring(0,2)+"."+y1.substring(2,5)+y1.substring(5,11)}
if(y1.length == 9){y2= y1.substring(0,3)+"."+y1.substring(3,9)}
if(y1.length == 10){y2= y1.substring(0,1)+"."+y1.substring(1,4)+"."+y1.substring(4,10)}
if(y1.length == 11){y2= y1.substring(0,2)+"."+y1.substring(2,5)+"."+y1.substring(5,11)}

var x1 = IPT
var x2 =document.modulo.itp.value
//if(x1.length == 4){x2= x1.charAt(0)+"."+x1.substring(1,7)}
//if(x1.length == 5){x2= x1.charAt(0)+x1.charAt(1)+"."+x1.substring(2,8)}
if(x1.length == 6 && x1.indexOf(",") == 4){x2= x1.substring(0,1)+"."+x1.substring(1,9)}
if(x1.length == 7 && x1.indexOf(",") == 4){x2= x1.substring(0,1)+"."+x1.substring(1,4)+x1.substring(4,10)}
if(x1.length == 8){x2= x1.substring(0,2)+"."+x1.substring(2,5)+x1.substring(5,11)}
if(x1.length == 9){x2= x1.substring(0,3)+"."+x1.substring(3,9)}
if(x1.length == 10){x2= x1.substring(0,1)+"."+x1.substring(1,4)+"."+x1.substring(4,10)}
if(x1.length == 11){x2= x1.substring(0,2)+"."+x1.substring(2,5)+"."+x1.substring(5,11)}


var v1 = PERMANENTE
var v2 =document.modulo.bp.value
//if(v1.length == 4){v2= v1.charAt(0)+"."+v1.substring(1,7)}
//if(v1.length == 5){v2= v1.charAt(0)+v1.charAt(1)+"."+v1.substring(2,8)}
if(v1.length == 6 && v1.indexOf(",") == 4){v2= v1.substring(0,1)+"."+v1.substring(1,9)}
if(v1.length == 7 && v1.indexOf(",") == 4){v2= v1.substring(0,1)+"."+v1.substring(1,4)+v1.substring(4,10)}
if(v1.length == 8){v2= v1.substring(0,2)+"."+v1.substring(2,5)+v1.substring(5,11)}
if(v1.length == 9){v2= v1.substring(0,3)+"."+v1.substring(3,9)}
if(v1.length == 10){v2= v1.substring(0,1)+"."+v1.substring(1,4)+"."+v1.substring(4,10)}
if(v1.length == 11){v2= v1.substring(0,2)+"."+v1.substring(2,5)+"."+v1.substring(5,11)}


var u1 = MORALE
var u2 =document.modulo.morale.value
//if(u1.length == 4){u2= u1.charAt(0)+"."+u1.substring(1,7)}
//if(u1.length == 5){u2= u1.charAt(0)+u1.charAt(1)+"."+u1.substring(2,8)}
if(u1.length == 6 && u1.indexOf(",") == 4){u2= u1.substring(0,1)+"."+u1.substring(1,9)}
if(u1.length == 7 && u1.indexOf(",") == 4){u2= u1.substring(0,1)+"."+u1.substring(1,4)+u1.substring(4,10)}
if(u1.length == 8){u2= u1.substring(0,2)+"."+u1.substring(2,5)+u1.substring(5,11)}
if(u1.length == 9){u2= u1.substring(0,3)+"."+u1.substring(3,9)}
if(u1.length == 10){u2= u1.substring(0,1)+"."+u1.substring(1,4)+"."+u1.substring(4,10)}
if(u1.length == 11){u2= u1.substring(0,2)+"."+u1.substring(2,5)+"."+u1.substring(5,11)}



var z1 = TOTALE
var z2 =document.modulo.totale.value 
//if(z1.length == 4){z2= z1.charAt(0)+"."+z1.substring(1,7)}
//if(z1.length == 5){z2= z1.charAt(0)+z1.charAt(1)+"."+z1.substring(2,8)}
if(z1.length == 6 && z1.indexOf(",") == 4){z2= z1.substring(0,1)+"."+z1.substring(1,9)}
if(z1.length == 7 && z1.indexOf(",") == 4){z2= z1.substring(0,1)+"."+z1.substring(1,4)+z1.substring(4,10)}
if(z1.length == 8){z2= z1.substring(0,2)+"."+z1.substring(2,5)+z1.substring(5,11)}
if(z1.length == 9){z2= z1.substring(0,3)+"."+z1.substring(3,9)}
if(z1.length == 10){z2= z1.substring(0,1)+"."+z1.substring(1,4)+"."+z1.substring(4,10)}
if(z1.length == 11){z2= z1.substring(0,2)+"."+z1.substring(2,5)+"."+z1.substring(5,11)}










document.modulo.itt.value = y2
document.modulo.itp.value = x2
document.modulo.bp.value = v2
document.modulo.morale.value = u2
document.modulo.totale.value = z2








}
function errore(){

var b = document.modulo.punti.value
if(b > 9) {document.write('<center><strong><font face=arial size=6 color=red>ERRORE !</FONT><BR><font face=arial size=4>Hai inserito un punteggio superiore a 9. Torna indietro e correggi.<font></strong><br><br><form action=biologico.html method=GET><input type=submit value="Torna indietro"></form>')}


}






