//
// Strutture Javascript globali
// Contenuto:
//  - win_popup(nome,prot,the_form,fpath,msg,itipo)
//  - init_combo(select_var,select_val[,0/1])
//  - MM_xxxx(): gestione immagini rollover.
//  - select_settore()
//  - lince_nop()
//  - valid_chars()
//	- what_checked_radio()
//	- some_checked_radio()
//	- get_checked_radio()
//	- do_checkradio()
//
// Window Popup: win_popup(nome,[prot/''],[the_form/false],[fpath/''],[msg/''],itipo)
// Apri una window con il contenuto specificato dal parametro prot ('http' o 'https') e da:
// 1) submit del form 'the_form' se the_form non e' false;  -- <a href="javascript:lince_nop()" OnClick="win_popup('NomeWin','',document.NomeForm,'','',1)">TESTO</a>
// 2) la url data dal path assoluto 'fpath' se fpath.length non e' zero  -- <a href="javascript:win_popup('NomeWin','',false,'/path/to/file','',1)">TESTO</a>
// 3) il messaggio 'msg' con un bottone di close se msg.length non e' zero.
// La window ha nome 'nome' e caratteristiche estetiche date da  win_popup_kinds[itipo].
//
// 20100302: novita` brillante di IE: occorre che il parametro name di window.open() sia una stringa senza spazi. Sorprendente!

var win_popup_kinds = new Array ( // ***NOTA*** - la funzione win_popup() appende a TUTTE le voci ",resizable=yes".
 'scrollbars=yes,toolbar=no,location=no,menubar=yes',				// 0: rapporto, scheda tmkt
 'top=150,left=200,screenX=320,screenY=240,scrollbars=yes,toolbar=no,location=no,menubar=no,width=400,height=230', // 1: login
 'top=320,left=240,screenX=320,screenY=240,scrollbars=yes,toolbar=no,location=no,menubar=no,width=400,height=120', // 2: alert
 'top=130,left=150,screenX=130,screenY=150,scrollbars=no,menubar=no,width=480,height=300',				  // 3: help
 'top=40,left=120,screenX=40,screenY=120,scrollbars=no,toolbar=no,location=no,menubar=no,width=550,height=450',	// 4: annunci
 'scrollbars,toolbar=no,location=no,menubar=no,width=665,height=450',		// 5: elencosettori,copyright
 'top=60,left=50,screenX=60,screenY=50,scrollbars=no,toolbar=no,location=no,menubar=no,width=700,height=470',	// 6: grafico
 'top=60,left=50,screenX=60,screenY=50,scrollbars=no,toolbar=no,location=no,menubar=no,width=600,height=400',	// 7: grafico
 'top=60,left=50,screenX=60,screenY=50,scrollbars=no,toolbar=no,location=no,menubar=no,width=660,height=460',	// 8: foto
 'top=60,left=50,screenX=60,screenY=50,scrollbars=no,toolbar=no,location=no,menubar=no,width=640,height=300',	// 9: output
 'scrollbars=yes,toolbar=no,location=no,menubar=no,width=700',					// 10: Scheda TMKT
 'top=40,left=50,screenX=40,screenY=50,scrollbars=yes,toolbar=no,location=no,menubar=no,width=680,height=480',	// 11:foto,anteprima,ricarica storia-LC
 'top=40,left=50,screenX=40,screenY=50,scrollbars=no,toolbar=no,location=no,menubar=no,width=700,height=480',	// 12: grafico
 'top=40,left=100,screenX=40,screenY=100,scrollbars=yes,toolbar=no,location=no,menubar=no,width=580,height=450',// 13: popup con scrollbar
 'top=15,left=120,screenX=15,screenY=120,scrollbars=no,toolbar=no,location=no,menubar=no,width=550,height=490',	// 14: annunci ampi
 'top=10,left=100,screenX=10,screenY=50,scrollbars=no,toolbar=no,location=no,menubar=no,width=620,height=500',	// 15: popup-slide
 'top=130,left=150,screenX=130,screenY=150,scrollbars=yes,menubar=no,width=480,height=300',	// 16: piccolo con scroll
 'top=15,left=120,screenX=15,screenY=120,scrollbars=yes,toolbar=no,location=no,menubar=no,width=570,height=490', // 17: annunci ampi con scrollbar
 'top=40,left=150,screenX=40,screenY=120,scrollbars=no,toolbar=no,location=no,menubar=no,width=440,height=400',	// 18: box
 'scrollbars=yes,toolbar=no,location=no,menubar=no,width=400,height=400', // 19: box per tmkt
 'top=60,left=50,screenX=60,screenY=50,scrollbars=yes,toolbar=no,location=no,menubar=no,width=800,height=530',	// 20: Vol
 'top=10,left=10,screenX=10,screenY=10,scrollbars=yes,toolbar=no,location=no,menubar=no,width=1000,height=600',	// 21: MAXI
 'top=40,left=50,screenX=40,screenY=50,scrollbars=yes,toolbar=no,location=no,menubar=no,width=800,height=350',	// 22: storia-LC (largo e stretto)
 'top=60,left=50,screenX=60,screenY=50,scrollbars=no,toolbar=no,location=no,menubar=no,width=660,height=560',	// 23: Esito Sondaggi
 ''							// (last)
);
var win_popup_handles = Array();  // wins popped up
var win_popup_handle_header =
	'<html><head><title>Lince</title><link rel="stylesheet" type="text/css" href="global_style.css"></head><body>' ;
var win_popup_handle_footer =
	'<br><center><form><input type="button" value="OK" OnClick="window.close()"></form></center></body></html>';


function win_popup(nome,prot,the_form,fpath,msg_or_h_and_p,itipo) {
  var dest = '';
  if (prot.length == 0) {
	prot = window.location.protocol;
  }
  else {
	prot = prot + ':';
  }

  h_and_p = window.location.host ;

  if (itipo >= win_popup_kinds.length) { itipo = 0; }

  if (the_form) {
    // alert('1:win_popup: nome ="' + nome + '" prot = "' + prot + '" the_form.action = "' + the_form.action + '" fpath = "' + fpath +
	//	'" msg_or_h_and_p = "' + msg_or_h_and_p + '" itipo = ' + itipo);
	if (nome.length) {
		the_form.target = nome ;
	}
	// per IE the_form.action e` la stringa da te indicata nell'html e non una struttura
	// Di conseguenza non puoi usare nessuna delle due istruzioni seguenti:
	// h_and_p = the_form.action.host + ':' + the_form.action.port ;
    // h_and_p = the_form.action.split('/')[2];
	// alert('h_and_p = ' + h_and_p);
	if (msg_or_h_and_p.length > 0) {
		h_and_p = msg_or_h_and_p ;
	}
	// alert('opening ' + nome + ' at ' + prot + '//' + h_and_p + '/modules/nil.html');
	win_popup_handles[win_popup_handles.length] = window.open(prot + '//' + h_and_p + '/modules/nil.html', nome, win_popup_kinds[itipo] + ',resizable=yes');

	if (fpath.length > 0) {
		the_form.action = prot + '//' + h_and_p + fpath ;
	}

	// se il form include topw_name/corpo_name assegna loro il valore corrente.
	if (the_form.topw_name) {
		the_form.topw_name.value = window.top.name ;
	}
	if (the_form.corpo_name) {
		the_form.corpo_name.value = window.name ;
	}

	the_form.submit();
	return true;
  }
  if (fpath.length) {
    // alert('2:win_popup: nome ="' + nome + '" prot = "' + prot + '" the_form = "' + the_form + '" fpath = "' + fpath +
	//	'" msg_or_h_and_p = "' + msg_or_h_and_p + '" itipo = ' + itipo);
	if (msg_or_h_and_p.length > 0) {
		h_and_p = msg_or_h_and_p ;
	}
	dest = prot + '//' + h_and_p + fpath ;
	// alert('opening ' + nome + ' at ' + dest);
	win_popup_handles[win_popup_handles.length] = window.open(dest, nome, win_popup_kinds[itipo] + ',resizable=yes');
	return ;
  }
  else {
	if (msg_or_h_and_p.length) {
		var ih = win_popup_handles.length ;
		win_popup_handles[ih] = window.open('', nome, win_popup_kinds[itipo] + ',resizable=yes');
		win_popup_handles[ih].document.open();
		win_popup_handles[ih].document.write(win_popup_handle_header);
		win_popup_handles[ih].document.write(msg_or_h_and_p);
		win_popup_handles[ih].document.write(win_popup_handle_footer);
		win_popup_handles[ih].document.close();
		return ;
	}
  }
  win_popup_handles[win_popup_handles.length] = window.open(dest, nome, win_popup_kinds[itipo] + ',resizable=yes');
  return null;
}

// init_combo(varptr, varval [, doins [, vartxt]])
// Inizializza il combo specificato al valore assegnato.
// Se il terzo argomento esiste ed è 1 e il valore manca viene aggiunto il nuovo Option.
//	Se il valore corrente è nullo viene anche selezionato.
//	Se esiste un quarto argomento viene usato come text dell'option aggiunta.
function init_combo(select_var, select_val) {
  var doins = 0;
  var fine = 0;
  var j = select_var.selectedIndex;
  if (init_combo.arguments.length > 2) {
    doins = init_combo.arguments[2];
  }
  for (var i = 0; i < select_var.length; i++) {
	if (select_var.options[i].value == select_val || (init_combo.arguments.length <= 3 && select_var.options[i].text == select_val)) {
		// val individuato oppure non c'era il quarto argomento ed è stato trovato nel text.
		select_var.options[i].defaultSelected=true ;
		select_var.options[i].selected=true ;
		fine = 1;
		break;
	}
  }
  if (fine == 0 && doins == 1) { // dobbiamo aggiungere un option
    if (init_combo.arguments.length > 3) {
	select_var.options[select_var.length] = new Option(init_combo.arguments[3],select_val);
    }
    else {
	select_var.options[select_var.length] = new Option(select_val,select_val);
    }
    if (select_var.options[j].text.length <= 0) {
	select_var.selectedIndex = select_var.length - 1;
    }
    else {
	select_var.selectedIndex = j;
    }
    select_var.options[select_var.selectedIndex].defaultSelected=true;
  }
  return;
}

//
// Gestione Roll-Over Images
//
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
   
}

function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" && document.MM_nbOver ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}

// cerca ciclicamente la sottostringa scritta nel textbox tbox all'interno del combo (tendina) e, se trovata, seleziona l'elemento.
var select_settore_last_i = 0;
function select_settore(tendina, tbox) {
   select_settore_last_i++;
   for (var i = select_settore_last_i; i < tendina.options.length; i++) {
     if (tendina.options[i].text.indexOf(tbox.value) >= 0) {
		tendina.options[i].selected = true;
		select_settore_last_i = i;
		return ;
	 }
   }
   for (i = 0; i < select_settore_last_i; i++) {
	if (tendina.options[i].text.indexOf(tbox.value) >= 0) {
		tendina.options[i].selected = true;
		select_settore_last_i = i;
		return ;
	}
   }
   select_settore_last_i = 0;
   return ;
}

function lince_nop() {
   return;
}

// jscript substr non ha le funzionalita` negative di javascript.
function jscompatsubstr(str, s, len) {
  if (s >= 0) {
    if (len >= 0) {
		return str.substr(s, len);
	}
	else { /* len < 0  [es. (4, -3) 3 caratteri indietro a partire dal car. 4] */
		return str.substr(s + len + 1, 0 - len) ;  /* es. (2, 3) */
    }
  }
  else { /* s < 0 [es. (-3, 2) posizionati a 3 car dalla fine e prendine 2 in avanti] */
    if (len >= 0) {
		return str.substr(str.length + s, len);  /* (str.length -3, len) */
	}
	else {  /* s,len < 0 [ es. (-2,-3) pos a 2 car dalla fine e torna indietro di altri 3 poi leggi quello e i 2 seguenti] */
		return str.substr(str.length + s + len + 1, 0 - len);  /* (str.length -4, 3) */
    }
  }
}

// valid_chars(stringa, char_validi)
// controlla se i caratteri presenti in stringa sono in  char_validi. Questa funzione rimpiazza l'uso di
// espressioni regolari che in JS sono notoriamente vulnerabili alle varie versioni di browser.
function valid_chars(stringa, char_validi) {
  // alert ('checking ' + stringa + ' con ' + char_validi);
  for (var i=0; i < stringa.length; i++) {
	if (char_validi.indexOf(stringa.charAt(i)) < 0) {
		return false;
	}
  }
  return true; // tutti i char sono validi.
}

//
// sintassi: what_checked_radio(r, val_a, val_b, val_c, ...)
// Verifica se nell'array di radio button r uno dei valori val_a... è selezionato.
// Restituisce l'indice nell'array corrispondente al valore selezionato.
function what_checked_radio(r) {
  for (var iv = 1; iv < what_checked_radio.arguments.length; iv++) {
	if (r.length) {
		for (var i=0; i < r.length; i++) {
			if (r[i].value == what_checked_radio.arguments[iv] && r[i].checked) {
				return i;
			}
		}
	}
	else { // JS bug: se c'è un solo pallino NON crea un array
		if (r.value == what_checked_radio.arguments[iv] && r.checked) {
			return 0 ;
		}
	}
  }
  return -1;
}
// Verifica se nell'array di radio button r uno dei valori (qualsiasi) è selezionato.
// In tal caso ne restituisce l'indice.
function some_checked_radio(r) {
  if (r.length) {
	for (var i=0; i < r.length; i++) {
		if (r[i].checked) {
			return i;
		}
	}
  }
  else {
	if (r.checked) {  // JS bug: se c'è un solo pallino NON crea un array
		return 0 ;
	}
  }
  return -1 ;
}
// poni checked il valore v nell'array di radiobutton r
function do_checkradio(r,v) {
  if (r.length) {
	for (var i=0; i < r.length; i++) {
		if (r[i].value == v) {
			r[i].checked = true;
			return i;
		}
	}
  }
  else {
	if (r.value == v) {
		r.checked = true ;
		return 0;
	}
  }
}
function get_checked_radio(r,i) {
  if (r.length && i < r.length) {
	return r[i].value ;
  }
  else {
	if (r.length) {
		alert('get_checked_radio(r,i) out o range i =' + i + ' >= ' + r.length);
		return r[r.length - 1].value ;
	}
	else {
		return r.value;
	}
  }
}

function some_checkbox(f, bname) {
  for (var i=0; i < f.elements.length; i++) {
    if (f.elements[i].name == bname + '[]' && f.elements[i].checked) {
		// alert('Trovato marcato ' + i);
		return (i);
    }
  }
  // alert('Non Trovato marcato alcun ' + bname + '[]');
  return -1;
}


//
// Valore di una variabile combo/text/hidden/textarea a partire dall'indice nel form.
//
function getformvarbyindex(formptr,idx) {
  varptr = formptr.elements[idx];
  if (varptr.options) {
    // la variabile appartiene a un combo
    if (varptr.options[varptr.selectedIndex].value.length > 0) { // non nullo
		// alert('getformvar 1 ' + varptr.name + ' ' + varptr.options[varptr.selectedIndex].value);
		return varptr.options[varptr.selectedIndex].value;
    }
    if (varptr.options[varptr.options.length - 1].value.length > 0) {  // l'ultimo non è nullo.
		// alert('getformvar 2 ' + varptr.name + ' ' + varptr.options[varptr.selectedIndex].value);
		return varptr.options[varptr.selectedIndex].value; // è il campo value quel che ci serve.
    }
    // alert('getformvar 3 ' + varptr.name + ' ' + varptr.options[varptr.selectedIndex].value);
    return varptr.options[varptr.selectedIndex].text ; // usiamo il campo text.
  }
  else {
	return varptr.value ;
  }
}
//
// restituisce l'indice della variabile varname nel form, -1 se non esiste.
// La presenza di un terzo argomento inibisce l'alert.
//
function getvarindex(formptr,varname) {
  for (var i=0; i < formptr.elements.length; i++) {
    if (formptr.elements[i].name == varname) {
    return (i);
    }
  }
  if (getvarindex.arguments.length < 3) {
    alert('getvarindex: non esiste la variabile ' + varname);
  }
  return (-1);
}
//
// Valore di una variabile combo/text/hidden/textarea del form a partire dal nome
//
function getformvar(formptr,varname) {
  var i;
  i = getvarindex(formptr,varname);
  if (i < 0) { return ''; }

  return getformvarbyindex(formptr, i) ;
}

//
// assegna alla variabile varname del form il valore varvalue
//
function setformvar(formptr,varname,varvalue) {
  var i;
  var varptr;

  i = getvarindex(formptr,varname);
  if (i < 0) { return ; }

  varptr = formptr.elements[i];

  if (varptr.options) {
    // la variabile appartiene a un combo
    init_combo(varptr, varvalue, 1);
    init_combo(varptr, varvalue);
  }
  else {
    // la variabile è un text o un hidden
    varptr.value = varvalue;
  }
  if (getformvarbyindex(formptr, i) != varvalue) {
      alert('setformvar Non sono riuscito a settare ' + varptr.name + ' con ' + varvalue);
  }
  return;
}

//
// (debug)
// Dump della variabili correnti del form.
//
function dumpform(formptr) {
  var str = '';
  for (var i=0; i < formptr.elements.length; i += 4) {
    for (var j=0; j < 4 && (i+j) < formptr.elements.length; j++) {
		str += formptr.elements[i+j].name + ' = "' + getformvarbyindex(formptr, i+j) + '" {' + formptr.elements[i+j].type + '}; ' ;
    }
    str += '\n';
	if (str.length > 2000) {
		str += 'Continua...';
		alert(str);
		str = '...\n';
	}
  }
  alert(str);
}
function rdumpform(formptr) {
  var str = '';
  for (var i=(formptr.elements.length-1); i >= -4; i -= 4) {
    for (var j=0; j < 4; j++) {
		z = i + j;
		if (z < formptr.elements.length && z >= 0) {
			str += formptr.elements[z].name + ' = "' + getformvarbyindex(formptr, z) + '" {' + formptr.elements[z].type + '}; ' ;
		}
    }
    str += '\n';
  }
  alert(str);
}

//
// Sostituisce il testo "v" di un link con il nuovo testo "n".
// Se l'argomento i>=0 e` specificato significa che il chiamante conosce gia` l'indice del link da modificare e
// possiamo evitare di cercarlo.
//
function changeLinkText(v, n, i) {
  // alert(document.links[0].text)
  if (i >= 0) {
    document.links[i].text = n ;
    return i ;
  }
  for (var i=0; i < document.links.length; i++) {
    if (document.links[i].text == v) {
      document.links[i].text = n ;
      return i ;
    }
  }
  return -1 ;
}

function printeuro(d) { // 12345678.456
  var s, a, v, j;
  if (d == 0) {
	return '0.00';
  }
  s = '' + Math.round(parseFloat(d) * 100.00);  // 1234567846
  a = s.substr(0, s.length -2) ; // 12345678
  s = s.substr(s.length -2, 2) ;  // 46
  v = ',';
  j = a.length - 3;
  while (j >= 0) {
	// alert('a.length = ' + a.length + ' j = ' + j + ' ' + s);
	s = a.substr(j, 3) + v + s ; // 678,46 -- 345.678,46
	v = '.';
	j -= 3;
  }
  if (j  > -3) {
	// alert(s);
	j += 3;
	s = a.substr(0, j) + v + s ; // -- 12.345.678,46
  }
  // alert(s);
  return s ;
}


//
// Routines Ajax
//
var lxAjaxRequest;
//
// gestisce un contasecondi in uno <span id="txtcntr">MM' SS"</span>
//
var lxAjaxCountConteggio_val = 1;
var lxAjaxCountConteggio_tID;
function lxAjaxCountConteggio() {
  lxAjaxCountConteggio_val += 1 ;
  secondi = lxAjaxCountConteggio_val % 60;
  minuti = (lxAjaxCountConteggio_val - secondi ) / 60 ;
  if (document.getElementById('txtcntr')) {
	  if (minuti > 0) {
		if (secondi < 10) {
			document.getElementById('txtcntr').innerHTML = '' + parseInt(minuti,10) + "' 0" + secondi + '"' ;
		}
		else {
			document.getElementById('txtcntr').innerHTML = '' + parseInt(minuti,10) + "' " + secondi + '"' ;
		}
	  }
	  else {
		if (secondi < 10) {
			document.getElementById('txtcntr').innerHTML = "0' 0" + lxAjaxCountConteggio_val + '"' ;
		}
		else {
			document.getElementById('txtcntr').innerHTML = "0' " + lxAjaxCountConteggio_val + '"' ;
		}
	  }
  }
  lxAjaxCountConteggio_tID = setTimeout('lxAjaxCountConteggio()', 1011);
}

//
// Crea un XMLHttpRequest object.
// methods/properties di xmlHttp:
//   - onreadystatechange: funzione ... XXX
//	 - readyState = 0 .. 4 (ossia request uninitialized, defined, sent, in-progress, complete).
//	 - responseText = testo fornito dal server when readyState=4.
//   - open('GET'/'POST', '<action path>', is_async)  dove is_async=true indica di eseguire una richiesta asincrona.
//	 - send(null)
function lxAjaxFunction(urlo, gestore) {
  try {
	// Firefox, Opera 8.0+, Safari
	lxAjaxRequest = new XMLHttpRequest();
  }
  catch (e) {
	// Internet Explorer
	try {
		lxAjaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    }
	catch (e) {
		try {
			lxAjaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) {
			alert("Your browser does not support AJAX!");
			return false;
		}
    }
  }
  lxAjaxRequest.open('GET', urlo, true);
  lxAjaxRequest.onreadystatechange = gestore ;
  lxAjaxRequest.send(null);
}

//
// gestisce un combo "suggestion" con id "cmbHint":
//     <input type="text" onkeyup="lxAjaxComboHintTxt(this, bpag, qtyp)"><select id="cmbHint"> ... </select>
// lxAjaxRequest.responseText contiene:
//   - il numero di record nella prima riga che viene scritto nello span 'cmbHintNumber', se esiste.
//   - le righe di output costituite da 2 stringhe separate da ';': il value e il text per ogni <option>.
function lxAjaxComboHint() {
  var coppia;
  var tmp1;
  var tmp2;
  var vett;
  var cmbHintNumber_tag;
  if (lxAjaxRequest) {
	if (lxAjaxRequest.readyState != 4) {
		return ;
	}
  }
  else {
	return ;
  }
  var sid = document.getElementById('cmbHint');
  vett = lxAjaxRequest.responseText.split('\n');
  sid.options.length = 0;
  sid.style.display = "none";
  if (vett.length > 1) {
	cmbHintNumber_tag = document.getElementById('cmbHintNumber') ;
	if (cmbHintNumber_tag != null) {
		if (vett.length > 2) {
			cmbHintNumber_tag.innerHTML = '&nbsp;(' + vett[0] + ' elementi):' ;
		}
		else {
			cmbHintNumber_tag.innerHTML = '&nbsp;(un elemento):' ;
		}
	}
	for (var i = 1; i < vett.length; i++) {
		coppia = vett[i].split(';');
		if (coppia.length > 2) {
			tmp1 = coppia.shift();
			tmp2 = coppia.join(';');
			coppia = new Array(tmp1, tmp2);
		}
		sid.options[sid.options.length] = new Option(coppia[1], coppia[0]);
	}

	if (navigator.userAgent.indexOf('MSIE') >= 0) {
		for (var i = 0; i < sid.options.length; i++) {
			sid.options[i].title = sid.options[i].text + ' (' + sid.options[i].value + ')' ;
		}
	}
	sid.style.display = "inline";
  }
  else {
	cmbHintNumber_tag = document.getElementById('cmbHintNumber') ;
	if (cmbHintNumber_tag != null) {
		cmbHintNumber_tag.innerHTML = '&nbsp;(0 elementi):' ;
	}
  }
}
function lxAjaxComboHintTxt(p, bpag, qtyp) {
  var sid = document.getElementById('cmbHint');
  document.getElementById('cmbHintNumber').innerHTML = '&nbsp;(attendere...):' ;
  if (p.value.length < 2) {
	sid.options.length = 0;
	sid.style.display = "none";
	document.getElementById('cmbHintNumber').innerHTML = '&nbsp;(0 elementi):' ;
	return ;
  }
  // var urlo = bpag  + ".phtml?qstr=" + escape(p.value) + "&qtyp=" + escape(qtyp) + "&sid=" + Math.random();
  var urlo = bpag + ".phtml?qstr=" + escape(p.value.substr(0,50)) + "&qtyp=" + escape(qtyp) + "&sid=" + Math.random();
  lxAjaxFunction(urlo, lxAjaxComboHint) ;
}


