
function formatoEuro(valore){
	str=String(valore);
	var str_arr=str.split(".");
	
	var lstr=str_arr[0].length;
	
	if (lstr > 3){ 
		str_arr[0]=str_arr[0].substr(0,lstr-3) + "." + str_arr[0].substr(lstr-3,3);
	}
	str=str_arr[0] + "," + str_arr[1];
return str;
}


function calcolaTotale()
{

   var bgColor="#cfffcf";
   var bgColorError="#d8a0b2";
   var test=true;
   
   
   //abbonamento semestrale, annuale
   var abbonamento= new Array(2) 
	abbonamento[0]=240; 
	abbonamento[1]=324; 
	
   //pacchetti minuti 250,500,1000,3000,5000
   var minuti= new Array(5) 
	minuti[0]=200; 
	minuti[1]=380; 
	minuti[2]=1227.60; 
	minuti[3]=2040; 
	minuti[4]=3200; 
	
   //servizi opzionali 50, 100, 150, 200, 250 euro
   var opzionali= new Array(5) 
	opzionali[0]=50; 
	opzionali[1]=100; 
	opzionali[2]=150; 
	opzionali[3]=200; 
	opzionali[4]=500; 
	
	
	
	var imponibile=0;
	var iva=0;
	var totale=0;
	
	for (i=0; i < document.conto.abbonamento.length; i++){
		document.getElementById("abb1_"+i).className="ristrettobianco";
		document.getElementById("abb2_"+i).className="ristrettobianco";
		document.getElementById("abb3_"+i).className="ristrettobianco";
		if (document.conto.abbonamento[i].checked) {
		   document.getElementById("abb1_"+i).className="ristrettogiallo";
		   document.getElementById("abb2_"+i).className="ristrettogiallo";
		   document.getElementById("abb3_"+i).className="ristrettogiallo";
		   imponibile=imponibile + abbonamento[i];
		}
	}
	for (i=0; i < document.conto.minuti.length; i++){
	    document.getElementById("min1_"+i).className="ristrettobianco";
		document.getElementById("min2_"+i).className="ristrettobianco";
		document.getElementById("min3_"+i).className="ristrettobianco";
		document.getElementById("min4_"+i).className="ristrettobianco";
		if (document.conto.minuti[i].checked) {
		   document.getElementById("min1_"+i).className="ristrettogiallo";
		   document.getElementById("min2_"+i).className="ristrettogiallo";
		   document.getElementById("min3_"+i).className="ristrettogiallo";
		   document.getElementById("min4_"+i).className="ristrettogiallo";
		   imponibile=imponibile + minuti[i];
		}
	}
	for (i=0; i < document.conto.opzionali.length; i++){
	    document.getElementById("opz1_"+i).className="ristrettobianco";
		document.getElementById("opz2_"+i).className="ristrettobianco";
		if (document.conto.opzionali[i].checked) {
		   document.getElementById("opz1_"+i).className="ristrettogiallo";
		   document.getElementById("opz2_"+i).className="ristrettogiallo";
		   imponibile=imponibile + opzionali[i];
		}
	}
	
iva=imponibile*0.2;
totale=imponibile+iva;

imponibile=imponibile.toFixed(2);
iva=iva.toFixed(2);
totale=totale.toFixed(2);

document.conto.imponibile.value=formatoEuro(imponibile);
document.conto.iva.value=formatoEuro(iva);
document.conto.totale.value=formatoEuro(totale);
 
 
 
//if (test==true) {
	//	    if (confirm("Confermi l'invio dei dati?")) {
			
		//	}
      //    }

	
}


function resetta(){

	for (i=0; i < document.conto.abbonamento.length; i++){
		document.getElementById("abb1_"+i).className="ristrettobianco";
		document.getElementById("abb2_"+i).className="ristrettobianco";
		document.getElementById("abb3_"+i).className="ristrettobianco";
	}
	for (i=0; i < document.conto.minuti.length; i++){
	    document.getElementById("min1_"+i).className="ristrettobianco";
		document.getElementById("min2_"+i).className="ristrettobianco";
		document.getElementById("min3_"+i).className="ristrettobianco";
		document.getElementById("min4_"+i).className="ristrettobianco";
	}
	for (i=0; i < document.conto.opzionali.length; i++){
	    document.getElementById("opz1_"+i).className="ristrettobianco";
		document.getElementById("opz2_"+i).className="ristrettobianco";
	}
	
	document.conto.imponibile.value="0,00";
}

function vrfTotale(){
	if (document.conto.imponibile.value=="0,00"){
	alert("Scegli un credito da acquistare");
	return false;
	}
}




// controllo dati pagamenti con carta di credito
function Trim(s) 
{
  // Remove leading spaces 
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '%'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '%'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}



function vrfDati(formname)
{
   var bgColor="#FFFFFF";
   var bgColorError="#FFDED3";
   var test=true;
   var ind=-1;
   for(var i=0; i <= document.forms.length -1; i++){	
		  if (document.forms[i].name==formname) ind=i;
		}
   
	if (ind != -1 ) {
	  	
		document.forms[ind].nomecliente.style.backgroundColor=bgColor;
		
	document.forms[ind].nomecliente.value=Trim(document.forms[ind].nomecliente.value);

		if (document.forms[ind].nomecliente.value=="") {
		  alert("Il campo 'Nome cliente' è obbligatorio");
		  document.forms[ind].nomecliente.style.backgroundColor=bgColorError;
		  document.forms[ind].nomecliente.focus();
		  test=false;
		  return false;
	    }
		
	

		document.forms[ind].numcell.style.backgroundColor=bgColor;
	    document.forms[ind].numcell.value=Trim(document.forms[ind].numcell.value);
		if (document.forms[ind].numcell.value=="") {
		  alert("Il campo 'Cellulare' è obbligatorio");
		  document.forms[ind].numcell.style.backgroundColor=bgColorError;
		  document.forms[ind].numcell.focus();
		  test=false;
		  return false;
		} 
		
	}

	
}


