
function servoCitta(stringa) {
	
  if (stringa.length > 1 && stringa != lastStringa) {
    if (typeof(servo) == 'undefined' || typeof(servo) == 'string') { servo = new ajax() }
    Scrivi('loading', 'caricamento...');
	servo.Carica('get','/ajax/servoCitta.asp?stringa=' + stringa, 'servoCitta_ok');
	
    }
  else {
    document.getElementById('listaComuni').style.display = 'none';
    Scrivi('loading', '');
    }
  lastStringa = stringa
  }
  
function servoCitta_prov(stringa, idprovincia) {

if (stringa.length > 1 && stringa != lastStringa) {
if (typeof(servo) == 'undefined' || typeof(servo) == 'string') { servo = new ajax() }
Scrivi('loading', 'caricamento...');
servo.Carica('get','/ajax/servoCitta.asp?stringa=' + stringa+'&idprovincia='+idprovincia, 'servoCitta_ok');

}
else {
document.getElementById('listaComuni').style.display = 'none';
Scrivi('loading', '');
}
lastStringa = stringa
}
  
  
function Carico_inizio()
{
//carico prima volta tutte le parole
//var servo1;
servo = new ajax();
servo.Carica('get','/ajax/servoparola.asp', 'servoparola_ok');
}

function servoParola(stringa) {

  if (stringa.length > 1 && stringa != lastStringa) {
    if (typeof(servo) == 'undefined' || typeof(servo) == 'string') { servo = new ajax() }
    Scrivi('loading', 'caricamento...');
    //servo.Carica('get','/ajax/servoparola.asp?stringa=' + stringa, 'servoparola_ok');
	idlingua = document.tra.lingua.value; 
	//alert(idlingua);
	servo.Carica('get','/ajax/servoparola.asp?stringa=' + stringa + '&idlingua='+ idlingua , 'servoparola_ok');
    }
  else {
    document.getElementById('listaparole').style.display = 'inline';
    Scrivi('loading', '');
    }
  lastStringa = stringa
  }
function servoParola2(stringa) {

  if (stringa.length > 1 ) {
    if (typeof(servo) == 'undefined' || typeof(servo) == 'string') { servo = new ajax() }
    Scrivi('loading', 'caricamento...');
    //servo.Carica('get','/ajax/servoparola.asp?stringa=' + stringa, 'servoparola_ok');
	idlingua = document.tra.lingua.value; 
	//alert(idlingua);
	servo.Carica('get','/ajax/servoparola.asp?stringa=' + stringa + '&idlingua='+ idlingua , 'servoparola_ok');
    }
  else {
    document.getElementById('listaparole').style.display = 'inline';
    Scrivi('loading', '');
    }
  lastStringa = stringa
  }
  
function servoParole_tradotte(idparola) {

  //if (idparola.length > 1 ) {
	  
	  //alert('typeof(servo) === ' + typeof(servo));
	  
    //if (typeof(servo) == 'undefined' || typeof(servo) == 'string') 
	//{ 
	//alert('entra');
	servo = new ajax();
    Scrivi('loading', 'caricamento...');
    
	idlingua = document.tra.lingua.value; 
	
	servo.Carica('get','/ajax/servoparola.asp?idparola=' + idparola, 'servoparole_tradotte_ok');
	
	//}
   
  //else {//test
  //  document.getElementById('listaparole_tradotte').style.display = 'inline';
  //  Scrivi('loading', '');
  //  }
  //lastStringa = idparola
  
  
  }
  
 function Scrivo_parole_trad(idparola2 , parola)
 {
	 //scrivo le parole tradotte della parole selezionata anche in altre lingue:
	 
	 //alert('Scrivo_parole_trad (idparola2 , parola)');
	 //alert('idparola2 === ' + idparola2);
	 //alert('parola = ' + parola);
	 document.tra.idparola.value = idparola2;
	 servoParole_tradotte(idparola2);
 }
 
 
 function Sel_parola(parola, lingua)
 {
 
 document.tra.new_parola.value = parola;
 document.tra.lingua_parola_new.value = lingua;
 
 seleziona_option(lingua);
 
 //alert('Sel_parola(parola, lingua)')
 //alert('new_parola = ' + document.tra.new_parola.value);
 //alert('lingua_parola_new = ' + document.tra.lingua_parola_new.value);
 }
 
 
 
 function servoparola_ok() {
  var nomeComune = '';
  var elencoComuni = '';
  var i = 0;
  var nomeComune_value;

  
  if (lunghezza('c') == 0) {
    document.getElementById('listaparole').style.display = 'none';
    Scrivi('loading', '');
    document.getElementById('idparola').value = '';
    return
    }
  
  if (lunghezza('c') == 1) {
    document.getElementById('key').value = LoadVal('c', 0).replace(/&#39/g, "'");
    document.getElementById('idparola').value = LoadAtt('c', 'id', 0);
    document.getElementById('listaparole').style.display = 'none';
    //qua ha trovato un risultato:
	Scrivo_parole_trad(document.getElementById('idparola').value);
	Scrivi('loading', '');
    return
    }
    
  while ( i < parseFloat(lunghezza('c')) ) {
    nomeComune = LoadVal('c', i);
    nomeComune_value = LoadAtt('c', 'id', i);
    nomeProvincia = LoadAtt('c', 'p', i);
    //elencoComuni = elencoComuni + '<div onclick="document.getElementById(\'idparola\').value = \'' + nomeComune_value + '\'; document.getElementById(\'key\').value = \'' + nomeComune.replace(/&#39/g, "\\'") + '\'; document.getElementById(\'listaparole\').style.display = \'none\'; Scrivo_parole_trad(document.getElementById(\'idparola\').value, \''+nomeComune+'\')" style="cursor:pointer" onmouseover="this.style.background=\'#ececec\'" onmouseout="this.style.background=\'#ffffff\'">' + nomeComune + ' (' + nomeProvincia + ')</div>';
    //elencoComuni = elencoComuni + '<div onclick="Sel_parola(\'' + nomeComune + '\', \'' + nomeProvincia + '\'); document.getElementById(\'key\').value = \'' + nomeComune.replace(/&#39/g, "\\'") + '\'; document.getElementById(\'listaparole\').style.display = \'none\'; Scrivo_parole_trad(document.getElementById(\'idparola\').value, \''+nomeComune+'\')" style="cursor:pointer" onmouseover="this.style.background=\'#ececec\'" onmouseout="this.style.background=\'#ffffff\'">' + nomeComune + ' (' + nomeProvincia + ')</div>';
   elencoComuni = elencoComuni + '<div onclick="document.getElementById(\'key\').value = \'' + nomeComune.replace(/&#39/g, "\\'") + '\'; document.getElementById(\'listaparole\').style.display = \'none\'; Scrivo_parole_trad(\''+nomeComune_value+'\', \''+nomeComune+'\')" style="cursor:pointer" onmouseover="this.style.background=\'#ececec\'" onmouseout="this.style.background=\'#ffffff\'">' + nomeComune + ' (' + nomeProvincia + ')</div>';
   
   //Scrivo_parole_trad(idparola, parola)
   
   
	i++
    }
    
  if (elencoComuni != '') {
    document.getElementById('listaparole').style.display = 'block';
    document.getElementById('listaparole').innerHTML = elencoComuni;
    Scrivi('loading', '')
    }
  else {
    document.getElementById('listaparole').style.display = 'none';
    Scrivi('loading', '')
    }
  servo = ''
  
  
  
  }
  
 function servoparole_tradotte_ok() {
  var nomeComune = '';
  var elencoComuni = '';
  var i = 0;
  var nomeComune_value;

  if (lunghezza('c') == 0) {
    document.getElementById('listaparole_tradotte').style.display = 'none';
    Scrivi('loading', '');
    document.getElementById('idparola').value = '';
    return
    }
	
  str_nazioni_presenti = "";
  //alert(lunghezza('c'));
  while ( i < parseFloat(lunghezza('c')) ) {
    nomeComune = LoadVal('c', i);
    nomeComune_value = LoadAtt('c', 'id', i);
    nomeProvincia = LoadAtt('c', 'p', i);
	//setto str_nazioni_presenti con ITA,ENG e le lingue già utilizzate per queste parole
	if(str_nazioni_presenti=="")
	{str_nazioni_presenti = nomeProvincia;}
	else
	{str_nazioni_presenti = str_nazioni_presenti +","+nomeProvincia;}
	
    //elencoComuni = elencoComuni + '<div onclick="document.getElementById(\'idparola\').value = \'' + nomeComune_value + '\'; document.getElementById(\'key\').value = \'' + nomeComune.replace(/&#39/g, "\\'") + '\'; document.getElementById(\'listaparole_tradotte\').style.display = \'none\'; Scrivo_parole_trad(document.getElementById(\'idparola\').value)" style="cursor:pointer" onmouseover="this.style.background=\'#ececec\'" onmouseout="this.style.background=\'#ffffff\'">' + nomeComune + ' (' + nomeProvincia + ')</div>';
   	//elencoComuni = elencoComuni + '<div onclick="document.tra.new_parola.value = \'' + nomeComune + '\';" style="cursor:pointer" onmouseover="this.style.background=\'#ececec\'" onmouseout="this.style.background=\'#ffffff\'">' + nomeComune + ' (' + nomeProvincia + ')</div>';
   	elencoComuni = elencoComuni + '<div onclick="Sel_parola(\'' + nomeComune + '\', \''+nomeProvincia+'\');" style="cursor:pointer" onmouseover="this.style.background=\'#ececec\'" onmouseout="this.style.background=\'#ffffff\'">' + nomeComune + ' (' + nomeProvincia + ')</div>';
   //Sel_parola(parola, lingua)
	i++
    }
    
  if (elencoComuni != '') {
    document.getElementById('listaparole_tradotte').style.display = 'block';
    document.getElementById('listaparole_tradotte').innerHTML = elencoComuni;
    Scrivi('loading', '')
    }
  else {
    document.getElementById('listaparole_tradotte').style.display = 'none';
    Scrivi('loading', '')
    }
  servo = ''
  
  
  
  }
  
function servoCitta_ok() {
  var nomeComune = '';
  var elencoComuni = '';
  var i = 0;
  var nomeComune_value;

  
  if (lunghezza('c') == 0) {
    document.getElementById('listaComuni').style.display = 'none';
    Scrivi('loading', '');
    document.getElementById('idComune').value = ''
    return
    }
  
  if (lunghezza('c') == 1) {
    document.getElementById('comune_nome').value = LoadVal('c', 0).replace(/&#39/g, "'");
    document.getElementById('idComune').value = LoadAtt('c', 'id', 0);
    document.getElementById('listaComuni').style.display = 'none';
    Scrivi('loading', '');
    return
    }
    
  while ( i < parseFloat(lunghezza('c')) ) {
    nomeComune = LoadVal('c', i);
    nomeComune_value = LoadAtt('c', 'id', i);
    nomeProvincia = LoadAtt('c', 'p', i);
    elencoComuni = elencoComuni + '<div onclick="document.getElementById(\'idComune\').value = \'' + nomeComune_value + '\'; document.getElementById(\'comune_nome\').value = \'' + nomeComune.replace(/&#39/g, "\\'") + '\'; document.getElementById(\'listaComuni\').style.display = \'none\'; " style="cursor:pointer" onmouseover="this.style.background=\'#ececec\'" onmouseout="this.style.background=\'#ffffff\'">' + nomeComune + ' (' + nomeProvincia + ')</div>';
    i++
    }
    
  if (elencoComuni != '') {
    document.getElementById('listaComuni').style.display = 'block';
    document.getElementById('listaComuni').innerHTML = elencoComuni;
    Scrivi('loading', '')
    }
  else {
    document.getElementById('listaComuni').style.display = 'none';
    Scrivi('loading', '')
    }
  servo = ''
  }
  
var servo;
var lastStringa;