function cambiaPagina(i) {
	var formCambiamentoPagina=document.getElementById("cambiamentopagina");
	formCambiamentoPagina.pagina.value=i;
	formCambiamentoPagina.submit();
}


function vediAnnunciCategoria(id) {
	var formVisAnnCat=document.getElementById("vis_ann_cat");
	formVisAnnCat.categoria.value=id;
	formVisAnnCat.submit();
}


function vediAziende(tipocat ,id) {
	var formVisAziCat=document.getElementById("vis_azi_cat");
	var inputCat=eval("formVisAziCat." + tipocat);
	inputCat.disabled=false;
	inputCat.value=id;
	formVisAziCat.submit();
}


function vediMailFallite(tipo, id) {
	var win=window.open('det_mail_fallite.asp?tipo=' + tipo + '&id=' + id, 'mf', 'scrollbars=yes,width=300,height=300,left=100,top=20,screenX=20,screenY=100')
	win.focus();
}


function contaCaratteri(campoTestoId, campoDispId, maxLunghezza, tagliaEccedenti) {
	var campoTesto, testo, caratteriDisponibili;
	var campoDisp = document.getElementById(campoDispId);

	if (maxLunghezza==null) {
		caratteriDisponibili='';
	} else {
		campoTesto = document.getElementById(campoTestoId);
		testo = campoTesto.value;
		if (tagliaEccedenti==null) tagliaEccedenti=true;
	
		caratteriDisponibili = maxLunghezza - testo.length;
		if (caratteriDisponibili<0 && tagliaEccedenti) {
			campoTesto.value = testo.substring(0, maxLunghezza);
			caratteriDisponibili = 0;
		}
	}

	if (campoDisp!=null)
		campoDisp.value = caratteriDisponibili;
}


function calcolaNewsletters() {
	var i, checkbox, totNL;

	i=1;
	totNL=0;
	checkbox=document.getElementById("newsletters"+i);
	while (checkbox!=null) {
		if (checkbox.checked)
			totNL+=Math.pow(2, (parseInt(checkbox.value)-1));
		i++;
		checkbox=document.getElementById("newsletters"+i);
	}

	document.getElementById("newsletters").value=totNL;
	return totNL;
}


var pswdChanged=false;

function abilitaPassword2() {
	var pswd2=document.getElementById("password2");
	pswd2.disabled=false;
	pswd2.style.backgroundColor='#FFFFFF';
}

function disabilitaPassword2() {
	var pswd2=document.getElementById("password2");
	pswd2.disabled=true;
	pswd2.style.backgroundColor='#CCCCCC';
}

function passwordChanged() {
	pswdChanged=true;
}

function passwordFocused() {
	if (!pswdChanged)
		abilitaPassword2();
}

function passwordBlurred() {
	if (!pswdChanged)
		disabilitaPassword2();
}



function seleziona(modo) {
	var i, checkbox, valore;

	i=1;	
	checkbox=document.getElementById("selez"+i);

	switch(modo.toUpperCase()) {
		case "T":
			valore=true;
			break;

		case "N":
			valore=false;
			break;

		case "I":
			valore=false;
			while (checkbox!=null) {
				checkbox.checked=(!checkbox.checked);
				i++;
				checkbox=document.getElementById("selez"+i);
			}
			return;
			
		default:
			return;
	}
		
	while (checkbox!=null) {
		checkbox.checked=valore;
		i++;
		checkbox=document.getElementById("selez"+i);
	}
}


function numeroSelezionati() {
	var num, i, checkbox;
	num=0;
	i=1;	
	checkbox=document.getElementById("selez"+i);
		
	while (checkbox!=null) {
		if (checkbox.checked)
			num++;
		i++;
		checkbox=document.getElementById("selez"+i);
	}
	return num;
}


function preOperazione(op) {
	var num, operazione, conferma;
	num=numeroSelezionati();

	if (num==0) {
		alert("Non ci sono " + entity[1] + " selezionat" + entity[3] + ".");
		return false;
	} else {
		switch(op.toUpperCase()) {
			case "E":
				operazione="eliminare";
				break;
			case "A":
				operazione="autorizzare";
				break;
			case "S":
				operazione="sospendere";
				break;
			case "R":
				operazione="ricaricare";
				break;
			case "P":
				operazione="pubblicare";
				break;
			case "M":
				//document.getElementById("formelenco").action='mail_compose.asp';
				document.getElementById("formelenco").action='prepara_mail.asp?tipomail=S';
				return true;
				operazione="mandare una mail";
				break;

			default:
				alert("Codice operazione (" + op + ") non valido.");
				return false;
		}
		conferma="Sei sicuro di voler " + operazione + " " + num + " " + (num==1?entity[0]:entity[1]) + "?";
		return confirm(conferma);
	}
}


function selezionaElencoPerValore(elenco, valore) {
	//alert('selezionaElencoPerValore');
	var i, strvalore;

	if (stringaVuota(valore))
		return;
	strvalore=""+valore;

	for (i=0; i<elenco.length; i++) {
		if (elenco.options[i].value==strvalore) {
			elenco.selectedIndex=i;
			break;
		}
	}
}


function selezionaRadioPerValore(radio, valore) {
	var i, strvalore;

	if (stringaVuota(valore))
		return;
	strvalore=""+valore;

	for (i=0; i<radio.length; i++) {
		if (radio[i].value==strvalore) {
			radio[i].checked=true;
			break;
		}
	}
}


function inizializzaFormRicerca(isc, cat, txt, dov, ord, ordm, rpp) {
	selezionaElencoPerValore(document.getElementById("stato_iscrizione"), isc);
	selezionaElencoPerValore(document.getElementById("categoria"), cat);
	if (!stringaVuota(txt))
		document.getElementById("testo").value=txt;
	selezionaElencoPerValore(document.getElementById("dove"), dov);
	selezionaRadioPerValore(document.form1.ordina_per, ord);
	selezionaRadioPerValore(document.form1.ordina_modo, ordm);
	selezionaElencoPerValore(document.getElementById("recordsperpagina"), rpp);
}

////// non utilizzato?
function impostaTipoAnnuncio() {
	var tipo=document.getElementById("tipoannuncio").value;

	if (tipo=="") {
		alert("Selezionare il tipo di annuncio");
		return false;
	}
	document.getElementById("nuovoannuncio").action=tipo + "_d.asp";
	return true;
}


function impostaAzione(az) {
	//alert("az="+az)
	document.getElementById("azione66").value=az;
	//alert("document.getElementById(  ).value="+document.getElementById("azione").value)
}
