var index;
var citta,attivita;

function trim(stringa){
    while (stringa.substring(0,1) == ' '){
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length-1, stringa.length) == ' '){
        stringa = stringa.substring(0,stringa.length-1);
    }
    return stringa;
}

function CodiceFiscale()
{ 
  var stato="italia";
  var cognome=document.getElementById("cognomeMit").value;
  var nome=document.getElementById("nomeMit").value;
  var sesso=document.getElementById("sessoMit").value;
  var citta=document.getElementById("comune").value;
  var datan=document.getElementById("datan").value;
  var cbocittanas=document.getElementById("cbocittanas").value;
  var provnas=document.getElementById("provnas").value;
  if ((provnas=="EE") || (cbocittanas=="ESTERO")) {
   stato="estero";
  }
  var s="Attenzione!Manca: ";
  var manca=false
  if (trim(cognome)==""){
   s=s+"Cognome"
   manca=true
  }
  if (trim(nome)==""){
   s=s+" ,Nome"
   manca=true
  }
  if (trim(sesso)==""){
   s=s+" ,Sesso"
   manca=true
  }
  if (trim(citta)==""){
   s=s+" ,Citta"
   manca=true
  }
  if (trim(datan)==""){
   s=s+" ,Data Nascita"
   manca=true
  }
  
  if (!manca){
  var link="codice_fiscale/codice.asp";
  link=link+"?cognome="+cognome+"&nome="+nome+"&sesso="+sesso+"&citta="+citta+"&datan="+datan+"&stato="+stato;
  var codFis = window.open(link,'codFis','width=1,height=1,resizable=no,,scrollbars=no,status=no,directory=no,menubar=no,top=10,left=10')
  }else{
  alert(s)
  }
}

function TO_array() {  // Inizio funzione TO_array
var $dime = arguments.length;
var $elem = new Array($dime);
var TO_temp;
var TO_str = "";
  
for (var TO_i = 1; TO_i < $dime; TO_i++)
     if (isNaN($elem[TO_i] = parseInt(arguments[TO_i - 1],10))) {
         alert("La funzione TO_array richiede valori numerici");
         $dime = 0;
      }

do {
         TO_temp = "";
         for ($elem[--TO_i]; $elem[TO_i] > 1; --$elem[TO_i])
              TO_temp += "new Array(" + TO_str + "),";
           TO_temp += "new Array(" + TO_str + ")";
          
    TO_str = TO_temp;
 
  } while(--$dime > 1 && 0 != TO_i);

    TO_str = "new Array(" + TO_str + ")";

return eval(TO_str);
}

function sommaImporto(tot,imp,tar,plafondsettimanale,plafondannuale,plafonddest){
var somma,flag,somma_sett,totval;

somma=parseFloat(document.getElementById(imp).value)+parseFloat(document.getElementById(tar).value); 
flag=controllaLimite(parseFloat(document.getElementById(imp).value),plafondsettimanale,plafondannuale,plafonddest);

if (flag=="")
{ 
 document.getElementById(tot).value=parseFloat(somma).toFixed(2);
 totval=parseFloat(document.getElementById("importo_valuta_ric").value)+parseFloat(document.getElementById("tariffavaluta").value);
 document.getElementById("importoTotvaluta").value=totval.toFixed(2);
 document.getElementById(tot).focus();
}else
{
 document.getElementById(tot).value="";
 if (flag=="settimanale"){
 alert("L'IMPORTO NON PUO' ESSERE MAGGIORE DI "+ parseFloat(plafondsettimanale) +"€.!! PLAFOND SETTIMANALE MITTENTE SUPERATO");
 }
 if (flag=="annuale"){
 alert("L'IMPORTO NON PUO' ESSERE MAGGIORE DI "+ parseFloat(plafondannuale) +"€.!! PLAFOND ANNUALE MITTENTE SUPERATO" );
 }
if (flag=="dest"){
 alert("L'IMPORTO NON PUO' ESSERE MAGGIORE DI "+ parseFloat(plafonddest) +"€.!! PLAFOND SETTIMANALE DESTINATARIO SUPERATO" );
 }
 if (flag=="operazione"){
 alert("L'IMPORTO NON PUO' SUPERARE I 1999,99 euro");
 }
 
 document.getElementById(tot).value="";
 document.getElementById(tot).focus();
 document.getElementById("importoTotvaluta").value="";
}
}

function calcolaTariffa(importo,tipo,cambio)
{var tarval;
  var splitted = tipo.split("_");
  for (i=0;i<=Mat.length-1;i++)
  {
   for (k=1;k<=10;k++)
   {
    if (splitted[0]==Mat[i][0])
     { //alert(importo +"="+parseFloat(Mat[i][k])+"-"+parseFloat(Mat[i][k+10]));
       if ((importo>=parseFloat(Mat[i][k])) && (importo<=parseFloat(Mat[i][k+10])))
       {
        document.getElementById("tariffa").value=format(Mat[i][k+20]);
        tarval=format(Mat[i][k+20])*parseFloat(cambio);
        document.getElementById("tariffavaluta").value=tarval.toFixed(2);
        break;
       }else{ 
         if (parseFloat(Mat[i][k])==0 && parseFloat(Mat[i][k+10])==0)
            {
              document.getElementById("tariffa").value=(format(Mat[i][31])*importo)/100;
              //alert(Mat[i][31])
              tarval=document.getElementById("tariffa").value*parseFloat(cambio);
              document.getElementById("tariffavaluta").value=tarval.toFixed(2);
              break;
            }
       }
     }
   }
  }
}

function Mid(String, Start, Length)
{
    if (String == null)
        return (false);
    
    if (Start > String.length)
        return '';
    
    if (Length == null || Length.length == 0)
        return (false);
    
    return String.substr((Start - 1), Length);
}

function importoTariffa(id1,id2){
var sql,val,cambio,car,valuta,cambiovaluta;

cambiovaluta=document.getElementById("valuta").value;

if (cambiovaluta!=""){
len=cambiovaluta.length;
for(var i=1;i<=len;i++)
{
 car=Mid(cambiovaluta, i, 1);
 if (car=="|"){
   cambio=Mid(cambiovaluta,i+1,len);
   valuta=Mid(cambiovaluta,1,i-1);
   len=len+1;
  }
}

if (trim(document.getElementById(id1).value)!="")
{
 if (valuta=="EUR")
 {
   cambio="1.0000";
 }else {
  cambio=cambio.toString();
  alert("Cambio "+valuta+"/EUR ="+cambio);
 }

 if  (trim(document.getElementById("valuta").value)!=0){
 cambio=cambio.replace(",",".");
 val=parseFloat(document.getElementById(id1).value)*cambio
 document.getElementById("importo_valuta_ric").value=val.toFixed(2);

 calcolaTariffa(document.getElementById(id2).value,document.getElementById("Paese").value,cambio);
 sommaImporto('importoTot','importo_valuta','tariffa','<%=plafondsettimanale%>','<%=plafondannuale%>','<%=plafonddest%>')
 checkLimite(document.getElementById('importoTot').value);
 }else{
  document.getElementById(id2).value='';
  document.getElementById("tariffa").value='';
  document.getElementById("tariffavaluta").value='';
  document.getElementById("importoTot").value='';
  document.getElementById("importoTotvaluta").value='';
 }
}else
 {
  document.getElementById(id2).value='';
 }
 }
}

function format(str) {
if (parseInt(str)==0 || isNaN(parseInt(str))){
str='';
}else{
index = str.indexOf(".");
if (index < 0) str = str + ".00";
else {
str = str.substring(0, index + 3);
if (str.length < (index + 3)) str += "0";
}
}
return str;
}
//***** FUNZIONI DI CONVALIDA DEI DATI INSERITI NEL MODULO DI CONTATTO*****

function IsEmailValid(mail){
  var EmailOk = true
  var Temp = mail;
  var AtSym = Temp.indexOf('@')
  var Period = Temp.lastIndexOf('.')
  var Space = Temp.indexOf(' ')
  var Length = Temp.length - 1
  // Array is from 0 to length-1
  if (Temp == "") {
    return true; }
  if ((AtSym < 1) || (Period <= AtSym+1) || (Period == Length ) || (Space != -1))
  {
    alert("Inserire un indirizzo E-mail valido.");
    //document.frmModulo.txtEmail.focus();
    EmailOk = false
  }   return EmailOk
}

function isTelValid(tel){
//Controlla che il Telefono sia composto da soli caratteri numerici e dai caratteri /, (, ),-
    var checkOK = "0123456789-/-()";
    var checkStr = trim(tel);
    var allValid = true;
    for (i = 0; i < checkStr.length; i++)
   {
      ch = checkStr.charAt(i);
      for (j = 0; j < checkOK.length; j++)
        if (ch == checkOK.charAt(j))
         break;
      if (j == checkOK.length)
     {
        allValid = false;
        break;
      }
    }
    if (!allValid)
    {
      alert("NUMERO TELEFONICO ERRATO!");
       document.getElementById("telefonoMit").value=""; 
       document.getElementById("telefonoMit").focus(); 
     }
     
document.getElementById("telefonoMit").value=trim(document.getElementById("telefonoMit").value);
return true;
}
function isCapValid(cap,campo){
//Controlla che il Telefono sia composto da soli caratteri numerici e dai caratteri /, (, ),-
    var checkOK = "0123456789";
    var checkStr = trim(cap);
    var allValid = true;
    
    if (checkStr.length>0){
    if (checkStr.length>5 || checkStr.length<5){
      allValid=false;
    }
    for (i = 0; i < checkStr.length; i++)
   {
      ch = checkStr.charAt(i);
      for (j = 0; j < checkOK.length; j++)
        if (ch == checkOK.charAt(j))
         break;
      if (j == checkOK.length)
     {
        allValid = false;
        break;
      }
    }

    if (!allValid)
    {
      alert("CODICE DI AVVIAMENTO POSTALE ERRATO!"); 
       document.getElementById(campo).value="";
       document.getElementById(campo).focus(); 
    }
    }
document.getElementById(campo).value=trim(document.getElementById(campo).value);
return true;
}

function isDateValid(text,campo)
{
if((typeof(text)=="undefined")||(text=="")) return false;
var dateMatchResult=text.match(/(^\d{1,2})[\/](\d{1,2})[\/](\d{2}$|\d{4})/);
if(dateMatchResult==null){
 alert("Data non corretta es. gg/mm/aaaa!");
 document.getElementById(campo).value="";
  document.getElementById(campo).focus(); 
 return false;
}

var day;
var month;
var year;
if(RegExp.$1.length==1) day="0"+RegExp.$1; else day=RegExp.$1;
if(RegExp.$2.length==1) month="0"+RegExp.$2; else month=RegExp.$2;
if(RegExp.$3.length==2) year=(parseInt(RegExp.$3,10)<32?"20":"19")+RegExp.$3;
else year=RegExp.$3;
var inputDate=day+"/"+month+"/"+year;
var date=new Date(year,month-1,day);
day=((date.getDate()<10)?"0":"")+date.getDate();
month=(((date.getMonth()+1)<10)?"0":"")+(date.getMonth()+1);
year=date.getFullYear();
var outputDate=day+"/"+month+"/"+year;
date = null;
if(inputDate!=outputDate)  {
alert("Data non corretta es. gg/mm/aaaa!");
 document.getElementById(campo).value="";
 document.getElementById(campo).focus(); 

 return false;
}
document.getElementById(campo).value=outputDate
return true;
}

function controllaLimite(imp,plafondsettimanale,plafondannuale,plafonddest)
{

 if (imp>1999.99){
  return "operazione"
 }
  if (imp>plafondsettimanale){
  return "settimanale";
 }
 if (imp>plafondannuale){
  return "annuale";
 }
 if (imp>plafonddest){
  return "dest";
 }
 return "";
}

function controllaLimite2(imp,tot_op_sett,tot_op_anno,tot_op_dest,plafondsettimanale,plafondannuale,plafonddest)
{
 var somma_sett;
 var somma_anno;
 var somma_dest;
 //if (parseFloat(imp)<parseFloat(imp_val_old))
 //{
 // imp=parseFloat(imp)-parseFloat(imp_val_old);
 // document.getElementById("totOpSett").value=parseFloat(imp)+parseFloat(tot_op_sett);
// }
// if (parseFloat(imp)>parseFloat(imp_val_old))
 //{
 // imp=parseFloat(imp)-parseFloat(imp_val_old);
 // document.getElementById("totOpSett").value=parseFloat(imp)+parseFloat(tot_op_sett);
// }
 somma_sett=imp+tot_op_sett;
 somma_anno=imp+tot_op_anno;
 somma_dest=imp+tot_op_dest
 
 if (somma_sett>plafondsettimanale)
 { 
  somma_sett=plafondsettimanale-tot_op_sett;
  if(somma_sett<0){
   somma_sett=0;
  }
  document.getElementById("plSett").value=somma_sett.toFixed(2);
  return ("SETTIMANALE");
 }
 if (somma_anno>plafondannuale)
 { 
  somma_anno=plafondannuale-tot_op_anno;
  if(somma_anno<0){
   somma_anno=0;
  }
  document.getElementById("plAnno").value=somma_anno.toFixed(2);
  return ("ANNUALE");
 }
 if (somma_dest>plafonddest)
 { 
  somma_dest=plafonddest-tot_op_dest;
  if(somma_dest<0){
   somma_dest=0;
  }
  document.getElementById("plDest").value=somma_dest.toFixed(2);
  return ("DESTINATARIO");
 }

 
 return ("si");
}

function ControllaCF(cf)
{
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return '';
	cf = cf.toUpperCase();
	if( cf.length != 16 ) {
		alert( "La lunghezza del codice fiscale non è\n"
		+"corretta: il codice fiscale dovrebbe essere lungo\n"
		+"esattamente 16 caratteri.\n");
		 document.getElementById('codfis').value="";
 		 document.getElementById('codfis').focus(); 

	}
			validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 ){
			alert( "Il codice fiscale contiene un carattere non valido `" +
				cf.charAt(i) +
				"'.\nI caratteri validi sono le lettere e le cifre.\n");
				 document.getElementById('codfis').value="";
		 		 document.getElementById('codfis').focus(); 

			}
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) ){
		alert("Il codice fiscale non è corretto:\n"+"il codice di controllo non corrisponde.\n");
		 document.getElementById('codfis').value="";
		 document.getElementById('codfis').focus(); 

		}
	return "";
}


function dateFormat(data, formato) { 
// (c) br1 - 2002 

	var giorni = new Array("Domenica","Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","Sabato");
	var mesi = new Array("Gennaio","Febbraio","marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");

// preparo la data...  verificare di passarla corretta!
	var adesso = new Date(data); 
	var anno = adesso.getFullYear();
	var mese = adesso.getMonth()+1;
	var giorno = adesso.getDate();
	var settim = adesso.getDay()
	var ore = adesso.getHours()
	var minuti = adesso.getMinutes()
	var secondi = adesso.getSeconds()

// preparo la stringa di risposta
	var rVal = '';

	if (formato.length==0) { 
// assenza del secondo parametro
		return String(adesso); 
	} else {

	// inizio loop
		while (formato.length>0) {

	// verifico se c'e' qualche separatore e lo aggiungo
			while (formato.length>0 && String("ymdphnst").indexOf(formato.charAt(0).toLowerCase())<0) {
				rVal += formato.charAt(0);
				formato = formato.substr(1);
			}


	// Separo il gruppo
			if (formato.length>0) {
				ff = formato.charAt(0);
				formato = formato.substr(1);
				while (formato.length>0 && formato.charAt(0).toLowerCase()==ff.charAt(0).toLowerCase()) {
					ff += formato.charAt(0);
					formato = formato.substr(1);
				}

	// espando il formato nella stringa corrispondente
				ff = ff.toLowerCase();	 // operazione preliminare... tutto in minuscolo
				switch (ff) 	{ 
					case "yy" : 
						rVal += String(anno).substr(2); 
						break; 
					case "yyyy" : 
						rVal += String(anno); 
						break; 
					case "m" : 
						rVal += String(mese); 
						break; 
					case "mm" : 
						rVal += lz(mese,2);
						break; 
					case "mmm" : 
						rVal += mesi[mese-1].substr(0,3);
						break; 
					case "mmmm" : 
						rVal += mesi[mese-1];
						break; 
					case "d" : 
						rVal += String(giorno); 
						break; 
					case "dd" : 
						rVal += lz(giorno,2); 
						break; 
					case "ddd" : 
						rVal += giorni[settim].substr(0,3);
						break; 
					case "dddd" : 
						rVal += giorni[settim];
						break; 
					case "p" : 
						var inizio = new Date(anno, 0, 0); 
						rVal += Math.floor((adesso - inizio) / 86400000);
						break; 
					case "ppp" : 
						var inizio = new Date(anno, 0, 0); 
						rVal += lz(Math.floor((adesso - inizio) / 86400000),3);
						break; 
					case "h" : 
						rVal += String(ore); 
						break; 
					case "hh" : 
						rVal += lz(ore,2); 
						break; 
					case "n" : 
						rVal += String(minuti); 
						break; 
					case "nn" : 
						rVal += lz(minuti,2); 
						break; 
					case "s" : 
						rVal += String(secondi); 
						break; 
					case "ss" : 
						rVal += lz(secondi,2); 
						break; 
					case "t" : 
						rVal += lz(ore,2)+":"+lz(minuti,2)+":"+lz(secondi,2); 
						break; 
					default :  // il numero dei caratteri del formato non e' permesso
						rVal += ff.replace(/./gi,"?");
				} 

			}

		} // fine loop principale

		return rVal;
	}
} 
function lz(numero, cifre) {
	n = String(numero);
	while (n.length<cifre) { 
		n="0"+n 
	}
	return n;
}

function controllaMitDest(link,servizio)
{
   if (link=="mittenti.asp")
   { 
       var nome=document.getElementById("nomeMit").value; 
	  
	   var cognome = document.getElementById("cognomeMit").value; 
	   var indirizzo = document.getElementById("indirizzoMit").value;
	   var citta = document.getElementById("cittaMit").value;
	   var cap = document.getElementById("capMit").value;
	   var stato = document.getElementById("statoMit").value;
	   var telefono = document.getElementById("telefonoMit").value;
	   var occupazione = document.getElementById("occupazioneMit").value;
	   var codfis = document.getElementById("codfis").value;
	  
       var comune = document.getElementById("comune").value;
	   var datan = document.getElementById("datan").value;
	   var sesso = document.getElementById("sessoMit").value;
	   var documento = document.getElementById("docMit").value;
	   var emesso = document.getElementById("emessa").value;
	   var scade = document.getElementById("scade").value;
	   var rilasciato = document.getElementById("docRilascioMit").value;
	   var numero = document.getElementById("numdocMit").value;
	   link=link+"?nome="+nome+"&cognome="+cognome+"&indirizzo="+indirizzo+"&citta="+citta+"&cap="+cap+"&stato="+stato+"&telefono="+telefono+"&occupazione="+occupazione+"&codfis="+codfis+"&comune="+comune+"&datan="+datan+"&sesso="+sesso+"&documento="+documento+"&emesso="+emesso+"&scade="+scade+"&rilasciato="+rilasciato+"&numero="+numero;
  
   }
   if (link=="destinatari.asp")
   {
       if (servizio!='money'){
       var nome=document.getElementById("nomeDest").value;
	   var cognome = document.getElementById("cognomeDest").value;
	   var indirizzo = document.getElementById("indDest").value;
	   var citta = document.getElementById("cittaDest").value;
	   var cap = document.getElementById("capDest").value;
	   var telefono = document.getElementById("telefonoDest").value;
	   var sesso = document.getElementById("sessoDest").value;
	   var documento = document.getElementById("tipodocDest").value;
	   var numero = document.getElementById("numdocDest").value;
	   var banca = document.getElementById("banca").value;
	   var cc = document.getElementById("cc").value;
	   
	   link=link+"?nome="+nome+"&cognome="+cognome+"&indirizzo="+indirizzo+"&citta="+citta+"&cap="+cap+"&telefono="+telefono+"&sesso="+sesso+"&documento="+documento+"&numero="+numero+"&banca="+banca+"&cc="+cc;
       }else{
       var nome=document.getElementById("nomeDest").value;
	   var cognome = document.getElementById("cognomeDest").value;
	   //var indirizzo = document.getElementById("indDest").value;
	   //var citta = document.getElementById("cittaDest").value;
	   //var cap = document.getElementById("capDest").value;
	   var telefono = document.getElementById("telefonoDest").value;
	   //var sesso = document.getElementById("sessoDest").value;
	   //var documento = document.getElementById("tipodocDest").value;
	   //var numero = document.getElementById("numdocDest").value;
	   var cc = document.getElementById("cc").value;
	   var agenzia = document.getElementById("agenzia").value;
	   link=link+"?nome="+nome+"&cognome="+cognome+"&telefono="+telefono+"&cc="+cc+"&servizio="+servizio+"&agenzia="+agenzia;
	   }
   }
   
 
   var cont = window.open(link,'codFis','width=822,height=410,resizable=no,,scrollbars=yes,status=yes,directory=no,menubar=no,top=10,left=10')
}

function controllaLimite3(imp,tot_op_sett,plafondsettimanale,imp_old,plafondannuale,tot_op_anno,tot_op_dest,plafonddest)
{

 var somma_sett;
 var somma_anno;
 var somma_dest;
 var imp_anno=imp;
 var imp_sett=imp;
 var imp_dest=imp;

 if (parseFloat(imp_sett)<parseFloat(imp_old))
 {
  imp_sett=parseFloat(imp_sett)-parseFloat(imp_old);
  document.getElementById("totOpSett").value=imp_sett+tot_op_sett;
 }
 if (parseFloat(imp_sett)>parseFloat(imp_old))
 {
  imp_sett=parseFloat(imp_sett)-parseFloat(imp_old);
  document.getElementById("totOpSett").value=imp_sett+tot_op_sett;
 }
 
 
 if(parseFloat(imp_dest)==parseFloat(imp_old)){
  somma_dest=0;
 }else{somma_dest=imp_dest+tot_op_dest;}
 
 if (parseFloat(imp_dest)<parseFloat(imp_old))
 {
  imp_dest=parseFloat(imp_dest)-parseFloat(imp_old);
  document.getElementById("totOpDest").value=imp_dest+tot_op_dest;
 }
 if (parseFloat(imp_dest)>parseFloat(imp_old))
 {
  imp_dest=parseFloat(imp_dest)-parseFloat(imp_old);
  document.getElementById("totOpDest").value=imp_dest+tot_op_dest;
 }
 
 
 if(parseFloat(imp_dest)==parseFloat(imp_old)){
  somma_dest=0;
 }else{somma_dest=imp_dest+tot_op_dest;}
 
 
 if (parseFloat(imp_anno)<parseFloat(imp_old))
 {
  imp_anno=parseFloat(imp_anno)-parseFloat(imp_old);
  document.getElementById("totOpAnno").value=parseFloat(imp_anno)+parseFloat(tot_op_anno);
 }
 if (parseFloat(imp_anno)>parseFloat(imp_old))
 {
  imp_anno=parseFloat(imp_anno)-parseFloat(imp_old);
  document.getElementById("totOpAnno").value=parseFloat(imp_anno)+parseFloat(tot_op_anno);
 }

 
 if (parseFloat(imp_anno)==parseFloat(imp_old)){
 somma_anno=0;
 }else{somma_anno=imp_anno+tot_op_anno;}
 
 if (somma_sett>plafondsettimanale)
 { 
  somma_sett=plafondsettimanale-tot_op_sett;
  if(somma_sett<0){
   somma_sett=0;
  }
  return ("SETTIMANALE");
 }
 
 if (somma_anno>plafondannuale)
 { 
  somma_anno=plafondannuale-tot_op_anno;
  if(somma_anno<0){
   somma_anno=0;
  }
  return ("ANNUALE");
 }
 
 if (somma_dest>plafonddest)
 { 
  somma_dest=plafonddest-tot_op_dest;
  if(somma_dest<0){
   somma_dest=0;
  }
  return ("DESTINATARIO");
 }
 
 
 
 return ("si");
}

function convDec(campo){
 var valore; 

 valore =  document.getElementById(campo).value;
 valore = valore.replace(",",".");
 document.getElementById(campo).value=valore;
}
function passaImporto(cambio){
 document.getElementById("importo_valuta").value= document.getElementById("importo").value;
 importoTariffa("importo","importo_valuta");
}
function openchk() {
   cartella = location.pathname;
   opzioni = 'width=200,height=10,top=0';
   window.open('chkout.htm?'+cartella,'ctrout',opzioni);
}

function insCitta(id){
var splitted,cap,cit,cbo=document.getElementById(id);
 splitted=cbo.value.split("-");
 cap=splitted[2];
 prov=splitted[1];
 cit=splitted[0];
 if (id=="cbocittaMit") {
  document.getElementById("cittaMit").value=cit;
  document.getElementById("capMit").value=cap;
  document.getElementById("provMit").value=prov;
 }else
 {
    if (typeof(prov) == "undefined"){
     prov="EE";
     
    }
    if (typeof(cit) == "undefined" || cit=="ESTERO"){
     cit=document.getElementById("comune").value;
    }
    document.getElementById("provnas").value=prov;
    document.getElementById("comune").value=cit;
 }
 
}

function insComuni(cb1,cb2)
   {  
      var ins,ind;
      if (cb2=="cbocittanas"){
       ind=2;
      }else{
       ind=1;
      }
      var cbo=document.getElementById(cb2);
      for(k=cbo.options.length-1;k>=ind;k--){
        cbo.options[k]=null;
      }
      if (trim(document.getElementById(cb1).value)!="")
      {
       document.getElementById(cb1).value=document.getElementById(cb1).value.toUpperCase();
       ins =document.getElementById(cb1).value;
       for (var i = 0; i < citta.length; ++i)
       { 
        if(citta[i].firstChild.nodeValue.substr(0,ins.length)==ins.substr(0,ins.length))
         { 
          cbo.options[cbo.options.length]=new Option(citta[i].firstChild.nodeValue ,citta[i].firstChild.nodeValue , false, false);
  		 }
       }
      }
  }
  
function insOccupazione(id){
 var splitted,occupazione,cbo=document.getElementById(id);
 //splitted=cbo.value.split("-");
 //occupazione=splitted[0];
 occupazione=cbo.value;
 document.getElementById("occupazioneMit").value=occupazione;
}

function insAttivita()
   {  
      var ins,attivparz;
      var cbo=document.getElementById("cbooccupazioneMit");
      for(k=cbo.options.length-1;k>=1;k--){
        cbo.options[k]=null;
      }
      if (trim(document.getElementById("occupazioneMit").value)!="")
      {
       document.getElementById("occupazioneMit").value=document.getElementById("occupazioneMit").value.toUpperCase();
       ins =document.getElementById("occupazioneMit").value;
       for (var i = 0; i < attivita.length; ++i)
       { 
       attivparz=attivita[i].firstChild.nodeValue.substr(7,ins.length);
        if(attivparz.toUpperCase()==ins.substr(0,ins.length))
         { 
          cbo.options[cbo.options.length]=new Option(attivita[i].firstChild.nodeValue ,attivita[i].firstChild.nodeValue , false, false);
  		 }
       }
      }
  }
function disponibile()
{
 var splitted = document.getElementById("Paese").value.split("_");
 if (splitted[0]==''){
  alert("ATTUALMENTE NON SIAMO OPERATIVI IN QUESTO PAESE")
  document.getElementById("importo_valuta_ric").value='';
  document.getElementById("tariffa").value='';
  document.getElementById("tariffavaluta").value='';
  document.getElementById("importoTot").value='';
  document.getElementById("importoTotvaluta").value='';
  
  return;
 }

}

