
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
sel_id_mat=document.preventivo.materiale.value;

orizz = 1;
vert = 1;
num_cop = document.preventivo.copie.value;
if (num_cop =="" && num_cop ==0){
document.preventivo.copie.value==1;
}
else if  ( (orizz*1)==0 || (vert*1)==0 ) {
document.getElementById('esito').innerHTML = "Inserisci valori diversi da O";
}

vis_scar= (orizz*1)*(vert*1);
s_or_scar=(vis_scar*1)/(orizz*1);
s_vert_scar=(vis_scar*1)/(vert*1);
sperf_un=(orizz *1)*(vert*1)/10000;
sperf_tota=(orizz *1)*(vert*1)*(num_cop*1)/10000;
faces=1;
document.preventivo.area.value =(num_cop*1);
otto=document.preventivo.soggetto.value;
if (otto==1){
document.preventivo.opz.value='stesso';}
else if (otto==1.1){
document.preventivo.opz.value='diverso';}
mquad=document.preventivo.area.value;
bilan=document.preventivo.pesan.value;
document.preventivo.peso.value=Math.ceil(((mquad*1)*(bilan*1))/(faces*1));
deni=document.preventivo.peso.value;
if (deni >= 0 && deni<=2)
{document.preventivo.sped.value=10+".50";
document.preventivo.spedIVA.value=12+".70";
}
else if (deni >2 && deni<=5)
{document.preventivo.sped.value=12+".00";
document.preventivo.spedIVA.value=14+".50";}
else if (deni >5 && deni<=10)
{document.preventivo.sped.value=13+".50";
document.preventivo.spedIVA.value=16+".40";}
else if (deni >10 && deni<=20)
{document.preventivo.sped.value=15+".50";
document.preventivo.spedIVA.value=18+".75";}
else if (deni >20 && deni<=30)
{document.preventivo.sped.value=18+".00";
document.preventivo.spedIVA.value=21+".80";}
else if (deni >30 && deni<=40)
{document.preventivo.sped.value=23+".00";
document.preventivo.spedIVA.value=27+".90";}
else if (deni >40 && deni<=50)
{document.preventivo.sped.value=33+".00";
document.preventivo.spedIVA.value=39+".90";}
else if (deni >50 && deni<=70)
{document.preventivo.sped.value=45+".00";
document.preventivo.spedIVA.value=54+".50";}
else if (deni >70)
{document.preventivo.sped.value=(((deni*1)-70)*1)+45+".00";
document.preventivo.spedIVA.value=((((deni*1)-70)*1)+45)*1.21;
}

sei=document.preventivo.costo.value;
document.preventivo.taglio.value=Math.ceil(num_cop*1)+".00";
num=Math.round(((mquad*1)*(sel_id_mat*1)*(otto*1))*100)/100;
num=""+num; 
if(num.indexOf(".") == -1)
    {
        document.preventivo.prezzo.value=num+".00"; 
		document.preventivo.costo.value=(num*1)+(num_cop*1)+".00"; 
		num=Math.round(((sei*1)*1.21)*100)/100;
num=""+num; 
if(num.indexOf(".") == -1)
    {
        document.preventivo.costoIVA.value=num+".00";
		num=Math.round(((sei*1)/(num_cop*1))*100)/100;
num=""+num; 
if(num.indexOf(".") == -1)
    {
        document.preventivo.costosing.value=num+".00"; 
		
    }
    else
    {
        var splitted=num.split(".");
        if(splitted[1].length < 2)splitted[1]=splitted[1]+"0";
        document.preventivo.costosing.value=splitted[0]+"."+splitted[1];
		
		
		
    }
    return num
		
    }
    else
    {
        var splitted=num.split(".");
        if(splitted[1].length < 2)splitted[1]=splitted[1]+"0";
        document.preventivo.costoIVA.value=splitted[0]+"."+splitted[1];
		num=Math.round(((sei*1)/(num_cop*1))*100)/100;
num=""+num; 
if(num.indexOf(".") == -1)
    {
        document.preventivo.costosing.value=num+".00"; 
		
    }
    else
    {
        var splitted=num.split(".");
        if(splitted[1].length < 2)splitted[1]=splitted[1]+"0";
        document.preventivo.costosing.value=splitted[0]+"."+splitted[1];
		
		
		
    }
    return num
		
		
		
    }
    return num;
	
    }
    else
    {
        var splitted=num.split(".");
        if(splitted[1].length < 2)splitted[1]=splitted[1]+"0";
        document.preventivo.prezzo.value=splitted[0]+"."+splitted[1];
		document.preventivo.costo.value=(splitted[0]*1)+(num_cop*1)+"."+(splitted[1]*1);
		num=Math.round(((sei*1)*1.21)*100)/100;
num=""+num; 
if(num.indexOf(".") == -1)
    {
        document.preventivo.costoIVA.value=num+".00";
		num=Math.round(((sei*1)/(num_cop*1))*100)/100;
num=""+num; 
if(num.indexOf(".") == -1)
    {
        document.preventivo.costosing.value=num+".00"; 
		
    }
    else
    {
        var splitted=num.split(".");
        if(splitted[1].length < 2)splitted[1]=splitted[1]+"0";
        document.preventivo.costosing.value=splitted[0]+"."+splitted[1];
		
		
		
    }
    return num
		
    }
    else
    {
        var splitted=num.split(".");
        if(splitted[1].length < 2)splitted[1]=splitted[1]+"0";
        document.preventivo.costoIVA.value=splitted[0]+"."+splitted[1];
		num=Math.round(((sei*1)/(num_cop*1))*100)/100;
num=""+num; 
if(num.indexOf(".") == -1)
    {
        document.preventivo.costosing.value=num+".00"; 
		
    }
    else
    {
        var splitted=num.split(".");
        if(splitted[1].length < 2)splitted[1]=splitted[1]+"0";
        document.preventivo.costosing.value=splitted[0]+"."+splitted[1];
		
		
		
    }
    return num
		
		
		
    }
    return num;
	
    }
    return num;
 }
 



var subi = new Array();
subi [0]="stesso soggetto";
subi [1]="soggetti differenti";
var costo_d  = new Array();
costo_d  [0]="1";
costo_d  [1]="1.1";

function sogg() {
  num_cop= document.preventivo.copie.value;
  var select_pl = document.preventivo.soggetto;

  select_pl.options.length=0;
  if (num_cop <= 1 ){
    select_pl.options[select_pl.options.length] = new Option(subi[0],costo_d[0]);
  }
  else  if (num_cop > 1){
    for(var i=0; i<subi.length; i++)
    select_pl.options[select_pl.options.length] = new Option(subi[i],costo_d[i]);
  }

}


function stopCalc(){
clearInterval(interval);
}

